From 1194b9bee601d16414f320e5b6c31b17f801b069 Mon Sep 17 00:00:00 2001 From: Taro Sato Date: Fri, 18 Oct 2019 15:38:00 -0700 Subject: [PATCH] Implement lists/ownerships --- cassettes/testlistsownerships.json | 99 ++++++++++++++++++++++++++++++ docs/api.rst | 15 +++++ tests/test_api.py | 4 ++ tweepy/api.py | 17 ++++- tweepy/models.py | 5 ++ 5 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 cassettes/testlistsownerships.json diff --git a/cassettes/testlistsownerships.json b/cassettes/testlistsownerships.json new file mode 100644 index 0000000..6a1130c --- /dev/null +++ b/cassettes/testlistsownerships.json @@ -0,0 +1,99 @@ +{ + "version": 1, + "interactions": [ + { + "request": { + "method": "GET", + "uri": "https://api.twitter.com/1.1/lists/ownerships.json", + "body": null, + "headers": { + "Host": [ + "api.twitter.com" + ] + } + }, + "response": { + "status": { + "code": 200, + "message": "OK" + }, + "headers": { + "content-type": [ + "application/json;charset=utf-8" + ], + "x-xss-protection": [ + "1; mode=block; report=https://twitter.com/i/xss_report" + ], + "x-content-type-options": [ + "nosniff" + ], + "expires": [ + "Tue, 31 Mar 1981 05:00:00 GMT" + ], + "last-modified": [ + "Sat, 13 Jul 2019 02:27:44 GMT" + ], + "server": [ + "tsa_b" + ], + "cache-control": [ + "no-cache, no-store, must-revalidate, pre-check=0, post-check=0" + ], + "x-connection-hash": [ + "25037a788cfa5c2a5a6656add6da8d4d" + ], + "x-rate-limit-limit": [ + "75" + ], + "x-frame-options": [ + "SAMEORIGIN" + ], + "x-rate-limit-remaining": [ + "70" + ], + "pragma": [ + "no-cache" + ], + "date": [ + "Sat, 13 Jul 2019 02:27:44 GMT" + ], + "status": [ + "200 OK" + ], + "set-cookie": [ + "personalization_id=\"v1_BGYj/OZeMyqRo/ANrpX+KA==\"; Max-Age=63072000; Expires=Mon, 12 Jul 2021 02:27:44 GMT; Path=/; Domain=.twitter.com", + "lang=en; Path=/", + "guest_id=v1%3A156298486472902530; Max-Age=63072000; Expires=Mon, 12 Jul 2021 02:27:44 GMT; Path=/; Domain=.twitter.com" + ], + "x-access-level": [ + "read-write-directmessages" + ], + "x-twitter-response-tags": [ + "BouncerCompliant" + ], + "x-transaction": [ + "00bcf3d1008d708d" + ], + "strict-transport-security": [ + "max-age=631138519" + ], + "content-disposition": [ + "attachment; filename=json.json" + ], + "content-length": [ + "96" + ], + "x-response-time": [ + "17" + ], + "x-rate-limit-reset": [ + "1562984893" + ] + }, + "body": { + "string": "{\"next_cursor\":0,\"next_cursor_str\":\"0\",\"previous_cursor\":0,\"previous_cursor_str\":\"0\",\"lists\":[]}" + } + } + } + ] +} diff --git a/docs/api.rst b/docs/api.rst index 244ef6c..c23a23d 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -849,6 +849,21 @@ List Methods :rtype: list of :class:`List` objects +.. method:: API.lists_ownerships([screen_name], [user_id], [cursor], \ + [count]) + + Returns the lists owned by the specified user. Private lists will + only be shown if the authenticated user is also the owner of the + lists. If ``user_id`` or ``screen_name`` are not provided, the + memberships for the authenticating user are returned. + + :param screen_name: |screen_name| + :param user_id: |user_id| + :param cursor: |cursor| + :param count: |count| + :rtype: list of :class:`List` objects + + .. method:: API.lists_subscriptions([screen_name], [user_id], [cursor], \ [count]) diff --git a/tests/test_api.py b/tests/test_api.py index 72a4c0e..f8b4aad 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -286,6 +286,10 @@ class TweepyAPITests(TweepyTestCase): def testlistsmemberships(self): self.api.lists_memberships() + @tape.use_cassette('testlistsownerships.json') + def testlistsownerships(self): + self.api.lists_ownerships() + @tape.use_cassette('testlistssubscriptions.json') def testlistssubscriptions(self): self.api.lists_subscriptions() diff --git a/tweepy/api.py b/tweepy/api.py index c8551a3..d1651eb 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -819,7 +819,7 @@ class API(object): allowed_param=['cursor'], require_auth=True ) - + @property def mutes(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/mute-block-report-users/api-reference/get-mutes-users-list @@ -832,7 +832,7 @@ class API(object): allowed_param=['cursor', 'include_entities', 'skip_status'], required_auth=True ) - + @property def create_mute(self): @@ -1025,6 +1025,19 @@ class API(object): require_auth=True ) + @property + def lists_ownerships(self): + """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-ownerships + :allowed_param: 'screen_name', 'user_id', 'cursor', 'count' + """ + return bind_api( + api=self, + path='/lists/ownerships.json', + payload_type='list', payload_list=True, + allowed_param=['screen_name', 'user_id', 'cursor', 'count'], + require_auth=True + ) + @property def lists_subscriptions(self): """ :reference: https://developer.twitter.com/en/docs/accounts-and-users/create-manage-lists/api-reference/get-lists-subscriptions diff --git a/tweepy/models.py b/tweepy/models.py index 7c33d8f..ba4a684 100644 --- a/tweepy/models.py +++ b/tweepy/models.py @@ -196,6 +196,11 @@ class User(Model): *args, **kwargs) + def lists_ownerships(self, *args, **kwargs): + return self._api.lists_ownerships(user=self.screen_name, + *args, + **kwargs) + def lists_subscriptions(self, *args, **kwargs): return self._api.lists_subscriptions(user=self.screen_name, *args, -- 2.25.1