Remove TwitterAPI representers
authorrinpatch <rinpatch@sdf.org>
Sat, 31 Aug 2019 07:41:15 +0000 (10:41 +0300)
committerrinpatch <rinpatch@sdf.org>
Sat, 31 Aug 2019 07:41:15 +0000 (10:41 +0300)
lib/pleroma/web/twitter_api/representers/base_representer.ex [deleted file]
lib/pleroma/web/twitter_api/representers/object_representer.ex [deleted file]
test/web/twitter_api/representers/object_representer_test.exs [deleted file]

diff --git a/lib/pleroma/web/twitter_api/representers/base_representer.ex b/lib/pleroma/web/twitter_api/representers/base_representer.ex
deleted file mode 100644 (file)
index 3d31e60..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Web.TwitterAPI.Representers.BaseRepresenter do
-  defmacro __using__(_opts) do
-    quote do
-      def to_json(object) do
-        to_json(object, %{})
-      end
-
-      def to_json(object, options) do
-        object
-        |> to_map(options)
-        |> Jason.encode!()
-      end
-
-      def enum_to_list(enum, options) do
-        mapping = fn el -> to_map(el, options) end
-        Enum.map(enum, mapping)
-      end
-
-      def to_map(object) do
-        to_map(object, %{})
-      end
-
-      def enum_to_json(enum) do
-        enum_to_json(enum, %{})
-      end
-
-      def enum_to_json(enum, options) do
-        enum
-        |> enum_to_list(options)
-        |> Jason.encode!()
-      end
-    end
-  end
-end
diff --git a/lib/pleroma/web/twitter_api/representers/object_representer.ex b/lib/pleroma/web/twitter_api/representers/object_representer.ex
deleted file mode 100644 (file)
index 47130ba..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-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
-    data = object.data
-
-    %{
-      url: url["href"] |> Pleroma.Web.MediaProxy.url(),
-      mimetype: url["mediaType"] || url["mimeType"],
-      id: data["uuid"],
-      oembed: false,
-      description: data["name"]
-    }
-  end
-
-  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
-
-  # If we only get the naked data, wrap in an object
-  def to_map(%{} = data, opts) do
-    to_map(%Object{data: data}, opts)
-  end
-end
diff --git a/test/web/twitter_api/representers/object_representer_test.exs b/test/web/twitter_api/representers/object_representer_test.exs
deleted file mode 100644 (file)
index c3cf330..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-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"
-          }
-        ],
-        "uuid" => 6
-      }
-    }
-
-    expected_object = %{
-      id: 6,
-      url: "someurl",
-      mimetype: "sometype",
-      oembed: false,
-      description: nil
-    }
-
-    assert expected_object == ObjectRepresenter.to_map(object)
-  end
-
-  test "represents mastodon-style attachments" do
-    object = %Object{
-      id: nil,
-      data: %{
-        "mediaType" => "image/png",
-        "name" => "blabla",
-        "type" => "Document",
-        "url" =>
-          "http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png"
-      }
-    }
-
-    expected_object = %{
-      url:
-        "http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png",
-      mimetype: "image/png",
-      oembed: false,
-      id: nil,
-      description: "blabla"
-    }
-
-    assert expected_object == ObjectRepresenter.to_map(object)
-  end
-end