TwitterAPI: Add /friends/ids.
This commit is contained in:
parent
773eba4f0b
commit
3533bf7eac
|
@ -189,6 +189,7 @@ def user_fetcher(username) do
|
||||||
|
|
||||||
get "/statuses/followers", TwitterAPI.Controller, :followers
|
get "/statuses/followers", TwitterAPI.Controller, :followers
|
||||||
get "/statuses/friends", TwitterAPI.Controller, :friends
|
get "/statuses/friends", TwitterAPI.Controller, :friends
|
||||||
|
get "/friends/ids", TwitterAPI.Controller, :friends_ids
|
||||||
|
|
||||||
get "/externalprofile/show", TwitterAPI.Controller, :external_profile
|
get "/externalprofile/show", TwitterAPI.Controller, :external_profile
|
||||||
end
|
end
|
||||||
|
|
|
@ -265,6 +265,18 @@ def friends(%{assigns: %{user: user}} = conn, _params) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def friends_ids(%{assigns: %{user: user}} = conn, _params) do
|
||||||
|
with {:ok, friends} <- User.get_friends(user) do
|
||||||
|
ids = friends
|
||||||
|
|> Enum.map(fn x -> x.id end)
|
||||||
|
|> Poison.encode!
|
||||||
|
json(conn, ids)
|
||||||
|
else
|
||||||
|
_e -> bad_request_reply(conn, "Can't get friends")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
def update_profile(%{assigns: %{user: user}} = conn, params) do
|
def update_profile(%{assigns: %{user: user}} = conn, params) do
|
||||||
params = if bio = params["description"] do
|
params = if bio = params["description"] do
|
||||||
Map.put(params, "bio", bio)
|
Map.put(params, "bio", bio)
|
||||||
|
|
|
@ -494,6 +494,25 @@ test "it returns a user's friends", %{conn: conn} do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe "GET /friends/ids" 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/friends/ids")
|
||||||
|
|
||||||
|
expected = Poison.encode!([followed_one.id, followed_two.id])
|
||||||
|
assert json_response(conn, 200) == expected
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "POST /api/account/update_profile.json" do
|
describe "POST /api/account/update_profile.json" do
|
||||||
test "it updates a user's profile" do
|
test "it updates a user's profile" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
Loading…
Reference in New Issue