about summary refs log tree commit diff
path: root/app/serializers/rest/account_serializer.rb
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2017-07-07 04:02:06 +0200
committerGitHub <noreply@github.com>2017-07-07 04:02:06 +0200
commit8b2cad56374b2dbb6e7a445e7917810935c45536 (patch)
treebebba9b1e98d599b3caa249a8d98fad0cfd70437 /app/serializers/rest/account_serializer.rb
parent2d6128672fcadeb29c99551a33648b4880969d22 (diff)
Refactor JSON templates to be generated with ActiveModelSerializers instead of Rabl (#4090)
Diffstat (limited to 'app/serializers/rest/account_serializer.rb')
-rw-r--r--app/serializers/rest/account_serializer.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/app/serializers/rest/account_serializer.rb b/app/serializers/rest/account_serializer.rb
new file mode 100644
index 000000000..012a4fd18
--- /dev/null
+++ b/app/serializers/rest/account_serializer.rb
@@ -0,0 +1,33 @@
+# frozen_string_literal: true
+
+class REST::AccountSerializer < ActiveModel::Serializer
+  include RoutingHelper
+
+  attributes :id, :username, :acct, :display_name, :locked, :created_at,
+             :note, :url, :avatar, :avatar_static, :header, :header_static,
+             :followers_count, :following_count, :statuses_count
+
+  def note
+    Formatter.instance.simplified_format(object)
+  end
+
+  def url
+    TagManager.instance.url_for(object)
+  end
+
+  def avatar
+    full_asset_url(object.avatar_original_url)
+  end
+
+  def avatar_static
+    full_asset_url(object.avatar_static_url)
+  end
+
+  def header
+    full_asset_url(object.header_original_url)
+  end
+
+  def header_static
+    full_asset_url(object.header_static_url)
+  end
+end