DEPRECATED: change_topic_status

DEPRECATED: change_topic_status

change_topic_status has been deprecated to remove the unused topic_slug param. A deprecation warning message will now be outputed if you use that method. Please use update_topic_status from now on.

diff --git a/examples/change_topic_status.rb b/examples/change_topic_status.rb
index 504b411..bb0f414 100644
--- a/examples/change_topic_status.rb
+++ b/examples/change_topic_status.rb
@@ -16,9 +16,8 @@ response = client.create_topic(
     raw: "This is the raw markdown for my post"
 )
 
-# get topic_id and topic_slug from response
+# get topic_id from response
 topic_id = response['topic_id']
-topic_slug = response['topic_slug']
 
 ##
 # available options (guessing from reading discourse source)
@@ -28,8 +27,8 @@ topic_slug = response['topic_slug']
 
 # lock topic (note: api_username determines user that is performing action)
 params = { status: 'closed', enabled: true, api_username: "YOUR USERNAME/USERS USERNAME" }
-client.change_topic_status(topic_slug, topic_id, params)
+client.change_topic_status(topic_id, params)
 
 # unlock topic (note: api_username determines user that is performing action)
 params = { status: 'closed', enabled: false, api_username: "YOUR USERNAME/USERS USERNAME" }
-client.change_topic_status(topic_slug, topic_id, params)
+client.change_topic_status(topic_id, params)
diff --git a/lib/discourse_api/api/topics.rb b/lib/discourse_api/api/topics.rb
index 4d2b6f5..9456861 100644
--- a/lib/discourse_api/api/topics.rb
+++ b/lib/discourse_api/api/topics.rb
@@ -42,11 +42,17 @@ module DiscourseApi
         put("/t/#{topic_id}.json", topic_id: topic_id, category_id: category_id)
       end
 
+      # TODO: Deprecated. Remove after 20201231
       def change_topic_status(topic_slug, topic_id, params = {})
+        deprecated(__method__, 'update_topic_status')
+        update_topic_status(topic_id, params)
+      end
+
+      def update_topic_status(topic_id, params = {})
         params = API.params(params)
           .required(:status, :enabled)
           .optional(:api_username)
-        put("/t/#{topic_id}/status", params.to_h)
+        put("/t/#{topic_id}/status", params)
       end
 
       def topic(id, params = {})
diff --git a/lib/discourse_api/client.rb b/lib/discourse_api/client.rb
index 488cd3a..f94a485 100644
--- a/lib/discourse_api/client.rb
+++ b/lib/discourse_api/client.rb
@@ -109,6 +109,10 @@ module DiscourseApi
       @user_agent ||= "DiscourseAPI Ruby Gem #{DiscourseApi::VERSION}"
     end
 
+    def deprecated(old, new)
+      warn "[DEPRECATED]: `#{old}` is deprecated. Please use `#{new}` instead." 
+    end
+
     private
 
     def connection
diff --git a/spec/discourse_api/api/topics_spec.rb b/spec/discourse_api/api/topics_spec.rb
index b73650c..7a10292 100644
--- a/spec/discourse_api/api/topics_spec.rb
+++ b/spec/discourse_api/api/topics_spec.rb
@@ -10,7 +10,7 @@ describe DiscourseApi::API::Topics do
     end
 
     it "changes the topic status" do
-      subject.change_topic_status(nil, 57, { status: 'visible', enabled: false })
+      subject.update_topic_status(57, { status: 'visible', enabled: false })
       expect(a_put("#{host}/t/57/status")).to have_been_made
     end
   end

GitHub sha: 9af21c1a

1 Like