Skip to content

Commit b1e14bd

Browse files
Allow bookmarking topic (#224)
Co-authored-by: Akshay Birajdar <akshaybirajdar05@gmail.com>
1 parent abfb54d commit b1e14bd

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

examples/bookmark_topic.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
3+
require File.expand_path('../../lib/discourse_api', __FILE__)
4+
5+
config = DiscourseApi::ExampleHelper.load_yml
6+
7+
client = DiscourseApi::Client.new(config['host'] || 'http://localhost:3000')
8+
client.api_key = config['api_key'] || "YOUR_API_KEY"
9+
client.api_username = config['api_username'] || "YOUR_USERNAME"
10+
11+
# Bookmark topic
12+
puts client.bookmark_topic(1418)
13+
14+
# Remove bookmark from topic
15+
puts client.remove_topic_bookmark(1418)

lib/discourse_api/api/topics.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ def topic_set_user_notification_level(topic_id, params)
9696
.required(:notification_level)
9797
post("/t/#{topic_id}/notifications", params)
9898
end
99+
100+
def bookmark_topic(topic_id)
101+
put("/t/#{topic_id}/bookmark.json")
102+
end
103+
104+
def remove_topic_bookmark(topic_id)
105+
put("/t/#{topic_id}/remove_bookmarks.json")
106+
end
99107
end
100108
end
101109
end

spec/discourse_api/api/topics_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,28 @@
200200
expect(response['success']).to eq('OK')
201201
end
202202
end
203+
204+
describe "#bookmark_topic" do
205+
before do
206+
stub_put("#{host}/t/1/bookmark.json").to_return(body: "", headers: { content_type: "application/json" })
207+
end
208+
209+
it "makes the put request" do
210+
response = subject.bookmark_topic(1)
211+
expect(a_put("#{host}/t/1/bookmark.json")).to have_been_made
212+
expect(response.body).to eq(nil)
213+
end
214+
end
215+
216+
describe "#remove_topic_bookmark" do
217+
before do
218+
stub_put("#{host}/t/1/remove_bookmarks.json").to_return(body: "", headers: { content_type: "application/json" })
219+
end
220+
221+
it "makes the put request" do
222+
response = subject.remove_topic_bookmark(1)
223+
expect(a_put("#{host}/t/1/remove_bookmarks.json")).to have_been_made
224+
expect(response.body).to eq(nil)
225+
end
226+
end
203227
end

0 commit comments

Comments
 (0)