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
{: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
|> 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)
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]
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