+ 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
+
+ def mentions_timeline(%{assigns: %{user: user}} = conn, params) do
+ statuses = TwitterAPI.fetch_mentions(user, params)
+ {:ok, json} = Poison.encode(statuses)
+
+ conn
+ |> json_reply(200, json)
+ end
+
+ def follow(%{assigns: %{user: user}} = conn, params) do
+ case TwitterAPI.follow(user, params) do
+ {:ok, user, followed, _activity} ->
+ render(conn, UserView, "show.json", %{user: followed, for: user})
+ {:error, msg} -> forbidden_json_reply(conn, msg)
+ end
+ end
+
+ def unfollow(%{assigns: %{user: user}} = conn, params) do
+ case TwitterAPI.unfollow(user, params) do
+ {:ok, user, unfollowed} ->
+ render(conn, UserView, "show.json", %{user: unfollowed, for: user})
+ {:error, msg} -> forbidden_json_reply(conn, msg)
+ end
+ end
+
+ def fetch_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ response = Poison.encode!(TwitterAPI.fetch_status(user, id))
+
+ conn
+ |> json_reply(200, response)
+ end
+
+ def fetch_conversation(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ id = String.to_integer(id)
+ response = Poison.encode!(TwitterAPI.fetch_conversation(user, id))