Add externalprofile to TwAPI.
This commit is contained in:
parent
2e753e8cd7
commit
36448d6483
5 changed files with 38 additions and 0 deletions
|
@ -38,6 +38,8 @@ defmodule Pleroma.Web.Router do
|
|||
get "/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation
|
||||
|
||||
post "/account/register", TwitterAPI.Controller, :register
|
||||
|
||||
get "/externalprofile/show", TwitterAPI.Controller, :external_profile
|
||||
end
|
||||
|
||||
scope "/api", Pleroma.Web do
|
||||
|
|
|
@ -350,4 +350,12 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
|
|||
{:error, "No such conversation"}
|
||||
end
|
||||
end
|
||||
|
||||
def get_external_profile(for_user, uri) do
|
||||
with %User{} = user <- User.get_cached_by_ap_id(uri) do
|
||||
{:ok, UserRepresenter.to_map(user, %{for: for_user})}
|
||||
else _e ->
|
||||
{:error, "Couldn't find user"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -207,6 +207,14 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
|
|||
|> json_reply(200, response)
|
||||
end
|
||||
|
||||
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
|
||||
conn
|
||||
|> json_reply(200, response)
|
||||
end
|
||||
end
|
||||
|
||||
defp bad_request_reply(conn, error_message) do
|
||||
json = error_json(conn, error_message)
|
||||
json_reply(conn, 400, json)
|
||||
|
|
|
@ -389,6 +389,17 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "GET /api/externalprofile/show" do
|
||||
test "it returns the user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
conn = conn
|
||||
|> get("/api/externalprofile/show", %{profileurl: user.ap_id})
|
||||
|
||||
assert json_response(conn, 200) == UserRepresenter.to_map(user)
|
||||
end
|
||||
end
|
||||
|
||||
defp valid_user(_context) do
|
||||
user = insert(:user)
|
||||
[user: user]
|
||||
|
|
|
@ -358,4 +358,13 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPITest do
|
|||
assert conversation_id == object.id
|
||||
end
|
||||
end
|
||||
|
||||
describe "fetching a user by uri" do
|
||||
test "fetches a user by uri" do
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, represented} = TwitterAPI.get_external_profile(user, user.ap_id)
|
||||
assert represented = UserRepresenter.to_map(user, %{for: user})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue