From 0a8cd6bd14633893463326174f9131f43d77f711 Mon Sep 17 00:00:00 2001 From: Nigel2x4 Date: Sun, 31 Mar 2019 15:54:16 +0200 Subject: [PATCH 1/9] Added notes functionality --- pytumblr/__init__.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pytumblr/__init__.py b/pytumblr/__init__.py index d383d7b..a9bd2c6 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 get_post_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 list of tags that you want applied to the post + :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 From aecca5f88b6e132c9a992727e9bd9ac3ef04449a Mon Sep 17 00:00:00 2001 From: Nigel2x4 Date: Sun, 31 Mar 2019 16:10:38 +0200 Subject: [PATCH 2/9] updated parameter messages --- pytumblr/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytumblr/__init__.py b/pytumblr/__init__.py index a9bd2c6..3ce460b 100644 --- a/pytumblr/__init__.py +++ b/pytumblr/__init__.py @@ -495,7 +495,7 @@ def get_post_notes(self, blogname, id, **kwargs): :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 list of tags that you want applied to 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 From 19543aef94dde19b262540d2ea2a39b9de5295be Mon Sep 17 00:00:00 2001 From: Nigel2x4 Date: Sun, 31 Mar 2019 16:38:56 +0200 Subject: [PATCH 3/9] refactored name to be more pytumblr like --- pytumblr/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytumblr/__init__.py b/pytumblr/__init__.py index 3ce460b..21a74fa 100644 --- a/pytumblr/__init__.py +++ b/pytumblr/__init__.py @@ -489,7 +489,7 @@ def edit_post(self, blogname, **kwargs): return self.send_api_request('post', url, kwargs, valid_options) @validate_blogname - def get_post_notes(self, blogname, id, **kwargs): + def notes_post(self, blogname, id, **kwargs): """ Gets the notes From 9938b398b2e8f89ecfcb02b4c628073bdd008dfd Mon Sep 17 00:00:00 2001 From: Nigel2x4 Date: Sun, 7 Apr 2019 13:09:27 +0200 Subject: [PATCH 4/9] updated documentation --- README.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.rst b/README.rst index ef65fd8..ceabc9c 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_post(blogName, id='123456') + +The results include a timestamp you can use to make future calls. + +.. code:: python + + data = client.notes_post(blogName, id='123456', before_timestamp=data["_links"]["next"]["query_params"]["before_timestamp"]) + + Tagged Methods ~~~~~~~~~~~~~~ From 16b1b12e528d81dd5e176cfdb9827d47e4747724 Mon Sep 17 00:00:00 2001 From: Evil Blonde Date: Mon, 1 Jul 2019 13:34:28 +0200 Subject: [PATCH 5/9] updates method name to be more concrete changes notes_post to notes --- pytumblr/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytumblr/__init__.py b/pytumblr/__init__.py index 21a74fa..8881588 100644 --- a/pytumblr/__init__.py +++ b/pytumblr/__init__.py @@ -489,7 +489,7 @@ def edit_post(self, blogname, **kwargs): return self.send_api_request('post', url, kwargs, valid_options) @validate_blogname - def notes_post(self, blogname, id, **kwargs): + def notes(self, blogname, id, **kwargs): """ Gets the notes From 386c27bfda4979eafd73d119f9f0138db6fecfe3 Mon Sep 17 00:00:00 2001 From: Evil Blonde Date: Mon, 1 Jul 2019 14:18:43 +0200 Subject: [PATCH 6/9] Updated README.MD to reflect notes name change --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index ceabc9c..173734d 100644 --- a/README.rst +++ b/README.rst @@ -232,13 +232,13 @@ In order to get the notes for a post, you need to have the post id and the blog .. code:: python - data = client.notes_post(blogName, id='123456') + data = client.notes(blogName, id='123456') The results include a timestamp you can use to make future calls. .. code:: python - data = client.notes_post(blogName, id='123456', before_timestamp=data["_links"]["next"]["query_params"]["before_timestamp"]) + data = client.notes(blogName, id='123456', before_timestamp=data["_links"]["next"]["query_params"]["before_timestamp"]) Tagged Methods From ec182dc35335fde78a0a60a684c63d3b8aa01e0d Mon Sep 17 00:00:00 2001 From: Nigel2x4 Date: Mon, 1 Jul 2019 23:21:40 +0200 Subject: [PATCH 7/9] created simple unit test --- tests/test_pytumblr.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/test_pytumblr.py b/tests/test_pytumblr.py index 9029a72..4e420b1 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": [] } }') @@ -175,6 +182,7 @@ def test_reblog(self, mock_post): assert parse_qs(mock_post.data) == parse_qs('state=coolguy&reblog_key=adsfsadf&id=123&tags=hello%2Cworld') + @mock.patch('requests.post') def test_edit_post(self, mock_post): mock_post.side_effect = wrap_response_storing_data( @@ -314,5 +322,7 @@ def test_create_video(self, mock_post): assert response == [] + + if __name__ == "__main__": unittest.main() From 13d6b00ca0051941deb74f21ecee1add41f77c6c Mon Sep 17 00:00:00 2001 From: Nigel2x4 Date: Mon, 1 Jul 2019 23:26:08 +0200 Subject: [PATCH 8/9] fixed uneven quotations in elements --- pytumblr/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytumblr/__init__.py b/pytumblr/__init__.py index 8881588..361556d 100644 --- a/pytumblr/__init__.py +++ b/pytumblr/__init__.py @@ -501,7 +501,7 @@ def notes(self, blogname, id, **kwargs): :returns: a dict created from the JSON response """ url = "/v2/blog/{}/notes".format(blogname) - valid_options = ['id', "mode", "before_timestamp"] + valid_options = ["id", "mode", "before_timestamp"] kwargs.update({"id":id}) return self.send_api_request('get', url, kwargs, valid_options) From 9c09e8ffa8a59c79149621602ba36ac3b68c6496 Mon Sep 17 00:00:00 2001 From: Evil Blonde Date: Mon, 1 Jul 2019 23:50:43 +0200 Subject: [PATCH 9/9] Fixed mock json data and removed whitespacing --- tests/test_pytumblr.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test_pytumblr.py b/tests/test_pytumblr.py index 4e420b1..c5d9585 100644 --- a/tests/test_pytumblr.py +++ b/tests/test_pytumblr.py @@ -116,7 +116,7 @@ def test_blogLikes_with_after(self, mock_get): @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} }') + 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"] == [] @@ -182,7 +182,6 @@ def test_reblog(self, mock_post): assert parse_qs(mock_post.data) == parse_qs('state=coolguy&reblog_key=adsfsadf&id=123&tags=hello%2Cworld') - @mock.patch('requests.post') def test_edit_post(self, mock_post): mock_post.side_effect = wrap_response_storing_data( @@ -322,7 +321,5 @@ def test_create_video(self, mock_post): assert response == [] - - if __name__ == "__main__": unittest.main()