Skip to content

Commit

Permalink
Add Client.get_space_buyers
Browse files Browse the repository at this point in the history
  • Loading branch information
Harmon758 committed Nov 17, 2021
1 parent caa0446 commit 8bf58ca
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
11 changes: 8 additions & 3 deletions docs/client.rst
Expand Up @@ -118,10 +118,12 @@
+--------------------------------------------------------------+----------------------------------------+
| `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|_ |
Expand Down Expand Up @@ -229,8 +231,9 @@
.. _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*
Expand Down Expand Up @@ -382,6 +385,8 @@ Spaces lookup

.. automethod:: Client.get_space

.. automethod:: Client.get_space_buyers

Lists
=====

Expand Down
2 changes: 2 additions & 0 deletions tests/test_client.py
Expand Up @@ -154,6 +154,8 @@ def test_get_space(self):
# 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)
Expand Down
42 changes: 42 additions & 0 deletions tweepy/client.py
Expand Up @@ -1865,6 +1865,48 @@ def get_space(self, id, **params):
), 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):
Expand Down

0 comments on commit 8bf58ca

Please sign in to comment.