From: Roger Braun Date: Thu, 30 Mar 2017 14:08:49 +0000 (+0200) Subject: Basic ObjectRepresenter. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=42c90855ba826a93cada909f105307c95dc0e130;p=akkoma Basic ObjectRepresenter. --- 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