about summary refs log tree commit diff
path: root/app/serializers/oembed_serializer.rb
diff options
context:
space:
mode:
authorkibigo! <marrus-sh@users.noreply.github.com>2017-07-12 02:03:17 -0700
committerkibigo! <marrus-sh@users.noreply.github.com>2017-07-12 02:03:17 -0700
commit79d898ae0ad8c0e66bd63ec3e0904e9e5e7894e8 (patch)
treeee8d832ed2f11e9afe62daf0e586a86004eb8d98 /app/serializers/oembed_serializer.rb
parentbcf7ee48e94cd2e4d2de28e8854e7f0e2b5cad1f (diff)
parent056b5ed72f6d980bceeb49eb249b8365fe8fce66 (diff)
Merge upstream!! #64 <3 <3
Diffstat (limited to 'app/serializers/oembed_serializer.rb')
-rw-r--r--app/serializers/oembed_serializer.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/app/serializers/oembed_serializer.rb b/app/serializers/oembed_serializer.rb
new file mode 100644
index 000000000..78376d253
--- /dev/null
+++ b/app/serializers/oembed_serializer.rb
@@ -0,0 +1,56 @@
+# frozen_string_literal: true
+
+class OEmbedSerializer < ActiveModel::Serializer
+  include RoutingHelper
+  include ActionView::Helpers::TagHelper
+
+  attributes :type, :version, :title, :author_name,
+             :author_url, :provider_name, :provider_url,
+             :cache_age, :html, :width, :height
+
+  def type
+    'rich'
+  end
+
+  def version
+    '1.0'
+  end
+
+  def author_name
+    object.account.display_name.presence || object.account.username
+  end
+
+  def author_url
+    account_url(object.account)
+  end
+
+  def provider_name
+    Rails.configuration.x.local_domain
+  end
+
+  def provider_url
+    root_url
+  end
+
+  def cache_age
+    86_400
+  end
+
+  def html
+    tag :iframe,
+        src: embed_account_stream_entry_url(object.account, object),
+        style: 'width: 100%; overflow: hidden',
+        frameborder: '0',
+        scrolling: 'no',
+        width: width,
+        height: height
+  end
+
+  def width
+    instance_options[:width]
+  end
+
+  def height
+    instance_options[:height]
+  end
+end