Add Twitter API verify_credentials endpoint.

This commit is contained in:
Roger Braun 2017-03-20 21:30:44 +01:00
commit 093fd1832d
3 changed files with 71 additions and 1 deletions

View file

@ -1,11 +1,25 @@
defmodule Pleroma.Web.Router do
use Pleroma.Web, :router
alias Pleroma.{Repo, User}
def user_fetcher(username) do
{:ok, Repo.get_by(User, %{nickname: username})}
end
pipeline :api do
plug :accepts, ["json"]
end
pipeline :authenticated_api do
plug :accepts, ["json"]
plug :fetch_session
plug Pleroma.Plugs.AuthenticationPlug, fetcher: &Pleroma.Web.Router.user_fetcher/1
end
scope "/api", Pleroma.Web do
pipe_through :api
pipe_through :authenticated_api
post "/account/verify_credentials.json", TwitterAPI.Controller, :verify_credentials
end
end

View file

@ -0,0 +1,18 @@
defmodule Pleroma.Web.TwitterAPI.Controller do
use Pleroma.Web, :controller
alias Pleroma.Web.TwitterAPI.Representers.UserRepresenter
def verify_credentials(%{assigns: %{user: user}} = conn, _params) do
response = user |> UserRepresenter.to_json
conn
|> json_reply(200, response)
end
defp json_reply(conn, status, json) do
conn
|> put_resp_content_type("application/json")
|> send_resp(status, json)
end
end