You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
akkoma-cachapa/lib/pleroma/web/twitter_api/representers/base_representer.ex

39 lines
874 B

# 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.BaseRepresenter do
defmacro __using__(_opts) do
quote do
7 years ago
def to_json(object) do
to_json(object, %{})
end
def to_json(object, options) do
object
|> to_map(options)
7 years ago
|> Jason.encode!()
end
def enum_to_list(enum, options) do
7 years ago
mapping = fn el -> to_map(el, options) end
Enum.map(enum, mapping)
end
def to_map(object) do
to_map(object, %{})
end
7 years ago
def enum_to_json(enum) do
enum_to_json(enum, %{})
end
def enum_to_json(enum, options) do
enum
|> enum_to_list(options)
7 years ago
|> Jason.encode!()
end
end
end
end