Skip to content

Commit

Permalink
Merge pull request #133 from Nigel2x4/notes
Browse files Browse the repository at this point in the history
Added ability to retrieve notes
  • Loading branch information
komapa authored Jul 11, 2019
2 parents 551dfb3 + 9c09e8f commit c831b38
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
16 changes: 16 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,22 @@ A note on tags: When passing tags, as params, please pass them as a list (not a
client.create_text(blogName, tags=['hello', 'world'], ...)
Getting notes for a post
^^^^^^^^^^^^^^^^^^^^^^^^

In order to get the notes for a post, you need to have the post id and the blog that it is on.

.. code:: python
data = client.notes(blogName, id='123456')
The results include a timestamp you can use to make future calls.

.. code:: python
data = client.notes(blogName, id='123456', before_timestamp=data["_links"]["next"]["query_params"]["before_timestamp"])
Tagged Methods
~~~~~~~~~~~~~~

Expand Down
19 changes: 18 additions & 1 deletion pytumblr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def blog_following(self, blogname, **kwargs):
"""
url = "/v2/blog/{}/following".format(blogname)
return self.send_api_request("get", url, kwargs, ['limit', 'offset'])

@validate_blogname
def followers(self, blogname, **kwargs):
"""
Expand Down Expand Up @@ -488,6 +488,23 @@ def edit_post(self, blogname, **kwargs):
valid_options = ['id'] + self._post_valid_options(kwargs.get('type', None))
return self.send_api_request('post', url, kwargs, valid_options)

@validate_blogname
def notes(self, blogname, id, **kwargs):
"""
Gets the notes
:param blogname: a string, the url of the blog that houses the post
:param id: a string, the id of the post.
:param mode: a string. Undocumented. Automatically added by tumblr but it's use is not yet known.
:param before_timestamp: a string, retreives data before this timestamp
:returns: a dict created from the JSON response
"""
url = "/v2/blog/{}/notes".format(blogname)
valid_options = ["id", "mode", "before_timestamp"]
kwargs.update({"id":id})
return self.send_api_request('get', url, kwargs, valid_options)

# Parameters valid for /post, /post/edit, and /post/reblog.
def _post_valid_options(self, post_type=None):
# These options are always valid
Expand Down
7 changes: 7 additions & 0 deletions tests/test_pytumblr.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ def test_blogLikes_with_after(self, mock_get):
response = self.client.blog_likes('codingjester.tumblr.com', after=1418684291)
assert response['liked_posts'] == []

@mock.patch('requests.get')
def test_notes(self, mock_get):
mock_get.side_effect = wrap_response('{"meta": {"status": 200, "msg": "OK"}, "response": {"notes": [], "total_notes": 1, "can_hide_or_delete_notes": false} }')

response = self.client.notes('codingjester.tumblr.com', id='123456789098')
assert response["notes"] == []

@mock.patch('requests.get')
def test_blogLikes_with_before(self, mock_get):
mock_get.side_effect = wrap_response('{"meta": {"status": 200, "msg": "OK"}, "response": {"liked_posts": [] } }')
Expand Down

0 comments on commit c831b38

Please sign in to comment.