diff options
author | Lorenz Diener <[email protected]> | 2017-04-27 10:41:30 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2017-04-27 10:41:30 +0200 |
commit | 2dc636879b067e6546466a1d49a8bf861ac1541b (patch) | |
tree | 47c42cf81ea6acb56fba26d48c2c42093fff99f1 /mastodon | |
parent | 9766171729a18dd4ee28f09f2dfc150354dfcdc8 (diff) | |
parent | 91e5388daef3f66b546726dcd57e84682df40a8f (diff) | |
download | mastodon.py-2dc636879b067e6546466a1d49a8bf861ac1541b.tar.gz |
Merge pull request #47 from aeonofdiscord/master
New API endpoints and documentation updates
Diffstat (limited to 'mastodon')
-rw-r--r-- | mastodon/Mastodon.py | 71 |
1 files changed, 65 insertions, 6 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index 003402f..3b00f37 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -211,6 +211,17 @@ class Mastodon: | |||
211 | return response['access_token'] | 211 | return response['access_token'] |
212 | 212 | ||
213 | ### | 213 | ### |
214 | # Reading data: Instance | ||
215 | ### | ||
216 | def instance(self): | ||
217 | """ | ||
218 | Retrieve basic information about the instance, including the URI and administrative contact email. | ||
219 | |||
220 | Returns a dict. | ||
221 | """ | ||
222 | return self.__api_request('GET', '/api/v1/instance/') | ||
223 | |||
224 | ### | ||
214 | # Reading data: Timelines | 225 | # Reading data: Timelines |
215 | ## | 226 | ## |
216 | def timeline(self, timeline = "home", max_id = None, since_id = None, limit = None): | 227 | def timeline(self, timeline = "home", max_id = None, since_id = None, limit = None): |
@@ -274,6 +285,14 @@ class Mastodon: | |||
274 | """ | 285 | """ |
275 | return self.__api_request('GET', '/api/v1/statuses/' + str(id)) | 286 | return self.__api_request('GET', '/api/v1/statuses/' + str(id)) |
276 | 287 | ||
288 | def status_card(self, id): | ||
289 | """ | ||
290 | Fetch a card associated with a status. | ||
291 | |||
292 | Returns a card dict. | ||
293 | """ | ||
294 | return self.__api_request('GET', '/api/v1/statuses/' + str(id) + '/card') | ||
295 | |||
277 | def status_context(self, id): | 296 | def status_context(self, id): |
278 | """ | 297 | """ |
279 | Fetch information about ancestors and descendants of a toot. | 298 | Fetch information about ancestors and descendants of a toot. |
@@ -380,7 +399,6 @@ class Mastodon: | |||
380 | """ | 399 | """ |
381 | params = self.__generate_params(locals()) | 400 | params = self.__generate_params(locals()) |
382 | return self.__api_request('GET', '/api/v1/accounts/search', params) | 401 | return self.__api_request('GET', '/api/v1/accounts/search', params) |
383 | |||
384 | 402 | ||
385 | ### | 403 | ### |
386 | # Reading data: Searching | 404 | # Reading data: Searching |
@@ -415,6 +433,17 @@ class Mastodon: | |||
415 | return self.__api_request('GET', '/api/v1/blocks') | 433 | return self.__api_request('GET', '/api/v1/blocks') |
416 | 434 | ||
417 | ### | 435 | ### |
436 | # Reading data: Reports | ||
437 | ### | ||
438 | def reports(self): | ||
439 | """ | ||
440 | Fetch a list of reports made by the authenticated user. | ||
441 | |||
442 | Returns a list of report dicts. | ||
443 | """ | ||
444 | return self.__api_request('GET', '/api/v1/reports') | ||
445 | |||
446 | ### | ||
418 | # Reading data: Favourites | 447 | # Reading data: Favourites |
419 | ### | 448 | ### |
420 | def favourites(self): | 449 | def favourites(self): |
@@ -608,6 +637,32 @@ class Mastodon: | |||
608 | """ | 637 | """ |
609 | return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/unmute") | 638 | return self.__api_request('POST', '/api/v1/accounts/' + str(id) + "/unmute") |
610 | 639 | ||
640 | def account_update_credentials(self, display_name = None, note = None, avatar = None, header = None): | ||
641 | """ | ||
642 | Update the profile for the currently authenticated user. | ||
643 | |||
644 | 'note' is the user's bio. | ||
645 | |||
646 | 'avatar' and 'header' are images encoded in base64, prepended by a content-type | ||
647 | (for example: 'data:image/png;base64,iVBORw0KGgoAAAA[...]') | ||
648 | """ | ||
649 | params = self.__generate_params(locals()) | ||
650 | return self.__api_request('PATCH', '/api/v1/accounts/update_credentials', params) | ||
651 | |||
652 | ### | ||
653 | # Writing data: Reports | ||
654 | ### | ||
655 | def report(self, account_id, status_ids, comment): | ||
656 | """ | ||
657 | Report a user to the admin. | ||
658 | |||
659 | Accepts a list of toot IDs associated with the report, and a comment. | ||
660 | |||
661 | Returns a report dict. | ||
662 | """ | ||
663 | params = self.__generate_params(locals()) | ||
664 | return self.__api_request('POST', '/api/v1/reports/', params) | ||
665 | |||
611 | ### | 666 | ### |
612 | # Writing data: Follow requests | 667 | # Writing data: Follow requests |
613 | ### | 668 | ### |
@@ -759,6 +814,9 @@ class Mastodon: | |||
759 | if method == 'POST': | 814 | if method == 'POST': |
760 | response_object = requests.post(self.api_base_url + endpoint, data = params, headers = headers, files = files, timeout = self.request_timeout) | 815 | response_object = requests.post(self.api_base_url + endpoint, data = params, headers = headers, files = files, timeout = self.request_timeout) |
761 | 816 | ||
817 | if method == 'PATCH': | ||
818 | response_object = requests.patch(self.api_base_url + endpoint, data = params, headers = headers, files = files, timeout = self.request_timeout) | ||
819 | |||
762 | if method == 'DELETE': | 820 | if method == 'DELETE': |
763 | response_object = requests.delete(self.api_base_url + endpoint, data = params, headers = headers, files = files, timeout = self.request_timeout) | 821 | response_object = requests.delete(self.api_base_url + endpoint, data = params, headers = headers, files = files, timeout = self.request_timeout) |
764 | except Exception as e: | 822 | except Exception as e: |
@@ -794,11 +852,12 @@ class Mastodon: | |||
794 | self.ratelimit_reset = self.__datetime_to_epoch(ratelimit_reset_datetime) | 852 | self.ratelimit_reset = self.__datetime_to_epoch(ratelimit_reset_datetime) |
795 | 853 | ||
796 | # Adjust server time to local clock | 854 | # Adjust server time to local clock |
797 | server_time_datetime = dateutil.parser.parse(response_object.headers['Date']) | 855 | if 'Date' in response_object.headers: |
798 | server_time = self.__datetime_to_epoch(server_time_datetime) | 856 | server_time_datetime = dateutil.parser.parse(response_object.headers['Date']) |
799 | server_time_diff = time.time() - server_time | 857 | server_time = self.__datetime_to_epoch(server_time_datetime) |
800 | self.ratelimit_reset += server_time_diff | 858 | server_time_diff = time.time() - server_time |
801 | self.ratelimit_lastcall = time.time() | 859 | self.ratelimit_reset += server_time_diff |
860 | self.ratelimit_lastcall = time.time() | ||
802 | except Exception as e: | 861 | except Exception as e: |
803 | raise MastodonRatelimitError("Rate limit time calculations failed: %s" % e) | 862 | raise MastodonRatelimitError("Rate limit time calculations failed: %s" % e) |
804 | 863 | ||