Allow bookmarking topic (#224)

Allow bookmarking topic (#224)

Co-authored-by: Akshay Birajdar akshaybirajdar05@gmail.com

diff --git a/examples/bookmark_topic.rb b/examples/bookmark_topic.rb
new file mode 100644
index 0000000..72334a3
--- /dev/null
+++ b/examples/bookmark_topic.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
+require File.expand_path('../../lib/discourse_api', __FILE__)
+
+config = DiscourseApi::ExampleHelper.load_yml
+
+client = DiscourseApi::Client.new(config['host'] || 'http://localhost:3000')
+client.api_key = config['api_key'] || "YOUR_API_KEY"
+client.api_username = config['api_username'] || "YOUR_USERNAME"
+
+# Bookmark topic
+puts client.bookmark_topic(1418)
+
+# Remove bookmark from topic
+puts client.remove_topic_bookmark(1418)
diff --git a/lib/discourse_api/api/topics.rb b/lib/discourse_api/api/topics.rb
index ad40600..7d101ea 100644
--- a/lib/discourse_api/api/topics.rb
+++ b/lib/discourse_api/api/topics.rb
@@ -96,6 +96,14 @@ module DiscourseApi
           .required(:notification_level)
         post("/t/#{topic_id}/notifications", params)
       end
+
+      def bookmark_topic(topic_id)
+        put("/t/#{topic_id}/bookmark.json")
+      end
+
+      def remove_topic_bookmark(topic_id)
+        put("/t/#{topic_id}/remove_bookmarks.json")
+      end
     end
   end
 end
diff --git a/spec/discourse_api/api/topics_spec.rb b/spec/discourse_api/api/topics_spec.rb
index c3538de..2617424 100644
--- a/spec/discourse_api/api/topics_spec.rb
+++ b/spec/discourse_api/api/topics_spec.rb
@@ -200,4 +200,28 @@ describe DiscourseApi::API::Topics do
       expect(response['success']).to eq('OK')
     end
   end
+
+  describe "#bookmark_topic" do
+    before do
+      stub_put("#{host}/t/1/bookmark.json").to_return(body: "", headers: { content_type: "application/json" })
+    end
+
+    it "makes the put request" do
+      response = subject.bookmark_topic(1)
+      expect(a_put("#{host}/t/1/bookmark.json")).to have_been_made
+      expect(response.body).to eq(nil)
+    end
+  end
+
+  describe "#remove_topic_bookmark" do
+    before do
+      stub_put("#{host}/t/1/remove_bookmarks.json").to_return(body: "", headers: { content_type: "application/json" })
+    end
+
+    it "makes the put request" do
+      response = subject.remove_topic_bookmark(1)
+      expect(a_put("#{host}/t/1/remove_bookmarks.json")).to have_been_made
+      expect(response.body).to eq(nil)
+    end
+  end
 end

GitHub sha: b1e14bd4

This commit appears in #224 which was approved by blake. It was merged by blake.