clean up methods handling, let Requests worry about methods

This commit is contained in:
codl 2017-10-04 16:17:03 +02:00
pare b18b6f201b
commit 5bc1706aa2
No se encontró ninguna clave conocida en la base de datos para esta firma
ID de clave GPG: 6CD7C8891ED1233A

Veure arxiu

@ -1024,29 +1024,14 @@ class Mastodon:
while not request_complete: while not request_complete:
request_complete = True request_complete = True
response_object = None
try: try:
if method == 'GET': response_object = requests.request(
response_object = requests.get(self.api_base_url + endpoint, params=params, method, self.api_base_url + endpoint, params=params,
headers=headers, files=files, headers=headers, files=files,
timeout=self.request_timeout) timeout=self.request_timeout)
if method == 'POST':
response_object = requests.post(self.api_base_url + endpoint, data=params, headers=headers,
files=files, timeout=self.request_timeout)
if method == 'PATCH':
response_object = requests.patch(self.api_base_url + endpoint, data=params, headers=headers,
files=files, timeout=self.request_timeout)
if method == 'DELETE':
response_object = requests.delete(self.api_base_url + endpoint, data=params, headers=headers,
files=files, timeout=self.request_timeout)
except Exception as e: except Exception as e:
raise MastodonNetworkError("Could not complete request: %s" % e) raise MastodonNetworkError("Could not complete request: %s" % e)
if response_object is None:
raise MastodonIllegalArgumentError("Illegal request.")
# Handle response # Handle response
if self.debug_requests: if self.debug_requests:
print('Mastodon: Response received with code ' + str(response_object.status_code) + '.') print('Mastodon: Response received with code ' + str(response_object.status_code) + '.')