From 123b8f4f74a7e1322bc602f66e6e962dc5ff767a Mon Sep 17 00:00:00 2001 From: Ben McGinnes Date: Sun, 2 Nov 2014 10:41:56 +1100 Subject: [PATCH 1/3] Added the create, destroy, list and list IDs mute(s) endpoints. Roughly modelled on the similar-ish block user functions (note: the "mutes/users" instead of just "mutes" appears to be intentional by Twitter). Also added myself to AUTHORS.rst because I reckon adding API bits makes the grade. ;) --- AUTHORS.rst | 1 + twython/endpoints.py | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index 24bd911..8a16050 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -54,3 +54,4 @@ Patches and Suggestions - `Mertcan Mermerkaya `_, Fixed code example in documentation - `Donne Martin `_, Fixed typos in `README.rst` - `Diego Allen `_, Add missing comma in documentation code snippet +- `Ben McGinnes `_, Added mute API endpoints, a couple of examples, random bits. diff --git a/twython/endpoints.py b/twython/endpoints.py index 444a920..7ac9961 100644 --- a/twython/endpoints.py +++ b/twython/endpoints.py @@ -523,6 +523,46 @@ class EndpointsMixin(object): """ return self.get('users/profile_banner', params=params) + def list_mutes(self, **params): + """Returns a collection of user objects that the authenticating user + is muting. + + Docs: https://dev.twitter.com/docs/api/1.1/get/mutes/users/list + + """ + return self.get('mutes/users/list', params=params) + list_mutes.iter_mode = 'cursor' + list_mutes.iter_key = 'users' + + def list_mute_ids(self, **params): + """Returns an array of numeric user ids the authenticating user + is muting. + + Docs: https://dev.twitter.com/docs/api/1.1/get/mutes/users/ids + + """ + return self.get('mutes/users/ids', params=params) + list_mutes_ids.iter_mode = 'cursor' + list_mutes_ids.iter_key = 'ids' + + def create_mute(self, **params): + """Mutes the specified user, preventing their tweets appearing + in the authenticating user's timeline. + + Docs: https://dev.twitter.com/docs/api/1.1/post/mutes/users/create + + """ + return self.post('mutes/users/create', params=params) + + def destroy_mute(self, **params): + """Un-mutes the user specified in the user or ID parameter for + the authenticating user. + + Docs: https://dev.twitter.com/docs/api/1.1/post/mutes/users/destroy + + """ + return self.post('mutes/users/destroy', params=params) + # Suggested Users def get_user_suggestions_by_slug(self, **params): """Access the users in a given category of the Twitter suggested user list. From b5847e3e84f76a9659305580e9042d33af0fa870 Mon Sep 17 00:00:00 2001 From: Ben McGinnes Date: Sun, 2 Nov 2014 14:15:37 +1100 Subject: [PATCH 2/3] Added muting to test suite. I should have checked for this earlier, ah well, 'tis here now. Again, basically a copy of the blocking code updated for muting. Excellent target to test it on too. --- tests/test_endpoints.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index b7478d0..aa79998 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -305,6 +305,28 @@ class TwythonEndpointsTestCase(unittest.TestCase): we have not uploaded a profile banner""" self.assertRaises(TwythonError, self.api.get_profile_banner_sizes) + @unittest.skip('skipping non-updated test') + def test_list_mutes(self): + """Test listing users who are muted by the authenticated user + succeeds""" + self.api.list_mutes() + + @unittest.skip('skipping non-updated test') + def test_list_mute_ids(self): + """Test listing user ids who are muted by the authenticated user + succeeds""" + self.api.list_mute_ids() + + @unittest.skip('skipping non-updated test') + def test_create_mute(self): + """Test muting a user succeeds""" + self.api.create_mute(screen_name='justinbieber') + + @unittest.skip('skipping non-updated test') + def test_destroy_mute(self): + """Test muting a user succeeds""" + self.api.destroy_mute(screen_name='justinbieber') + # Suggested Users @unittest.skip('skipping non-updated test') def test_get_user_suggestions_by_slug(self): From 036760bfd4a3d06b534be06bc3a56843ccb84868 Mon Sep 17 00:00:00 2001 From: Ben McGinnes Date: Sun, 2 Nov 2014 16:04:39 +1100 Subject: [PATCH 3/3] Fixed typo with list_mute_ids. --- twython/endpoints.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/twython/endpoints.py b/twython/endpoints.py index 7ac9961..81aa582 100644 --- a/twython/endpoints.py +++ b/twython/endpoints.py @@ -542,8 +542,8 @@ class EndpointsMixin(object): """ return self.get('mutes/users/ids', params=params) - list_mutes_ids.iter_mode = 'cursor' - list_mutes_ids.iter_key = 'ids' + list_mute_ids.iter_mode = 'cursor' + list_mute_ids.iter_key = 'ids' def create_mute(self, **params): """Mutes the specified user, preventing their tweets appearing