diff options
Diffstat (limited to 'mastodon/preferences.py')
-rw-r--r-- | mastodon/preferences.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/mastodon/preferences.py b/mastodon/preferences.py new file mode 100644 index 0000000..5e7435f --- /dev/null +++ b/mastodon/preferences.py | |||
@@ -0,0 +1,71 @@ | |||
1 | # preferences.py - user preferences, markers | ||
2 | |||
3 | import collections | ||
4 | |||
5 | from .versions import _DICT_VERSION_PREFERENCES, _DICT_VERSION_MARKER | ||
6 | from .errors import MastodonIllegalArgumentError | ||
7 | from .utility import api_version | ||
8 | |||
9 | from .internals import Mastodon as Internals | ||
10 | |||
11 | class Mastodon(Internals): | ||
12 | ### | ||
13 | # Reading data: Preferences | ||
14 | ### | ||
15 | @api_version("2.8.0", "2.8.0", _DICT_VERSION_PREFERENCES) | ||
16 | def preferences(self): | ||
17 | """ | ||
18 | Fetch the user's preferences, which can be used to set some default options. | ||
19 | As of 2.8.0, apps can only fetch, not update preferences. | ||
20 | |||
21 | Returns a :ref:`preference dict <preference dict>`. | ||
22 | """ | ||
23 | return self.__api_request('GET', '/api/v1/preferences') | ||
24 | |||
25 | ## | ||
26 | # Reading data: Read markers | ||
27 | ## | ||
28 | @api_version("3.0.0", "3.0.0", _DICT_VERSION_MARKER) | ||
29 | def markers_get(self, timeline=["home"]): | ||
30 | """ | ||
31 | Get the last-read-location markers for the specified timelines. Valid timelines | ||
32 | are the same as in :ref:`timeline() <timeline()>` | ||
33 | |||
34 | Note that despite the singular name, `timeline` can be a list. | ||
35 | |||
36 | Returns a dict of :ref:`read marker dicts <read marker dicts>`, keyed by timeline name. | ||
37 | """ | ||
38 | if not isinstance(timeline, (list, tuple)): | ||
39 | timeline = [timeline] | ||
40 | params = self.__generate_params(locals()) | ||
41 | |||
42 | return self.__api_request('GET', '/api/v1/markers', params) | ||
43 | |||
44 | ## | ||
45 | # Writing data: Read markers | ||
46 | ## | ||
47 | @api_version("3.0.0", "3.0.0", _DICT_VERSION_MARKER) | ||
48 | def markers_set(self, timelines, last_read_ids): | ||
49 | """ | ||
50 | Set the "last read" marker(s) for the given timeline(s) to the given id(s) | ||
51 | |||
52 | Note that if you give an invalid timeline name, this will silently do nothing. | ||
53 | |||
54 | Returns a dict with the updated :ref:`read marker dicts <read marker dicts>`, keyed by timeline name. | ||
55 | """ | ||
56 | if not isinstance(timelines, (list, tuple)): | ||
57 | timelines = [timelines] | ||
58 | |||
59 | if not isinstance(last_read_ids, (list, tuple)): | ||
60 | last_read_ids = [last_read_ids] | ||
61 | |||
62 | if len(last_read_ids) != len(timelines): | ||
63 | raise MastodonIllegalArgumentError("Number of specified timelines and ids must be the same") | ||
64 | |||
65 | params = collections.OrderedDict() | ||
66 | for timeline, last_read_id in zip(timelines, last_read_ids): | ||
67 | params[timeline] = collections.OrderedDict() | ||
68 | params[timeline]["last_read_id"] = self.__unpack_id(last_read_id) | ||
69 | |||
70 | return self.__api_request('POST', '/api/v1/markers', params, use_json=True) | ||
71 | \ No newline at end of file | ||