about summary refs log tree commit diff
path: root/app/serializers/rest/media_attachment_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/media_attachment_serializer.rb
parent2d6128672fcadeb29c99551a33648b4880969d22 (diff)
Refactor JSON templates to be generated with ActiveModelSerializers instead of Rabl (#4090)
Diffstat (limited to 'app/serializers/rest/media_attachment_serializer.rb')
-rw-r--r--app/serializers/rest/media_attachment_serializer.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/app/serializers/rest/media_attachment_serializer.rb b/app/serializers/rest/media_attachment_serializer.rb
new file mode 100644
index 000000000..9b07a686e
--- /dev/null
+++ b/app/serializers/rest/media_attachment_serializer.rb
@@ -0,0 +1,24 @@
+# frozen_string_literal: true
+
+class REST::MediaAttachmentSerializer < ActiveModel::Serializer
+  include RoutingHelper
+
+  attributes :id, :type, :url, :preview_url,
+             :remote_url, :text_url, :meta
+
+  def url
+    full_asset_url(object.file.url(:original))
+  end
+
+  def preview_url
+    full_asset_url(object.file.url(:small))
+  end
+
+  def text_url
+    medium_url(object.id)
+  end
+
+  def meta
+    object.file.meta
+  end
+end