Basic ObjectRepresenter.
authorRoger Braun <roger@rogerbraun.net>
Thu, 30 Mar 2017 14:08:49 +0000 (16:08 +0200)
committerRoger Braun <roger@rogerbraun.net>
Thu, 30 Mar 2017 14:08:49 +0000 (16:08 +0200)
lib/pleroma/web/twitter_api/representers/object_representer.ex [new file with mode: 0644]
test/web/twitter_api/representers/object_representer_test.exs [new file with mode: 0644]

diff --git a/lib/pleroma/web/twitter_api/representers/object_representer.ex b/lib/pleroma/web/twitter_api/representers/object_representer.ex
new file mode 100644 (file)
index 0000000..57ab24c
--- /dev/null
@@ -0,0 +1,15 @@
+defmodule Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter do
+  use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
+  alias Pleroma.Object
+
+  def to_map(%Object{} = object, _opts) do
+    data = object.data
+    url = List.first(data["url"])
+    %{
+      url: url["href"],
+      mimetype: url["mediaType"],
+      id: object.id,
+      oembed: false
+    }
+  end
+end
diff --git a/test/web/twitter_api/representers/object_representer_test.exs b/test/web/twitter_api/representers/object_representer_test.exs
new file mode 100644 (file)
index 0000000..fc6e0af
--- /dev/null
@@ -0,0 +1,30 @@
+defmodule Pleroma.Web.TwitterAPI.Representers.ObjectReprenterTest do
+  use Pleroma.DataCase
+
+  alias Pleroma.Object
+  alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter
+
+  test "represent an image attachment" do
+    object = %Object{
+      id: 5,
+      data: %{
+        "type" => "Image",
+        "url" => [
+          %{
+            "mediaType" => "sometype",
+            "href" => "someurl"
+          }
+        ]
+      }
+    }
+
+    expected_object = %{
+      id: 5,
+      url: "someurl",
+      mimetype: "sometype",
+      oembed: false
+    }
+
+    assert expected_object == ObjectRepresenter.to_map(object)
+  end
+end