mastodon-glitch/app/api/mastodon/entities.rb

55 lines
1.3 KiB
Ruby
Raw Normal View History

2016-02-20 21:53:20 +00:00
module Mastodon
module Entities
class Account < Grape::Entity
2016-02-24 17:44:03 +00:00
include ApplicationHelper
expose :id
2016-02-20 21:53:20 +00:00
expose :username
2016-02-24 17:44:03 +00:00
expose :domain do |account|
account.local? ? LOCAL_DOMAIN : account.domain
end
2016-02-22 15:00:20 +00:00
expose :display_name
expose :note
2016-02-24 17:44:03 +00:00
expose :url do |account|
account.local? ? profile_url(name: account.username) : account.url
end
2016-02-20 21:53:20 +00:00
end
class Status < Grape::Entity
2016-02-24 17:44:03 +00:00
include ApplicationHelper
2016-02-20 21:53:20 +00:00
format_with(:iso_timestamp) { |dt| dt.iso8601 }
2016-02-24 17:44:03 +00:00
expose :id
expose :uri do |status|
status.local? ? unique_tag(status.stream_entry.created_at, status.stream_entry.activity_id, status.stream_entry.activity_type) : status.uri
end
expose :url do |status|
status.local? ? status_url(name: status.account.username, id: status.id) : status.url
end
2016-02-20 21:53:20 +00:00
expose :text
2016-02-24 17:44:03 +00:00
expose :in_reply_to_id
expose :reblog_of_id
expose :reblog, using: Mastodon::Entities::Status
2016-02-20 21:53:20 +00:00
expose :account, using: Mastodon::Entities::Account
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
class StreamEntry < Grape::Entity
expose :activity, using: Mastodon::Entities::Status
end
2016-02-20 21:53:20 +00:00
end
end