Add retweeting to TwAPI controller.
authorRoger Braun <roger@rogerbraun.net>
Sat, 15 Apr 2017 12:09:54 +0000 (14:09 +0200)
committerRoger Braun <roger@rogerbraun.net>
Sat, 15 Apr 2017 12:09:54 +0000 (14:09 +0200)
lib/pleroma/web/router.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex
test/web/twitter_api/twitter_api_controller_test.exs

index 7e4866c2f2ab3e728215614d8c5e8a6aa836e6be..7bb3c9763e79ae8c71394ac15cb679fd2f8aef04 100644 (file)
@@ -43,5 +43,6 @@ defmodule Pleroma.Web.Router do
     post "/favorites/create/:id", TwitterAPI.Controller, :favorite
     post "/favorites/create", TwitterAPI.Controller, :favorite
     post "/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite
+    post "/statuses/retweet/:id", TwitterAPI.Controller, :retweet
   end
 end
index c71c123b21c276cc5f4c62f704e302d7d44fd4e6..a4d8a1d14ee44e2067c8a252313b7a513069bbcc 100644 (file)
@@ -122,6 +122,15 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
     |> json_reply(200, response)
   end
 
+  def retweet(%{assigns: %{user: user}} = conn, %{"id" => id}) do
+    activity = Repo.get(Activity, id)
+    {:ok, status} = TwitterAPI.retweet(user, activity)
+    response = Poison.encode!(status)
+
+    conn
+    |> json_reply(200, response)
+  end
+
   defp json_reply(conn, status, json) do
     conn
     |> put_resp_content_type("application/json")
index 814f457b98037a95c661e0e3b4bccb0e21a42715..0eb1b60c528dd3be3d89f8ef76ebf21e85f6cb35 100644 (file)
@@ -197,6 +197,25 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
     end
   end
 
+  describe "POST /api/statuses/retweet/:id" do
+    setup [:valid_user]
+    test "without valid credentials", %{conn: conn} do
+      note_activity = insert(:note_activity)
+      conn = post conn, "/api/statuses/retweet/#{note_activity.id}.json"
+      assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+    end
+
+    test "with credentials", %{conn: conn, user: current_user} do
+      note_activity = insert(:note_activity)
+
+      conn = conn
+      |> with_credentials(current_user.nickname, "test")
+      |> post("/api/statuses/retweet/#{note_activity.id}.json")
+
+      assert json_response(conn, 200)
+    end
+  end
+
   defp valid_user(_context) do
     { :ok, user } = UserBuilder.insert(%{nickname: "lambda", ap_id: "lambda"})
     [user: user]