Skip to content

Commit c831b38

Browse files
authored
Merge pull request #133 from Nigel2x4/notes
Added ability to retrieve notes
2 parents 551dfb3 + 9c09e8f commit c831b38

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

README.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,22 @@ A note on tags: When passing tags, as params, please pass them as a list (not a
225225
226226
client.create_text(blogName, tags=['hello', 'world'], ...)
227227
228+
Getting notes for a post
229+
^^^^^^^^^^^^^^^^^^^^^^^^
230+
231+
In order to get the notes for a post, you need to have the post id and the blog that it is on.
232+
233+
.. code:: python
234+
235+
data = client.notes(blogName, id='123456')
236+
237+
The results include a timestamp you can use to make future calls.
238+
239+
.. code:: python
240+
241+
data = client.notes(blogName, id='123456', before_timestamp=data["_links"]["next"]["query_params"]["before_timestamp"])
242+
243+
228244
Tagged Methods
229245
~~~~~~~~~~~~~~
230246

pytumblr/__init__.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def blog_following(self, blogname, **kwargs):
164164
"""
165165
url = "/v2/blog/{}/following".format(blogname)
166166
return self.send_api_request("get", url, kwargs, ['limit', 'offset'])
167-
167+
168168
@validate_blogname
169169
def followers(self, blogname, **kwargs):
170170
"""
@@ -488,6 +488,23 @@ def edit_post(self, blogname, **kwargs):
488488
valid_options = ['id'] + self._post_valid_options(kwargs.get('type', None))
489489
return self.send_api_request('post', url, kwargs, valid_options)
490490

491+
@validate_blogname
492+
def notes(self, blogname, id, **kwargs):
493+
"""
494+
Gets the notes
495+
496+
:param blogname: a string, the url of the blog that houses the post
497+
:param id: a string, the id of the post.
498+
:param mode: a string. Undocumented. Automatically added by tumblr but it's use is not yet known.
499+
:param before_timestamp: a string, retreives data before this timestamp
500+
501+
:returns: a dict created from the JSON response
502+
"""
503+
url = "/v2/blog/{}/notes".format(blogname)
504+
valid_options = ["id", "mode", "before_timestamp"]
505+
kwargs.update({"id":id})
506+
return self.send_api_request('get', url, kwargs, valid_options)
507+
491508
# Parameters valid for /post, /post/edit, and /post/reblog.
492509
def _post_valid_options(self, post_type=None):
493510
# These options are always valid

tests/test_pytumblr.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ def test_blogLikes_with_after(self, mock_get):
114114
response = self.client.blog_likes('codingjester.tumblr.com', after=1418684291)
115115
assert response['liked_posts'] == []
116116

117+
@mock.patch('requests.get')
118+
def test_notes(self, mock_get):
119+
mock_get.side_effect = wrap_response('{"meta": {"status": 200, "msg": "OK"}, "response": {"notes": [], "total_notes": 1, "can_hide_or_delete_notes": false} }')
120+
121+
response = self.client.notes('codingjester.tumblr.com', id='123456789098')
122+
assert response["notes"] == []
123+
117124
@mock.patch('requests.get')
118125
def test_blogLikes_with_before(self, mock_get):
119126
mock_get.side_effect = wrap_response('{"meta": {"status": 200, "msg": "OK"}, "response": {"liked_posts": [] } }')

0 commit comments

Comments
 (0)