From a027b0027cc06609b112d4341348734c1378d6f2 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 20 Jul 2017 20:35:30 +0200 Subject: [PATCH] Add friends endpoint. --- lib/pleroma/web/router.ex | 1 + .../web/twitter_api/twitter_api_controller.ex | 8 ++++++++ .../twitter_api_controller_test.exs | 18 ++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index 84a39d817..34207a62f 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -72,6 +72,7 @@ defmodule Pleroma.Web.Router do post "/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar get "/statuses/followers", TwitterAPI.Controller, :followers + get "/statuses/friends", TwitterAPI.Controller, :friends end pipeline :ostatus do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index ea3030676..9b1c74a3f 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -218,6 +218,14 @@ defmodule Pleroma.Web.TwitterAPI.Controller do end end + def friends(%{assigns: %{user: user}} = conn, _params) do + with {:ok, friends} <- User.get_friends(user) do + render(conn, UserView, "index.json", %{users: friends, for: user}) + else + _e -> bad_request_reply(conn, "Can't get friends") + end + end + defp bad_request_reply(conn, error_message) do json = error_json(conn, error_message) json_reply(conn, 400, json) diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs index 4bf1c928b..8c689d7d3 100644 --- a/test/web/twitter_api/twitter_api_controller_test.exs +++ b/test/web/twitter_api/twitter_api_controller_test.exs @@ -437,6 +437,24 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do end end + describe "GET /api/statuses/friends" do + test "it returns a user's friends", %{conn: conn} do + user = insert(:user) + followed_one = insert(:user) + followed_two = insert(:user) + not_followed = insert(:user) + + {:ok, user} = User.follow(user, followed_one) + {:ok, user} = User.follow(user, followed_two) + + conn = conn + |> assign(:user, user) + |> get("/api/statuses/friends") + + assert json_response(conn, 200) == UserView.render("index.json", %{users: [followed_one, followed_two], for: user}) + end + end + defp valid_user(_context) do user = insert(:user) [user: user] -- 2.45.2