1
0

webfinger_serializer.rb 963 B

12345678910111213141516171819202122232425262728293031323334
  1. # frozen_string_literal: true
  2. class WebfingerSerializer < ActiveModel::Serializer
  3. include RoutingHelper
  4. attributes :subject, :aliases, :links
  5. def subject
  6. object.to_webfinger_s
  7. end
  8. def aliases
  9. if object.instance_actor?
  10. [instance_actor_url]
  11. else
  12. [short_account_url(object), account_url(object)]
  13. end
  14. end
  15. def links
  16. if object.instance_actor?
  17. [
  18. { rel: 'http://webfinger.net/rel/profile-page', type: 'text/html', href: about_more_url(instance_actor: true) },
  19. { rel: 'self', type: 'application/activity+json', href: instance_actor_url },
  20. ]
  21. else
  22. [
  23. { rel: 'http://webfinger.net/rel/profile-page', type: 'text/html', href: short_account_url(object) },
  24. { rel: 'self', type: 'application/activity+json', href: account_url(object) },
  25. { rel: 'http://ostatus.org/schema/1.0/subscribe', template: "#{authorize_interaction_url}?uri={uri}" },
  26. ]
  27. end
  28. end
  29. end