Skip to content

Commit 10d7a72

Browse files
authored
Merge pull request #23 from messagebird/fix-http-method
Fix support for HTTP request with methods other than GET and POST.
2 parents b3e7069 + 4e92226 commit 10d7a72

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

messagebird/http_client.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import requests
23

34
try:
@@ -28,14 +29,22 @@ def request(self, path, method='GET', params=None):
2829
'Content-Type': 'application/json'
2930
}
3031

31-
if method == 'GET':
32+
if method == 'DELETE':
33+
response = requests.delete(url, verify=True, headers=headers, data=json.dumps(params))
34+
elif method == 'GET':
3235
response = requests.get(url, verify=True, headers=headers, params=params)
33-
else:
36+
elif method == 'PATCH':
37+
response = requests.patch(url, verify=True, headers=headers, data=json.dumps(params))
38+
elif method == 'POST':
3439
response = requests.post(url, verify=True, headers=headers, data=json.dumps(params))
40+
elif method == 'PUT':
41+
response = requests.put(url, verify=True, headers=headers, data=json.dumps(params))
42+
else:
43+
raise ValueError(str(method) + ' is not a supported HTTP method')
3544

3645
if response.status_code in self.__supported_status_codes:
3746
response_text = response.text
3847
else:
3948
response.raise_for_status()
4049

41-
return response_text
50+
return response_text

0 commit comments

Comments
 (0)