From 4e92226b178c815dd92d0c38f5eccf74bbb94367 Mon Sep 17 00:00:00 2001 From: Emile Pels Date: Wed, 31 Oct 2018 12:16:57 +0100 Subject: [PATCH] Fix support for HTTP request with methods other than GET and POST. Previously, we assumed any non-GET was a POST, which is obviously wrong. We're also using DELETE, PATCH and PUT. Also add a forgotten import --- messagebird/http_client.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/messagebird/http_client.py b/messagebird/http_client.py index e07a10c..72123c3 100644 --- a/messagebird/http_client.py +++ b/messagebird/http_client.py @@ -1,3 +1,4 @@ +import json import requests try: @@ -28,14 +29,22 @@ def request(self, path, method='GET', params=None): 'Content-Type': 'application/json' } - if method == 'GET': + if method == 'DELETE': + response = requests.delete(url, verify=True, headers=headers, data=json.dumps(params)) + elif method == 'GET': response = requests.get(url, verify=True, headers=headers, params=params) - else: + elif method == 'PATCH': + response = requests.patch(url, verify=True, headers=headers, data=json.dumps(params)) + elif method == 'POST': response = requests.post(url, verify=True, headers=headers, data=json.dumps(params)) + elif method == 'PUT': + response = requests.put(url, verify=True, headers=headers, data=json.dumps(params)) + else: + raise ValueError(str(method) + ' is not a supported HTTP method') if response.status_code in self.__supported_status_codes: response_text = response.text else: response.raise_for_status() - return response_text \ No newline at end of file + return response_text