Skip to content

Commit

Permalink
Add Client.get_muted
Browse files Browse the repository at this point in the history
  • Loading branch information
Harmon758 committed Oct 7, 2021
1 parent 6ca75e1 commit 00cdab8
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 21 deletions.
Expand Up @@ -13,7 +13,7 @@ interactions:
Content-Type:
- application/json
User-Agent:
- Python/3.9.6 Requests/2.25.1 Tweepy/4.0.0-alpha
- Python/3.10.0 Requests/2.26.0 Tweepy/4.0.1
method: POST
uri: https://api.twitter.com/2/users/1072250532645998596/muting
response:
Expand All @@ -22,7 +22,7 @@ interactions:
H4sIAAAAAAAAAKpWSkksSVSyqlbKLS3JzEtXsiopKk2trQUAAAD//wMAKOKMLRgAAAA=
headers:
api-version:
- '2.24'
- '2.27'
cache-control:
- no-cache, no-store, max-age=0
content-disposition:
Expand All @@ -34,30 +34,88 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Mon, 20 Sep 2021 21:47:48 UTC
- Thu, 07 Oct 2021 07:59:53 UTC
server:
- tsa_a
- tsa_b
set-cookie:
- personalization_id="v1_tx5lZdBKqUcj82GIzmOxSg=="; Max-Age=63072000; Expires=Wed,
20 Sep 2023 21:47:48 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None
- guest_id=v1%3A163217446858292923; Max-Age=63072000; Expires=Wed, 20 Sep 2023
21:47:48 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None
- personalization_id="v1_LnGt1yhHG67NY2wX1DxNrQ=="; Max-Age=63072000; Expires=Sat,
07 Oct 2023 07:59:53 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None
- guest_id=v1%3A163359359375660636; Max-Age=63072000; Expires=Sat, 07 Oct 2023
07:59:53 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None
strict-transport-security:
- max-age=631138519
x-access-level:
- read-write-directmessages
x-connection-hash:
- b749ed00177b9e8d4fa0590d2ddcb7210910a14c470247d2796add7567c67c6f
- 93d1eddbd259216f59385fb3ebebee0b6a399312fc3efe26e65391fcc2e28396
x-content-type-options:
- nosniff
x-frame-options:
- SAMEORIGIN
x-rate-limit-limit:
- '50'
x-rate-limit-remaining:
- '49'
- '48'
x-rate-limit-reset:
- '1632175368'
- '1633594356'
x-xss-protection:
- '0'
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate
Connection:
- keep-alive
Cookie:
- guest_id=v1%3A163359359375660636; personalization_id="v1_LnGt1yhHG67NY2wX1DxNrQ=="
User-Agent:
- Python/3.10.0 Requests/2.26.0 Tweepy/4.0.1
method: GET
uri: https://api.twitter.com/2/users/1072250532645998596/muting
response:
body:
string: !!binary |
H4sIAAAAAAAAAKpWSkksSVSyiq5WykxRslIyNLcwNzE1MVHSUcpLzE0FioSUZ5aUpBYpBJcWFOQX
lQAlSotTi1AlYXK1sTpKuakg86qVilKLS3NK4pPzS/NKlKwMa2sBAAAA//8DAMW+VFVrAAAA
headers:
api-version:
- '2.27'
cache-control:
- no-cache, no-store, max-age=0
content-disposition:
- attachment; filename=json.json
content-encoding:
- gzip
content-length:
- '111'
content-type:
- application/json; charset=utf-8
date:
- Thu, 07 Oct 2021 07:59:53 UTC
server:
- tsa_b
strict-transport-security:
- max-age=631138519
x-access-level:
- read-write-directmessages
x-connection-hash:
- 93d1eddbd259216f59385fb3ebebee0b6a399312fc3efe26e65391fcc2e28396
x-content-type-options:
- nosniff
x-frame-options:
- SAMEORIGIN
x-rate-limit-limit:
- '15'
x-rate-limit-remaining:
- '11'
x-rate-limit-reset:
- '1633594302'
x-xss-protection:
- '0'
status:
Expand All @@ -75,9 +133,9 @@ interactions:
Content-Length:
- '0'
Cookie:
- guest_id=v1%3A163217446858292923; personalization_id="v1_tx5lZdBKqUcj82GIzmOxSg=="
- guest_id=v1%3A163359359375660636; personalization_id="v1_LnGt1yhHG67NY2wX1DxNrQ=="
User-Agent:
- Python/3.9.6 Requests/2.25.1 Tweepy/4.0.0-alpha
- Python/3.10.0 Requests/2.26.0 Tweepy/4.0.1
method: DELETE
uri: https://api.twitter.com/2/users/1072250532645998596/muting/17874544
response:
Expand All @@ -86,7 +144,7 @@ interactions:
H4sIAAAAAAAAAKpWSkksSVSyqlbKLS3JzEtXskpLzClOra0FAAAA//8DAL40mrYZAAAA
headers:
api-version:
- '2.24'
- '2.27'
cache-control:
- no-cache, no-store, max-age=0
content-disposition:
Expand All @@ -98,25 +156,25 @@ interactions:
content-type:
- application/json; charset=utf-8
date:
- Mon, 20 Sep 2021 21:47:48 UTC
- Thu, 07 Oct 2021 07:59:54 UTC
server:
- tsa_a
- tsa_b
strict-transport-security:
- max-age=631138519
x-access-level:
- read-write-directmessages
x-connection-hash:
- b749ed00177b9e8d4fa0590d2ddcb7210910a14c470247d2796add7567c67c6f
- 93d1eddbd259216f59385fb3ebebee0b6a399312fc3efe26e65391fcc2e28396
x-content-type-options:
- nosniff
x-frame-options:
- SAMEORIGIN
x-rate-limit-limit:
- '50'
x-rate-limit-remaining:
- '49'
- '48'
x-rate-limit-reset:
- '1632175368'
- '1633594363'
x-xss-protection:
- '0'
status:
Expand Down
2 changes: 2 additions & 0 deletions docs/client.rst
Expand Up @@ -94,6 +94,8 @@ Mutes

.. automethod:: Client.unmute

.. automethod:: Client.get_muted

.. automethod:: Client.mute

User lookup
Expand Down
6 changes: 4 additions & 2 deletions tests/test_client.py
Expand Up @@ -108,10 +108,12 @@ def test_get_users_following(self):
user_id = 783214 # User ID for @Twitter
self.client.get_users_following(user_id)

@tape.use_cassette("test_mute_and_unmute.yaml", serializer="yaml")
def test_mute_and_unmute(self):
@tape.use_cassette("test_mute_get_muted_and_unmute.yaml",
serializer="yaml")
def test_mute_get_muted_and_unmute(self):
user_id = 17874544 # User ID for @TwitterSupport
self.client.mute(user_id)
self.client.get_muted()
self.client.unmute(user_id)

@tape.use_cassette("test_get_user.yaml", serializer="yaml")
Expand Down
42 changes: 42 additions & 0 deletions tweepy/client.py
Expand Up @@ -1364,6 +1364,48 @@ def unmute(self, target_user_id):

return self._make_request("DELETE", route, user_auth=True)

def get_muted(self, **params):
"""get_muted(*, expansions, max_results, pagination_token, \
tweet_fields, user_fields)
Returns a list of users who are muted by the authenticating user.
Parameters
----------
expansions : Union[List[str], str]
:ref:`expansions_parameter`
max_results : int
The maximum number of results to be returned per page. This can be
a number between 1 and 1000. By default, each page will return 100
results.
pagination_token : str
Used to request the next page of results if all results weren't
returned with the latest request, or to go back to the previous
page of results.
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/users/mutes/api-reference/get-users-muting
"""
id = self.access_token.partition('-')[0]
route = f"/2/users/{id}/muting"

return self._make_request(
"GET", route, params=params,
endpoint_parameters=(
"expansions", "max_results", "pagination_token",
"tweet.fields", "user.fields"
), data_type=User, user_auth=True
)

def mute(self, target_user_id):
"""Allows an authenticated user ID to mute the target user.
Expand Down

0 comments on commit 00cdab8

Please sign in to comment.