aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex McGivern <[email protected]>2017-04-27 00:21:32 +0100
committerAlex McGivern <[email protected]>2017-04-27 00:21:32 +0100
commit91e5388daef3f66b546726dcd57e84682df40a8f (patch)
tree47c42cf81ea6acb56fba26d48c2c42093fff99f1
parent973182cda07bc64545523b2ae0940c6f170c6db6 (diff)
downloadmastodon.py-91e5388daef3f66b546726dcd57e84682df40a8f.tar.gz
added content-type hint
fixed POST parameters for reports added handling for PATCH requests added check for missing Date header to prevent errors when testing against Puma
-rw-r--r--mastodon/Mastodon.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index a32241b..3b00f37 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -643,7 +643,8 @@ class Mastodon:
643 643
644 'note' is the user's bio. 644 'note' is the user's bio.
645 645
646 'avatar' and 'header' are PNG images encoded in base64. 646 'avatar' and 'header' are images encoded in base64, prepended by a content-type
647 (for example: 'data:image/png;base64,iVBORw0KGgoAAAA[...]')
647 """ 648 """
648 params = self.__generate_params(locals()) 649 params = self.__generate_params(locals())
649 return self.__api_request('PATCH', '/api/v1/accounts/update_credentials', params) 650 return self.__api_request('PATCH', '/api/v1/accounts/update_credentials', params)
@@ -651,7 +652,7 @@ class Mastodon:
651 ### 652 ###
652 # Writing data: Reports 653 # Writing data: Reports
653 ### 654 ###
654 def report(self, id, toots, comment): 655 def report(self, account_id, status_ids, comment):
655 """ 656 """
656 Report a user to the admin. 657 Report a user to the admin.
657 658
@@ -813,6 +814,9 @@ class Mastodon:
813 if method == 'POST': 814 if method == 'POST':
814 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)
815 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
816 if method == 'DELETE': 820 if method == 'DELETE':
817 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)
818 except Exception as e: 822 except Exception as e:
@@ -848,11 +852,12 @@ class Mastodon:
848 self.ratelimit_reset = self.__datetime_to_epoch(ratelimit_reset_datetime) 852 self.ratelimit_reset = self.__datetime_to_epoch(ratelimit_reset_datetime)
849 853
850 # Adjust server time to local clock 854 # Adjust server time to local clock
851 server_time_datetime = dateutil.parser.parse(response_object.headers['Date']) 855 if 'Date' in response_object.headers:
852 server_time = self.__datetime_to_epoch(server_time_datetime) 856 server_time_datetime = dateutil.parser.parse(response_object.headers['Date'])
853 server_time_diff = time.time() - server_time 857 server_time = self.__datetime_to_epoch(server_time_datetime)
854 self.ratelimit_reset += server_time_diff 858 server_time_diff = time.time() - server_time
855 self.ratelimit_lastcall = time.time() 859 self.ratelimit_reset += server_time_diff
860 self.ratelimit_lastcall = time.time()
856 except Exception as e: 861 except Exception as e:
857 raise MastodonRatelimitError("Rate limit time calculations failed: %s" % e) 862 raise MastodonRatelimitError("Rate limit time calculations failed: %s" % e)
858 863
Powered by cgit v1.2.3 (git 2.41.0)