user_serializer.rb 686 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
# frozen_string_literal: true

class UserSerializer < ActiveModel::Serializer
  attributes :mastodon_url, :mastodon_username, :twitter_username,
             :display_name, :avatar_url, :following

  def mastodon_url
    object.mastodon.info['url'] || object.mastodon.profile_url
  end

  def mastodon_username
    object.mastodon.uid
  end

  def twitter_username
    object.twitter.display_name
  end

  def display_name
    object.mastodon.info['display_name'].presence ||
      object.mastodon.info['username'] ||
      object.mastodon.display_name.presence ||
      object.mastodon.uid.split('@').first
  end

  def avatar_url
Yamagishi Kazutoshi's avatar
Yamagishi Kazutoshi committed
27
    object.mastodon.info['avatar'].presence
28 29
  end
end