diff options
author | Lorenz Diener <[email protected]> | 2019-10-12 22:55:17 +0200 |
---|---|---|
committer | Lorenz Diener <[email protected]> | 2019-10-12 22:55:17 +0200 |
commit | 45908b6f4e9c66fe102b30764e6d153a8d0339a5 (patch) | |
tree | b8e1caaa65c0b43a181cbd672199c7e8b919616c /mastodon | |
parent | 1f36deb11950a627b52a587fc3ec30c37f9bb456 (diff) | |
download | mastodon.py-45908b6f4e9c66fe102b30764e6d153a8d0339a5.tar.gz |
Add, test and document last-read markers. Fixes #192
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index d07bae7..b8ad976 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -213,6 +213,7 @@ class Mastodon: | |||
213 | __DICT_VERSION_PREFERENCES = "2.8.0" | 213 | __DICT_VERSION_PREFERENCES = "2.8.0" |
214 | __DICT_VERSION_ADMIN_ACCOUNT = "2.9.1" | 214 | __DICT_VERSION_ADMIN_ACCOUNT = "2.9.1" |
215 | __DICT_VERSION_FEATURED_TAG = "3.0.0" | 215 | __DICT_VERSION_FEATURED_TAG = "3.0.0" |
216 | __DICT_VERSION_MARKER = "3.0.0" | ||
216 | 217 | ||
217 | ### | 218 | ### |
218 | # Registering apps | 219 | # Registering apps |
@@ -1590,6 +1591,25 @@ class Mastodon: | |||
1590 | """ | 1591 | """ |
1591 | return self.__api_request('GET', '/api/v1/preferences') | 1592 | return self.__api_request('GET', '/api/v1/preferences') |
1592 | 1593 | ||
1594 | ## | ||
1595 | # Reading data: Read markers | ||
1596 | ## | ||
1597 | @api_version("3.0.0", "3.0.0", __DICT_VERSION_MARKER) | ||
1598 | def markers_get(self, timeline=["home"]): | ||
1599 | """ | ||
1600 | Get the last-read-location markers for the specified timelines. Valid timelines | ||
1601 | are the same as in `timeline()`_ | ||
1602 | |||
1603 | Note that despite the singular name, `timeline` can be a list. | ||
1604 | |||
1605 | Returns a dict of `read marker dicts`_, keyed by timeline name. | ||
1606 | """ | ||
1607 | if not isinstance(timeline, (list, tuple)): | ||
1608 | timeline = [timeline] | ||
1609 | params = self.__generate_params(locals()) | ||
1610 | |||
1611 | return self.__api_request('GET', '/api/v1/markers', params) | ||
1612 | |||
1593 | ### | 1613 | ### |
1594 | # Writing data: Statuses | 1614 | # Writing data: Statuses |
1595 | ### | 1615 | ### |
@@ -2450,6 +2470,34 @@ class Mastodon: | |||
2450 | params = self.__generate_params(locals()) | 2470 | params = self.__generate_params(locals()) |
2451 | self.__api_request('DELETE', '/api/v1/domain_blocks', params) | 2471 | self.__api_request('DELETE', '/api/v1/domain_blocks', params) |
2452 | 2472 | ||
2473 | ## | ||
2474 | # Writing data: Read markers | ||
2475 | ## | ||
2476 | @api_version("3.0.0", "3.0.0", __DICT_VERSION_MARKER) | ||
2477 | def markers_set(self, timelines, last_read_ids): | ||
2478 | """ | ||
2479 | Set the "last read" marker(s) for the given timeline(s) to the given id(s) | ||
2480 | |||
2481 | Note that if you give an invalid timeline name, this will silently do nothing. | ||
2482 | |||
2483 | Returns a dict with the updated `read marker dicts`_, keyed by timeline name. | ||
2484 | """ | ||
2485 | if not isinstance(timelines, (list, tuple)): | ||
2486 | timelines = [timelines] | ||
2487 | |||
2488 | if not isinstance(last_read_ids, (list, tuple)): | ||
2489 | last_read_ids = [last_read_ids] | ||
2490 | |||
2491 | if len(last_read_ids) != len(timelines): | ||
2492 | raise MastodonIllegalArgumentError("Number of specified timelines and ids must be the same") | ||
2493 | |||
2494 | params = collections.OrderedDict() | ||
2495 | for timeline, last_read_id in zip(timelines, last_read_ids): | ||
2496 | params[timeline] = collections.OrderedDict() | ||
2497 | params[timeline]["last_read_id"] = self.__unpack_id(last_read_id) | ||
2498 | |||
2499 | return self.__api_request('POST', '/api/v1/markers', params, use_json=True) | ||
2500 | |||
2453 | ### | 2501 | ### |
2454 | # Writing data: Push subscriptions | 2502 | # Writing data: Push subscriptions |
2455 | ### | 2503 | ### |
@@ -3071,7 +3119,7 @@ class Mastodon: | |||
3071 | """ | 3119 | """ |
3072 | Converts json string numerals to native python bignums. | 3120 | Converts json string numerals to native python bignums. |
3073 | """ | 3121 | """ |
3074 | for key in ('id', 'week', 'in_reply_to_id', 'in_reply_to_account_id', 'logins', 'registrations', 'statuses', 'day'): | 3122 | for key in ('id', 'week', 'in_reply_to_id', 'in_reply_to_account_id', 'logins', 'registrations', 'statuses', 'day', 'last_read_id'): |
3075 | if (key in json_object and isinstance(json_object[key], six.text_type)): | 3123 | if (key in json_object and isinstance(json_object[key], six.text_type)): |
3076 | try: | 3124 | try: |
3077 | json_object[key] = int(json_object[key]) | 3125 | json_object[key] = int(json_object[key]) |