Add Client.get_space_buyers
authorHarmon <Harmon758@gmail.com>
Wed, 17 Nov 2021 13:38:45 +0000 (07:38 -0600)
committerHarmon <Harmon758@gmail.com>
Wed, 17 Nov 2021 13:38:45 +0000 (07:38 -0600)
docs/client.rst
tests/test_client.py
tweepy/client.py

index c93b25c5adfdad5e882ed0d2d9f444349e59c608..bf0bc4bd083c1b96a5db0ad5492174fb94027797 100644 (file)
     +--------------------------------------------------------------+----------------------------------------+
     | `GET /2/spaces`_                                             | :meth:`Client.get_spaces`              |
     +--------------------------------------------------------------+----------------------------------------+
-    | `GET /2/spaces/by/creator_ids`_                              | :meth:`Client.get_spaces`              |
-    +--------------------------------------------------------------+----------------------------------------+
     | `GET /2/spaces/:id`_                                         | :meth:`Client.get_space`               |
     +--------------------------------------------------------------+----------------------------------------+
+    | `GET /2/spaces/:id/buyers`_                                  | :meth:`Client.get_space_buyers`        |
+    +--------------------------------------------------------------+----------------------------------------+
+    | `GET /2/spaces/by/creator_ids`_                              | :meth:`Client.get_spaces`              |
+    +--------------------------------------------------------------+----------------------------------------+
     | .. centered:: :ref:`Lists`                                                                            |
     +-------------------------------------------------------------------------------------------------------+
     | .. centered:: |List Tweets lookup|_                                                                   |
 .. _GET /2/spaces/search: https://developer.twitter.com/en/docs/twitter-api/spaces/search/api-reference/get-spaces-search
 .. |Spaces lookup| replace:: *Spaces lookup*
 .. _GET /2/spaces: https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces
-.. _GET /2/spaces/by/creator_ids: https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-by-creator-ids
 .. _GET /2/spaces/:id: https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id
+.. _GET /2/spaces/:id/buyers: https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id-buyers
+.. _GET /2/spaces/by/creator_ids: https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-by-creator-ids
 .. |List Tweets lookup| replace:: *List Tweets lookup*
 .. _GET /2/lists/:id/tweets: https://developer.twitter.com/en/docs/twitter-api/lists/list-tweets/api-reference/get-lists-id-tweets
 .. |List follows| replace:: *List follows*
@@ -382,6 +385,8 @@ Spaces lookup
 
 .. automethod:: Client.get_space
 
+.. automethod:: Client.get_space_buyers
+
 Lists
 =====
 
index eb3aa5891efcba6dae7a196332b07e9569d226e5..02ebed82bc42193d257d1c895bdba0ae908c2de2 100644 (file)
@@ -154,6 +154,8 @@ class TweepyTestCase(unittest.TestCase):
         # https://twitter.com/TwitterSpaces/status/1436382283347283969
         self.client.get_space(space_id)
 
+    # TODO: Test Client.get_space_buyers
+
     @tape.use_cassette("test_get_list_tweets.yaml", serializer="yaml")
     def test_get_list_tweets(self):
         list_id = 84839422  # List ID for Official Twitter Accounts (@Twitter)
index 1a05640472d2cfc61ab07b3329592a72ebd01cde..de689a681cd5c04049ded2e3efdf8813b93bbb39 100644 (file)
@@ -1865,6 +1865,48 @@ class Client:
             ), data_type=Space
         )
 
+    def get_space_buyers(self, id, **params):
+        """get_space_buyers(id, *, expansions, media_fields, place_fields, \
+                            poll_fields, tweet_fields, user_fields)
+
+        Returns a list of user who purchased a ticket to the requested Space.
+        You must authenticate the request using the Access Token of the creator
+        of the requested Space.
+
+        Parameters
+        ----------
+        id : str
+            Unique identifier of the Space for which you want to request
+            Tweets.
+        expansions : Union[List[str], str]
+            :ref:`expansions_parameter`
+        media_fields : Union[List[str], str]
+            :ref:`media_fields_parameter`
+        place_fields : Union[List[str], str]
+            :ref:`place_fields_parameter`
+        poll_fields : Union[List[str], str]
+            :ref:`poll_fields_parameter`
+        tweet_fields : Union[List[str], str]
+            :ref:`tweet_fields_parameter`
+        user_fields : Union[List[str], str]
+            :ref:`user_fields_parameter`
+
+        Returns
+        -------
+        Union[dict, requests.Response, Response]
+
+        References
+        ----------
+        https://developer.twitter.com/en/docs/twitter-api/spaces/lookup/api-reference/get-spaces-id-buyers
+        """
+        return self._make_request(
+            "GET", f"/2/spaces/{id}/buyers", params=params,
+            endpoint_parameters=(
+                "expansions", "media.fields", "place.fields", "poll.fields",
+                "tweet.fields", "user.fields"
+            ), data_type=User
+        )
+
     # List Tweets lookup
 
     def get_list_tweets(self, id, *, user_auth=False, **params):