Skip to content

Commit

Permalink
Merge pull request #88 from Dettorer/add-endpoint-post-by-number
Browse files Browse the repository at this point in the history
Add a wrapper for the /posts/by_number endpoint
  • Loading branch information
bennylope committed Sep 1, 2023
2 parents 565b714 + f94d861 commit d8ec2f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/pydiscourse/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,19 @@ def post_by_id(self, post_id, **kwargs):
"""
return self._get(f"/posts/{post_id}.json", **kwargs)

def post_by_number(self, topic_id, post_number, **kwargs):
"""
Get a post from its number inside a specific topic
Args:
topic_id: the topic the post belongs to
post_number: the number of the post inside the topic
**kwargs:
Returns:
post
"""
return self._get(f"/posts/by_number/{topic_id}/{post_number}", **kwargs)

def posts(self, topic_id, post_ids=None, **kwargs):
"""
Get a set of posts from a topic
Expand Down
9 changes: 9 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ def test_latest_posts(self, discourse_client, requests_mock):
discourse_client.latest_posts(before=54321)
assert request.called_once

def test_post_by_number(self, discourse_client, requests_mock):
request = requests_mock.get(
f"{discourse_client.host}/posts/by_number/8796/5",
headers={"Content-Type": "application/json; charset=utf-8"},
json={},
)
discourse_client.post_by_number(8796, 5)
assert request.called_once

def test_search(self, discourse_client, requests_mock):
request = requests_mock.get(
f"{discourse_client.host}/search.json?term=needle",
Expand Down

0 comments on commit d8ec2f6

Please sign in to comment.