2018-12-23 21:04:54 +01:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2017-03-20 21:30:18 +01:00
|
|
|
defmodule Pleroma.Web.TwitterAPI.Representers.BaseRepresenter do
|
|
|
|
defmacro __using__(_opts) do
|
|
|
|
quote do
|
2018-03-30 15:01:53 +02:00
|
|
|
def to_json(object) do
|
|
|
|
to_json(object, %{})
|
|
|
|
end
|
|
|
|
|
2017-03-20 21:30:18 +01:00
|
|
|
def to_json(object, options) do
|
|
|
|
object
|
|
|
|
|> to_map(options)
|
2018-03-30 15:01:53 +02:00
|
|
|
|> Jason.encode!()
|
2017-03-20 21:30:18 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def enum_to_list(enum, options) do
|
2018-03-30 15:01:53 +02:00
|
|
|
mapping = fn el -> to_map(el, options) end
|
2017-03-20 21:30:18 +01:00
|
|
|
Enum.map(enum, mapping)
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_map(object) do
|
|
|
|
to_map(object, %{})
|
|
|
|
end
|
|
|
|
|
2018-03-30 15:01:53 +02:00
|
|
|
def enum_to_json(enum) do
|
|
|
|
enum_to_json(enum, %{})
|
|
|
|
end
|
|
|
|
|
2017-03-20 21:30:18 +01:00
|
|
|
def enum_to_json(enum, options) do
|
|
|
|
enum
|
|
|
|
|> enum_to_list(options)
|
2018-03-30 15:01:53 +02:00
|
|
|
|> Jason.encode!()
|
2017-03-20 21:30:18 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|