diff options
Diffstat (limited to 'lib/pleroma/web')
-rw-r--r-- | lib/pleroma/web/router.ex | 1 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/twitter_api.ex | 8 | ||||
-rw-r--r-- | lib/pleroma/web/twitter_api/twitter_api_controller.ex | 9 |
3 files changed, 18 insertions, 0 deletions
diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index c34f03cbb..6d854c538 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -31,5 +31,6 @@ defmodule Pleroma.Web.Router do post "/account/verify_credentials.json", TwitterAPI.Controller, :verify_credentials post "/statuses/update.json", TwitterAPI.Controller, :status_update get "/statuses/friends_timeline.json", TwitterAPI.Controller, :friends_timeline + post "/friendships/create.json", TwitterAPI.Controller, :follow end end diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 7e0ca4233..fb093b227 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -34,6 +34,14 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do |> activities_to_statuses end + def follow(%User{} = follower, followed_id) do + with %User{} = followed <- Repo.get(User, followed_id), + { :ok, follower } <- User.follow(follower, followed) + do + { :ok, follower, followed } + end + end + defp activities_to_statuses(activities) do Enum.map(activities, fn(activity) -> actor = get_in(activity.data, ["actor"]) diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 088439f48..ac319b109 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -32,6 +32,15 @@ defmodule Pleroma.Web.TwitterAPI.Controller do |> json_reply(200, json) end + def follow(%{assigns: %{user: user}} = conn, %{ "user_id" => followed_id }) do + { :ok, _user, follower } = TwitterAPI.follow(user, followed_id) + + response = follower |> UserRepresenter.to_json + + conn + |> json_reply(200, response) + end + defp json_reply(conn, status, json) do conn |> put_resp_content_type("application/json") |