From 42c90855ba826a93cada909f105307c95dc0e130 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 30 Mar 2017 16:08:49 +0200 Subject: [PATCH] Basic ObjectRepresenter. --- .../representers/object_representer.ex | 15 ++++++++++ .../representers/object_representer_test.exs | 30 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 lib/pleroma/web/twitter_api/representers/object_representer.ex create mode 100644 test/web/twitter_api/representers/object_representer_test.exs 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 index 000000000..57ab24caa --- /dev/null +++ b/lib/pleroma/web/twitter_api/representers/object_representer.ex @@ -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 index 000000000..fc6e0aff9 --- /dev/null +++ b/test/web/twitter_api/representers/object_representer_test.exs @@ -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