Skip to content

Commit b50974c

Browse files
Carmercarmera
andauthored
adds params to get topic_posts (#226)
Co-authored-by: carmer <carmer.andrew@gmail.com>
1 parent 5a1990a commit b50974c

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lib/discourse_api/api/topics.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,22 @@ def delete_topic(id)
7474
delete("/t/#{id}.json")
7575
end
7676

77-
def topic_posts(topic_id, post_ids = [])
77+
def topic_posts(topic_id, post_ids = [], params = {})
78+
params = API.params(params)
79+
.optional(:asc,
80+
:filter,
81+
:include_raw,
82+
:include_suggested,
83+
:post_number,
84+
:username_filters,
85+
)
86+
7887
url = ["/t/#{topic_id}/posts.json"]
7988
if post_ids.count > 0
8089
url.push('?')
8190
url.push(post_ids.map { |id| "post_ids[]=#{id}" }.join('&'))
8291
end
83-
response = get(url.join)
92+
response = get(url.join, params)
8493
response[:body]
8594
end
8695

spec/discourse_api/api/topics_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@
170170
expect(body['post_stream']['posts']).to be_an Array
171171
expect(body['post_stream']['posts'].first).to be_a Hash
172172
end
173+
174+
it "can retrieve a topic posts' raw attribute" do
175+
body = subject.topic_posts(57, [123], { include_raw: true })
176+
expect(body).to be_a Hash
177+
expect(body['post_stream']['posts']).to be_an Array
178+
expect(body['post_stream']['posts'].first).to be_a Hash
179+
expect(body['post_stream']['posts'].first['raw']).to be_an Array
180+
end
173181
end
174182

175183
describe "#create_topic_with_tags" do

spec/fixtures/topic_posts.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"read":true,
3535
"user_title":null,
3636
"actions_summary":[{"id":2,"count":3,"can_act":true}],
37+
"raw": [{"type":"paragraph","children":[{"text":"This is a raw post I've got white space!... and emojis 😈😈😈😈😈😈"}]}],
3738
"moderator":false,
3839
"admin":false,
3940
"staff":false,

0 commit comments

Comments
 (0)