clacks/lib/clacks_web/controllers/inbox_controller.ex

29 lines
678 B
Elixir

defmodule ClacksWeb.InboxController do
require Logger
use ClacksWeb, :controller
alias Clacks.Inbox
plug Plug.Parsers, parsers: [:urlencoded, :json], json_decoder: Jason
plug ClacksWeb.Plug.HTTPSignature
def shared(conn, _params) do
handle(conn, conn.body_params)
end
def user_specific(conn, _params) do
handle(conn, conn.body_params)
end
def handle(conn, %{"type" => type} = activity) do
case Inbox.handle(activity) do
:ok ->
put_status(conn, 200)
{:error, reason} ->
Logger.error("Could not handle incoming #{type} activity: #{inspect(reason)}")
put_status(conn, 500)
end
|> json(%{})
end
end