akkoma/lib/pleroma/web/twitter_api/representers/object_representer.ex

36 lines
915 B
Elixir
Raw Normal View History

2017-03-30 08:08:49 -06:00
defmodule Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter do
use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
alias Pleroma.Object
def to_map(%Object{data: %{"url" => [url | _]}} = object, _opts) do
2017-03-30 08:08:49 -06:00
data = object.data
2018-03-30 07:01:53 -06:00
2017-03-30 08:08:49 -06:00
%{
2017-11-22 11:06:07 -07:00
url: url["href"] |> Pleroma.Web.MediaProxy.url(),
2018-07-12 11:06:28 -06:00
mimetype: url["mediaType"] || url["mimeType"],
2017-03-30 09:07:03 -06:00
id: data["uuid"],
oembed: false,
description: data["name"]
2017-03-30 08:08:49 -06:00
}
end
2017-03-30 09:07:03 -06:00
def to_map(%Object{data: %{"url" => url} = data}, _opts) when is_binary(url) do
%{
url: url |> Pleroma.Web.MediaProxy.url(),
mimetype: data["mediaType"] || data["mimeType"],
id: data["uuid"],
oembed: false,
description: data["name"]
}
end
def to_map(%Object{}, _opts) do
%{}
end
2017-03-30 09:07:03 -06:00
# If we only get the naked data, wrap in an object
def to_map(%{} = data, opts) do
to_map(%Object{data: data}, opts)
end
2017-03-30 08:08:49 -06:00
end