|> json_reply(200, json)
end
- def follow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
- { :ok, user, follower, _activity } = TwitterAPI.follow(user, followed_id)
-
- response = follower |> UserRepresenter.to_json(%{for: user})
+ def user_timeline(%{assigns: %{user: user}} = conn, params) do
+ case TwitterAPI.get_user(user, params) do
+ {:ok, target_user} ->
+ params = Map.merge(params, %{"actor_id" => target_user.ap_id})
+ statuses = TwitterAPI.fetch_user_statuses(user, params)
+ conn
+ |> json_reply(200, statuses |> Poison.encode!)
+ {:error, msg} ->
+ bad_request_reply(conn, msg)
+ end
+ end
- conn
- |> json_reply(200, response)
+ def follow(%{assigns: %{user: user}} = conn, params) do
+ case TwitterAPI.follow(user, params) do
+ { :ok, user, followed, _activity } ->
+ response = followed |> UserRepresenter.to_json(%{for: user})
+ conn
+ |> json_reply(200, response)
+ { :error, msg } -> forbidden_json_reply(conn, msg)
+ end
end
- def unfollow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do
- case TwitterAPI.unfollow(user, followed_id) do
- { :ok, user, followed } ->
- response = followed |> UserRepresenter.to_json(%{for: user})
-
+ def unfollow(%{assigns: %{user: user}} = conn, params) do
- { :ok, user, follower } = TwitterAPI.unfollow(user, params)
-
- response = follower |> UserRepresenter.to_json(%{for: user})
-
- conn
- |> json_reply(200, response)
++ case TwitterAPI.unfollow(user, params) do
++ { :ok, user, unfollowed, } ->
++ response = unfollowed |> UserRepresenter.to_json(%{for: user})
+ conn
+ |> json_reply(200, response)
+ { :error, msg } -> forbidden_json_reply(conn, msg)
+ end
end
def fetch_status(%{assigns: %{user: user}} = conn, %{ "id" => id }) do
assert status == ActivityRepresenter.to_map(activity, %{for: user, user: actor})
end
- test "Follow another user" do
+ test "Follow another user using user_id" do
user = insert(:user)
- following = insert(:user)
-
- {:ok, user, following, activity } = TwitterAPI.follow(user, following.id)
+ followed = insert(:user)
- user = Repo.get(User, user.id)
- follow = Repo.get(Activity, activity.id)
+ {:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"user_id" => followed.id})
+ assert user.following == [User.ap_followers(followed)]
- assert user.following == [User.ap_followers(following)]
- assert follow == activity
+ { :error, msg } = TwitterAPI.follow(user, %{"user_id" => followed.id})
+ assert msg == "Could not follow user: #{followed.nickname} is already on your list."
end
- test "Unfollow another user using user_id" do
- following = insert(:user)
- user = insert(:user, %{following: [User.ap_followers(following)]})
+ test "Follow another user using screen_name" do
+ user = insert(:user)
+ followed = insert(:user)
- {:ok, user, _following } = TwitterAPI.unfollow(user, %{"user_id" => following.id})
+ {:ok, user, followed, _activity } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
+ assert user.following == [User.ap_followers(followed)]
- user = Repo.get(User, user.id)
+ { :error, msg } = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
+ assert msg == "Could not follow user: #{followed.nickname} is already on your list."
+ end
+
- test "Unfollow another user" do
- followed = insert(:user)
- user = insert(:user, %{following: [User.ap_followers(followed)]})
++ test "Unfollow another user using user_id" do
++ unfollowed = insert(:user)
++ user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
+
++ {:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
+ assert user.following == []
+
- { :ok, user, _followed } = TwitterAPI.unfollow(user, followed.id)
++ { :error, msg } = TwitterAPI.unfollow(user, %{"user_id" => unfollowed.id})
++ assert msg == "Not subscribed!"
+ end
- user = Repo.get(User, user.id)
+ test "Unfollow another user using screen_name" do
- following = insert(:user)
- user = insert(:user, %{following: [User.ap_followers(following)]})
-
- {:ok, user, _following } = TwitterAPI.unfollow(user, %{"screen_name" => following.nickname})
-
- user = Repo.get(User, user.id)
++ unfollowed = insert(:user)
++ user = insert(:user, %{following: [User.ap_followers(unfollowed)]})
++ {:ok, user, unfollowed } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
assert user.following == []
- { :error, msg } = TwitterAPI.unfollow(user, followed.id)
++
++ { :error, msg } = TwitterAPI.unfollow(user, %{"screen_name" => unfollowed.nickname})
+ assert msg == "Not subscribed!"
end
test "fetch statuses in a context using the conversation id" do