Implement lists/ownerships
authorTaro Sato <okomestudio@gmail.com>
Fri, 18 Oct 2019 22:38:00 +0000 (15:38 -0700)
committerTaro Sato <okomestudio@gmail.com>
Fri, 18 Oct 2019 22:38:00 +0000 (15:38 -0700)
cassettes/testlistsownerships.json [new file with mode: 0644]
docs/api.rst
tests/test_api.py
tweepy/api.py
tweepy/models.py

diff --git a/cassettes/testlistsownerships.json b/cassettes/testlistsownerships.json
new file mode 100644 (file)
index 0000000..6a1130c
--- /dev/null
@@ -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\":[]}"
+                }
+            }
+        }
+    ]
+}
index 244ef6ca9096a09c8ce85ae35094b6287c9c0414..c23a23d94ba8b491b74278a2c1020a8ceb035192 100644 (file)
@@ -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])
 
index 72a4c0e10c48f182fa1500a9798d003862112ae6..f8b4aad002f1d51658101755f3cd492ae2741504 100644 (file)
@@ -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()
index c8551a3b6fbea0a699d244fca132415bff2ea56e..d1651ebed204183729db52e6ebbfe2e7496182aa 100644 (file)
@@ -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
index 7c33d8f52453d2d4c8f54d0fac35493af18da013..ba4a6847a845edd5c37c00848d7491727a93bfea 100644 (file)
@@ -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,