+ 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} ->
+ 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, params) do
+ 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
+ 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))
+
+ conn
+ |> json_reply(200, response)
+ end
+
+ def upload(conn, %{"media" => media}) do
+ response = TwitterAPI.upload(media)
+ conn
+ |> put_resp_content_type("application/atom+xml")
+ |> send_resp(200, response)
+ end
+
+ def help_test(conn, _params) do
+ conn |> json_reply(200, Poison.encode!("ok"))
+ end
+
+ def upload_json(conn, %{"media" => media}) do
+ response = TwitterAPI.upload(media, "json")
+ conn
+ |> json_reply(200, response)
+ end
+
+ def config(conn, _params) do
+ response = %{
+ site: %{
+ name: Web.base_url,
+ server: Web.base_url,
+ textlimit: -1
+ }
+ }
+ |> Poison.encode!
+
+ conn
+ |> json_reply(200, response)
+ end
+
+ def favorite(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+ activity = Repo.get(Activity, id)
+ {:ok, status} = TwitterAPI.favorite(user, activity)
+ response = Poison.encode!(status)
+
+ conn
+ |> json_reply(200, response)
+ end