More Jason changes.

This commit is contained in:
lain 2018-03-27 16:45:38 +02:00
parent 527e803758
commit d2099c849d
8 changed files with 36 additions and 36 deletions

View file

@ -58,7 +58,7 @@ defp halt_or_continue(conn, %{optional: true}) do
defp halt_or_continue(conn, _) do
conn
|> put_resp_content_type("application/json")
|> send_resp(403, Poison.encode!(%{error: "Invalid credentials."}))
|> send_resp(403, Jason.encode!(%{error: "Invalid credentials."}))
|> halt
end
end

View file

@ -305,7 +305,7 @@ def user_data_from_user_object(data) do
def fetch_and_prepare_user_from_ap_id(ap_id) do
with {:ok, %{status_code: 200, body: body}} <- @httpoison.get(ap_id, ["Accept": "application/activity+json"]),
{:ok, data} <- Poison.decode(body) do
{:ok, data} <- Jason.decode(body) do
user_data_from_user_object(data)
else
e -> Logger.error("Could not decode user at fetch #{ap_id}, #{inspect(e)}")
@ -348,7 +348,7 @@ def publish(actor, activity) do
|> Enum.uniq
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
json = Poison.encode!(data)
json = Jason.encode!(data)
Enum.each remote_inboxes, fn(inbox) ->
Federator.enqueue(:publish_single_ap, %{inbox: inbox, json: json, actor: actor, id: activity.data["id"]})
end
@ -370,7 +370,7 @@ def fetch_object_from_id(id) do
Logger.info("Fetching #{id} via AP")
with true <- String.starts_with?(id, "http"),
{:ok, %{body: body, status_code: code}} when code in 200..299 <- @httpoison.get(id, [Accept: "application/activity+json"], follow_redirect: true, timeout: 10000, recv_timeout: 20000),
{:ok, data} <- Poison.decode(body),
{:ok, data} <- Jason.decode(body),
nil <- Object.get_by_ap_id(data["id"]),
params <- %{"type" => "Create", "to" => data["to"], "cc" => data["cc"], "actor" => data["attributedTo"], "object" => data},
{:ok, activity} <- Transmogrifier.handle_incoming(params) do

View file

@ -284,7 +284,7 @@ def get_notification(%{assigns: %{user: user}} = conn, %{"id" => id} = _params)
{:error, reason} ->
conn
|> put_resp_content_type("application/json")
|> send_resp(403, Poison.encode!(%{"error" => reason}))
|> send_resp(403, Jason.encode!(%{"error" => reason}))
end
end
@ -300,7 +300,7 @@ def dismiss_notification(%{assigns: %{user: user}} = conn, %{"id" => id} = _para
{:error, reason} ->
conn
|> put_resp_content_type("application/json")
|> send_resp(403, Poison.encode!(%{"error" => reason}))
|> send_resp(403, Jason.encode!(%{"error" => reason}))
end
end
@ -381,7 +381,7 @@ def follow(%{assigns: %{user: follower}} = conn, %{"id" => id}) do
{:error, message} ->
conn
|> put_resp_content_type("application/json")
|> send_resp(403, Poison.encode!(%{"error" => message}))
|> send_resp(403, Jason.encode!(%{"error" => message}))
end
end
@ -394,7 +394,7 @@ def follow(%{assigns: %{user: follower}} = conn, %{"uri" => uri}) do
{:error, message} ->
conn
|> put_resp_content_type("application/json")
|> send_resp(403, Poison.encode!(%{"error" => message}))
|> send_resp(403, Jason.encode!(%{"error" => message}))
end
end
@ -419,7 +419,7 @@ def block(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
{:error, message} ->
conn
|> put_resp_content_type("application/json")
|> send_resp(403, Poison.encode!(%{"error" => message}))
|> send_resp(403, Jason.encode!(%{"error" => message}))
end
end
@ -431,7 +431,7 @@ def unblock(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
{:error, message} ->
conn
|> put_resp_content_type("application/json")
|> send_resp(403, Poison.encode!(%{"error" => message}))
|> send_resp(403, Jason.encode!(%{"error" => message}))
end
end
@ -565,7 +565,7 @@ def index(%{assigns: %{user: user}} = conn, _params) do
push_subscription: nil,
accounts: accounts,
custom_emojis: mastodon_emoji
} |> Poison.encode!
} |> Jason.encode!
conn
|> put_layout(false)
|> render(MastodonView, "index.html", %{initial_state: initial_state})

View file

@ -42,8 +42,8 @@ def handle_cast(%{action: :stream, topic: "user", item: %Notification{} = item},
Enum.each(topics[topic] || [], fn (socket) ->
json = %{
event: "notification",
payload: Pleroma.Web.MastodonAPI.MastodonAPIController.render_notification(socket.assigns["user"], item) |> Poison.encode!
} |> Poison.encode!
payload: Pleroma.Web.MastodonAPI.MastodonAPIController.render_notification(socket.assigns["user"], item) |> Jason.encode!
} |> Jason.encode!
send socket.transport_pid, {:text, json}
end)
@ -95,8 +95,8 @@ def push_to_socket(topics, topic, item) do
Enum.each(topics[topic] || [], fn (socket) ->
json = %{
event: "update",
payload: Pleroma.Web.MastodonAPI.StatusView.render("status.json", activity: item, for: socket.assigns[:user]) |> Poison.encode!
} |> Poison.encode!
payload: Pleroma.Web.MastodonAPI.StatusView.render("status.json", activity: item, for: socket.assigns[:user]) |> Jason.encode!
} |> Jason.encode!
send socket.transport_pid, {:text, json}
end)

View file

@ -5,7 +5,7 @@ def to_json(object) do to_json(object, %{}) end
def to_json(object, options) do
object
|> to_map(options)
|> Poison.encode!
|> Jason.encode!
end
def enum_to_list(enum, options) do
@ -21,7 +21,7 @@ def enum_to_json(enum) do enum_to_json(enum, %{}) end
def enum_to_json(enum, options) do
enum
|> enum_to_list(options)
|> Poison.encode!
|> Jason.encode!
end
end
end

View file

@ -169,7 +169,7 @@ def upload(%Plug.Upload{} = file, format \\ "xml") do
media_id_string: "#{object.id}}",
media_url: href,
size: 0
} |> Poison.encode!
} |> Jason.encode!
end
end
@ -190,7 +190,7 @@ def register_user(params) do
else
{:error, changeset} ->
errors = Ecto.Changeset.traverse_errors(changeset, fn {msg, _opts} -> msg end)
|> Poison.encode!
|> Jason.encode!
{:error, %{error: errors}}
end
end

View file

@ -44,7 +44,7 @@ defp extract_media_ids(status_data) do
def public_and_external_timeline(%{assigns: %{user: user}} = conn, params) do
statuses = TwitterAPI.fetch_public_and_external_statuses(user, params)
{:ok, json} = Poison.encode(statuses)
{:ok, json} = Jason.encode(statuses)
conn
|> json_reply(200, json)
@ -52,7 +52,7 @@ def public_and_external_timeline(%{assigns: %{user: user}} = conn, params) do
def public_timeline(%{assigns: %{user: user}} = conn, params) do
statuses = TwitterAPI.fetch_public_statuses(user, params)
{:ok, json} = Poison.encode(statuses)
{:ok, json} = Jason.encode(statuses)
conn
|> json_reply(200, json)
@ -60,7 +60,7 @@ def public_timeline(%{assigns: %{user: user}} = conn, params) do
def friends_timeline(%{assigns: %{user: user}} = conn, params) do
statuses = TwitterAPI.fetch_friend_statuses(user, params)
{:ok, json} = Poison.encode(statuses)
{:ok, json} = Jason.encode(statuses)
conn
|> json_reply(200, json)
@ -85,7 +85,7 @@ def user_timeline(%{assigns: %{user: user}} = conn, params) do
params = Map.merge(params, %{"actor_id" => target_user.ap_id, "whole_db" => true})
statuses = TwitterAPI.fetch_user_statuses(user, params)
conn
|> json_reply(200, statuses |> Poison.encode!)
|> json_reply(200, statuses |> Jason.encode!)
{:error, msg} ->
bad_request_reply(conn, msg)
end
@ -93,7 +93,7 @@ def user_timeline(%{assigns: %{user: user}} = conn, params) do
def mentions_timeline(%{assigns: %{user: user}} = conn, params) do
statuses = TwitterAPI.fetch_mentions(user, params)
{:ok, json} = Poison.encode(statuses)
{:ok, json} = Jason.encode(statuses)
conn
|> json_reply(200, json)
@ -140,7 +140,7 @@ def unfollow(%{assigns: %{user: user}} = conn, params) do
end
def fetch_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
response = Poison.encode!(TwitterAPI.fetch_status(user, id))
response = Jason.encode!(TwitterAPI.fetch_status(user, id))
conn
|> json_reply(200, response)
@ -148,7 +148,7 @@ def fetch_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
def fetch_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do
id = String.to_integer(id)
response = Poison.encode!(TwitterAPI.fetch_conversation(user, id))
response = Jason.encode!(TwitterAPI.fetch_conversation(user, id))
conn
|> json_reply(200, response)
@ -200,7 +200,7 @@ def register(conn, params) do
else
{:error, errors} ->
conn
|> json_reply(400, Poison.encode!(errors))
|> json_reply(400, Jason.encode!(errors))
end
end
@ -220,7 +220,7 @@ def update_banner(%{assigns: %{user: user}} = conn, params) do
{:ok, user} <- User.update_and_set_cache(change) do
CommonAPI.update(user)
%{"url" => [ %{ "href" => href } | _ ]} = object.data
response = %{ url: href } |> Poison.encode!
response = %{ url: href } |> Jason.encode!
conn
|> json_reply(200, response)
end
@ -232,7 +232,7 @@ def update_background(%{assigns: %{user: user}} = conn, params) do
change <- User.info_changeset(user, %{info: new_info}),
{:ok, _user} <- User.update_and_set_cache(change) do
%{"url" => [ %{ "href" => href } | _ ]} = object.data
response = %{ url: href } |> Poison.encode!
response = %{ url: href } |> Jason.encode!
conn
|> json_reply(200, response)
end
@ -240,7 +240,7 @@ def update_background(%{assigns: %{user: user}} = conn, params) do
def external_profile(%{assigns: %{user: current_user}} = conn, %{"profileurl" => uri}) do
with {:ok, user_map} <- TwitterAPI.get_external_profile(current_user, uri),
response <- Poison.encode!(user_map) do
response <- Jason.encode!(user_map) do
conn
|> json_reply(200, response)
else
@ -259,7 +259,7 @@ def update_most_recent_notification(%{assigns: %{user: user}} = conn, %{"id" =>
changeset <- User.info_changeset(user, %{info: updated_info}),
{:ok, _user} <- User.update_and_set_cache(changeset) do
conn
|> json_reply(200, Poison.encode!(mrn))
|> json_reply(200, Jason.encode!(mrn))
else
_e -> bad_request_reply(conn, "Can't update.")
end
@ -287,7 +287,7 @@ def friends_ids(%{assigns: %{user: user}} = conn, _params) do
with {:ok, friends} <- User.get_friends(user) do
ids = friends
|> Enum.map(fn x -> x.id end)
|> Poison.encode!
|> Jason.encode!
json(conn, ids)
else
@ -296,7 +296,7 @@ def friends_ids(%{assigns: %{user: user}} = conn, _params) do
end
def empty_array(conn, _params) do
json(conn, Poison.encode!([]))
json(conn, Jason.encode!([]))
end
def update_profile(%{assigns: %{user: user}} = conn, params) do
@ -339,6 +339,6 @@ defp forbidden_json_reply(conn, error_message) do
end
defp error_json(conn, error_message) do
%{"error" => error_message, "request" => conn.request_path} |> Poison.encode!
%{"error" => error_message, "request" => conn.request_path} |> Jason.encode!
end
end

View file

@ -4,7 +4,7 @@ defmodule Pleroma.Web.WebFinger do
alias Pleroma.{Repo, User, XmlBuilder}
alias Pleroma.Web
alias Pleroma.Web.{XML, Salmon, OStatus}
require Poison
require Jason
require Logger
def host_meta do
@ -182,7 +182,7 @@ def finger(account) do
if doc != :error do
webfinger_from_xml(doc)
else
{:ok, doc} = Poison.decode(body)
{:ok, doc} = Jason.decode(body)
webfinger_from_json(doc)
end
else