chinwagsocial/app/api/mastodon/entities.rb

51 lines
1.2 KiB
Ruby
Raw Normal View History

2016-02-21 08:53:20 +11:00
module Mastodon
module Entities
class Account < Grape::Entity
2016-02-25 04:44:03 +11:00
include ApplicationHelper
expose :id
2016-02-21 08:53:20 +11:00
expose :username
2016-02-25 04:44:03 +11:00
expose :domain do |account|
account.local? ? LOCAL_DOMAIN : account.domain
end
2016-02-23 02:00:20 +11:00
expose :display_name
expose :note
2016-02-25 04:44:03 +11:00
expose :url do |account|
account.local? ? profile_url(name: account.username) : account.url
end
2016-02-21 08:53:20 +11:00
end
class Status < Grape::Entity
2016-02-25 04:44:03 +11:00
include ApplicationHelper
2016-02-21 08:53:20 +11:00
format_with(:iso_timestamp) { |dt| dt.iso8601 }
2016-02-25 04:44:03 +11: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-21 08:53:20 +11:00
expose :text
2016-02-25 04:44:03 +11:00
expose :in_reply_to_id
expose :reblog_of_id
expose :reblog, using: Mastodon::Entities::Status
2016-02-21 08:53:20 +11:00
expose :account, using: Mastodon::Entities::Account
with_options(format_with: :iso_timestamp) do
expose :created_at
expose :updated_at
end
end
end
end