diff --git a/README.rst b/README.rst index ef65fd8..173734d 100644 --- a/README.rst +++ b/README.rst @@ -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 ~~~~~~~~~~~~~~ diff --git a/pytumblr/__init__.py b/pytumblr/__init__.py index 506ab65..d503a79 100644 --- a/pytumblr/__init__.py +++ b/pytumblr/__init__.py @@ -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): """ @@ -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 diff --git a/tests/test_pytumblr.py b/tests/test_pytumblr.py index 56217df..aa38556 100644 --- a/tests/test_pytumblr.py +++ b/tests/test_pytumblr.py @@ -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": [] } }')