diff options
Diffstat (limited to 'mastodon/lists.py')
-rw-r--r-- | mastodon/lists.py | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/mastodon/lists.py b/mastodon/lists.py new file mode 100644 index 0000000..0882133 --- /dev/null +++ b/mastodon/lists.py | |||
@@ -0,0 +1,112 @@ | |||
1 | # list.py - list endpoints | ||
2 | |||
3 | from .versions import _DICT_VERSION_LIST, _DICT_VERSION_ACCOUNT | ||
4 | from .utility import api_version | ||
5 | |||
6 | from .internals import Mastodon as Internals | ||
7 | |||
8 | class Mastodon(Internals): | ||
9 | ### | ||
10 | # Reading data: Lists | ||
11 | ### | ||
12 | @api_version("2.1.0", "2.1.0", _DICT_VERSION_LIST) | ||
13 | def lists(self): | ||
14 | """ | ||
15 | Fetch a list of all the Lists by the logged-in user. | ||
16 | |||
17 | Returns a list of :ref:`list dicts <list dicts>`. | ||
18 | """ | ||
19 | return self.__api_request('GET', '/api/v1/lists') | ||
20 | |||
21 | @api_version("2.1.0", "2.1.0", _DICT_VERSION_LIST) | ||
22 | def list(self, id): | ||
23 | """ | ||
24 | Fetch info about a specific list. | ||
25 | |||
26 | Returns a :ref:`list dict <list dict>`. | ||
27 | """ | ||
28 | id = self.__unpack_id(id) | ||
29 | return self.__api_request('GET', '/api/v1/lists/{0}'.format(id)) | ||
30 | |||
31 | @api_version("2.1.0", "2.6.0", _DICT_VERSION_ACCOUNT) | ||
32 | def list_accounts(self, id, max_id=None, min_id=None, since_id=None, limit=None): | ||
33 | """ | ||
34 | Get the accounts that are on the given list. | ||
35 | |||
36 | Returns a list of :ref:`account dicts <account dicts>`. | ||
37 | """ | ||
38 | id = self.__unpack_id(id) | ||
39 | |||
40 | if max_id is not None: | ||
41 | max_id = self.__unpack_id(max_id, dateconv=True) | ||
42 | |||
43 | if min_id is not None: | ||
44 | min_id = self.__unpack_id(min_id, dateconv=True) | ||
45 | |||
46 | if since_id is not None: | ||
47 | since_id = self.__unpack_id(since_id, dateconv=True) | ||
48 | |||
49 | params = self.__generate_params(locals(), ['id']) | ||
50 | return self.__api_request('GET', '/api/v1/lists/{0}/accounts'.format(id)) | ||
51 | |||
52 | ### | ||
53 | # Writing data: Lists | ||
54 | ### | ||
55 | @api_version("2.1.0", "2.1.0", _DICT_VERSION_LIST) | ||
56 | def list_create(self, title): | ||
57 | """ | ||
58 | Create a new list with the given `title`. | ||
59 | |||
60 | Returns the :ref:`list dict <list dict>` of the created list. | ||
61 | """ | ||
62 | params = self.__generate_params(locals()) | ||
63 | return self.__api_request('POST', '/api/v1/lists', params) | ||
64 | |||
65 | @api_version("2.1.0", "2.1.0", _DICT_VERSION_LIST) | ||
66 | def list_update(self, id, title): | ||
67 | """ | ||
68 | Update info about a list, where "info" is really the lists `title`. | ||
69 | |||
70 | Returns the :ref:`list dict <list dict>` of the modified list. | ||
71 | """ | ||
72 | id = self.__unpack_id(id) | ||
73 | params = self.__generate_params(locals(), ['id']) | ||
74 | return self.__api_request('PUT', '/api/v1/lists/{0}'.format(id), params) | ||
75 | |||
76 | @api_version("2.1.0", "2.1.0", "2.1.0") | ||
77 | def list_delete(self, id): | ||
78 | """ | ||
79 | Delete a list. | ||
80 | """ | ||
81 | id = self.__unpack_id(id) | ||
82 | self.__api_request('DELETE', '/api/v1/lists/{0}'.format(id)) | ||
83 | |||
84 | @api_version("2.1.0", "2.1.0", "2.1.0") | ||
85 | def list_accounts_add(self, id, account_ids): | ||
86 | """ | ||
87 | Add the account(s) given in `account_ids` to the list. | ||
88 | """ | ||
89 | id = self.__unpack_id(id) | ||
90 | |||
91 | if not isinstance(account_ids, list): | ||
92 | account_ids = [account_ids] | ||
93 | account_ids = list(map(lambda x: self.__unpack_id(x), account_ids)) | ||
94 | |||
95 | params = self.__generate_params(locals(), ['id']) | ||
96 | self.__api_request( | ||
97 | 'POST', '/api/v1/lists/{0}/accounts'.format(id), params) | ||
98 | |||
99 | @api_version("2.1.0", "2.1.0", "2.1.0") | ||
100 | def list_accounts_delete(self, id, account_ids): | ||
101 | """ | ||
102 | Remove the account(s) given in `account_ids` from the list. | ||
103 | """ | ||
104 | id = self.__unpack_id(id) | ||
105 | |||
106 | if not isinstance(account_ids, list): | ||
107 | account_ids = [account_ids] | ||
108 | account_ids = list(map(lambda x: self.__unpack_id(x), account_ids)) | ||
109 | |||
110 | params = self.__generate_params(locals(), ['id']) | ||
111 | self.__api_request( | ||
112 | 'DELETE', '/api/v1/lists/{0}/accounts'.format(id), params) \ No newline at end of file | ||