diff options
Diffstat (limited to 'mastodon/relationships.py')
-rw-r--r-- | mastodon/relationships.py | 136 |
1 files changed, 136 insertions, 0 deletions
diff --git a/mastodon/relationships.py b/mastodon/relationships.py new file mode 100644 index 0000000..9cf15db --- /dev/null +++ b/mastodon/relationships.py | |||
@@ -0,0 +1,136 @@ | |||
1 | # relationships.py - endpoints for user and domain blocks and mutes as well as follow requests | ||
2 | |||
3 | from .versions import _DICT_VERSION_ACCOUNT, _DICT_VERSION_RELATIONSHIP | ||
4 | from .utility import api_version | ||
5 | |||
6 | from .internals import Mastodon as Internals | ||
7 | |||
8 | class Mastodon(Internals): | ||
9 | ### | ||
10 | # Reading data: Mutes and Blocks | ||
11 | ### | ||
12 | @api_version("1.1.0", "2.6.0", _DICT_VERSION_ACCOUNT) | ||
13 | def mutes(self, max_id=None, min_id=None, since_id=None, limit=None): | ||
14 | """ | ||
15 | Fetch a list of users muted by the logged-in user. | ||
16 | |||
17 | Returns a list of :ref:`account dicts <account dicts>`. | ||
18 | """ | ||
19 | if max_id is not None: | ||
20 | max_id = self.__unpack_id(max_id, dateconv=True) | ||
21 | |||
22 | if min_id is not None: | ||
23 | min_id = self.__unpack_id(min_id, dateconv=True) | ||
24 | |||
25 | if since_id is not None: | ||
26 | since_id = self.__unpack_id(since_id, dateconv=True) | ||
27 | |||
28 | params = self.__generate_params(locals()) | ||
29 | return self.__api_request('GET', '/api/v1/mutes', params) | ||
30 | |||
31 | @api_version("1.0.0", "2.6.0", _DICT_VERSION_ACCOUNT) | ||
32 | def blocks(self, max_id=None, min_id=None, since_id=None, limit=None): | ||
33 | """ | ||
34 | Fetch a list of users blocked by the logged-in user. | ||
35 | |||
36 | Returns a list of :ref:`account dicts <account dicts>`. | ||
37 | """ | ||
38 | if max_id is not None: | ||
39 | max_id = self.__unpack_id(max_id, dateconv=True) | ||
40 | |||
41 | if min_id is not None: | ||
42 | min_id = self.__unpack_id(min_id, dateconv=True) | ||
43 | |||
44 | if since_id is not None: | ||
45 | since_id = self.__unpack_id(since_id, dateconv=True) | ||
46 | |||
47 | params = self.__generate_params(locals()) | ||
48 | return self.__api_request('GET', '/api/v1/blocks', params) | ||
49 | |||
50 | ### | ||
51 | # Reading data: Follow requests | ||
52 | ### | ||
53 | @api_version("1.0.0", "2.6.0", _DICT_VERSION_ACCOUNT) | ||
54 | def follow_requests(self, max_id=None, min_id=None, since_id=None, limit=None): | ||
55 | """ | ||
56 | Fetch the logged-in user's incoming follow requests. | ||
57 | |||
58 | Returns a list of :ref:`account dicts <account dicts>`. | ||
59 | """ | ||
60 | if max_id is not None: | ||
61 | max_id = self.__unpack_id(max_id, dateconv=True) | ||
62 | |||
63 | if min_id is not None: | ||
64 | min_id = self.__unpack_id(min_id, dateconv=True) | ||
65 | |||
66 | if since_id is not None: | ||
67 | since_id = self.__unpack_id(since_id, dateconv=True) | ||
68 | |||
69 | params = self.__generate_params(locals()) | ||
70 | return self.__api_request('GET', '/api/v1/follow_requests', params) | ||
71 | |||
72 | ### | ||
73 | # Reading data: Domain blocks | ||
74 | ### | ||
75 | @api_version("1.4.0", "2.6.0", "1.4.0") | ||
76 | def domain_blocks(self, max_id=None, min_id=None, since_id=None, limit=None): | ||
77 | """ | ||
78 | Fetch the logged-in user's blocked domains. | ||
79 | |||
80 | Returns a list of blocked domain URLs (as strings, without protocol specifier). | ||
81 | """ | ||
82 | if max_id is not None: | ||
83 | max_id = self.__unpack_id(max_id, dateconv=True) | ||
84 | |||
85 | if min_id is not None: | ||
86 | min_id = self.__unpack_id(min_id, dateconv=True) | ||
87 | |||
88 | if since_id is not None: | ||
89 | since_id = self.__unpack_id(since_id, dateconv=True) | ||
90 | |||
91 | params = self.__generate_params(locals()) | ||
92 | return self.__api_request('GET', '/api/v1/domain_blocks', params) | ||
93 | |||
94 | ### | ||
95 | # Writing data: Follow requests | ||
96 | ### | ||
97 | @api_version("1.0.0", "3.0.0", _DICT_VERSION_RELATIONSHIP) | ||
98 | def follow_request_authorize(self, id): | ||
99 | """ | ||
100 | Accept an incoming follow request. | ||
101 | |||
102 | Returns the updated :ref:`relationship dict <relationship dict>` for the requesting account. | ||
103 | """ | ||
104 | id = self.__unpack_id(id) | ||
105 | url = '/api/v1/follow_requests/{0}/authorize'.format(str(id)) | ||
106 | return self.__api_request('POST', url) | ||
107 | |||
108 | @api_version("1.0.0", "3.0.0", _DICT_VERSION_RELATIONSHIP) | ||
109 | def follow_request_reject(self, id): | ||
110 | """ | ||
111 | Reject an incoming follow request. | ||
112 | |||
113 | Returns the updated :ref:`relationship dict <relationship dict>` for the requesting account. | ||
114 | """ | ||
115 | id = self.__unpack_id(id) | ||
116 | url = '/api/v1/follow_requests/{0}/reject'.format(str(id)) | ||
117 | return self.__api_request('POST', url) | ||
118 | |||
119 | ### | ||
120 | # Writing data: Domain blocks | ||
121 | ### | ||
122 | @api_version("1.4.0", "1.4.0", "1.4.0") | ||
123 | def domain_block(self, domain=None): | ||
124 | """ | ||
125 | Add a block for all statuses originating from the specified domain for the logged-in user. | ||
126 | """ | ||
127 | params = self.__generate_params(locals()) | ||
128 | self.__api_request('POST', '/api/v1/domain_blocks', params) | ||
129 | |||
130 | @api_version("1.4.0", "1.4.0", "1.4.0") | ||
131 | def domain_unblock(self, domain=None): | ||
132 | """ | ||
133 | Remove a domain block for the logged-in user. | ||
134 | """ | ||
135 | params = self.__generate_params(locals()) | ||
136 | self.__api_request('DELETE', '/api/v1/domain_blocks', params) \ No newline at end of file | ||