Skip to content

Commit 0affba6

Browse files
author
Sam Wierema
committed
Add support for GET parameters
The new Lookup API has endpoints that accept GET parameters. Change the request method to optionally set a method parameter. If the method is GET, add params to the request (if they exist).
1 parent 90f8e11 commit 0affba6

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

messagebird/client.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def __init__(self, access_key):
3131
self.access_key = access_key
3232
self._supported_status_codes = [200, 201, 204, 401, 404, 405, 422]
3333

34-
def request(self, path, params={}):
34+
def request(self, path, method='GET', params={}):
3535
url = urljoin(ENDPOINT, path)
3636

3737
headers = {
@@ -41,8 +41,8 @@ def request(self, path, params={}):
4141
'Content-Type' : 'application/json'
4242
}
4343

44-
if len(params) == 0:
45-
response = requests.get(url, verify=True, headers=headers)
44+
if method == 'GET':
45+
response = requests.get(url, verify=True, headers=headers, params=params)
4646
else:
4747
response = requests.post(url, verify=True, headers=headers, data=json.dumps(params))
4848

@@ -66,7 +66,7 @@ def hlr(self, id):
6666

6767
def hlr_create(self, msisdn, reference):
6868
"""Perform a new HLR lookup."""
69-
return HLR().load(self.request('hlr', { 'msisdn' : msisdn, 'reference' : reference }))
69+
return HLR().load(self.request('hlr', 'POST', { 'msisdn' : msisdn, 'reference' : reference }))
7070

7171
def message(self, id):
7272
"""Retrieve the information of a specific message."""
@@ -78,7 +78,7 @@ def message_create(self, originator, recipients, body, params={}):
7878
recipients = ','.join(recipients)
7979

8080
params.update({ 'originator' : originator, 'body' : body, 'recipients' : recipients })
81-
return Message().load(self.request('messages', params))
81+
return Message().load(self.request('messages', 'POST', params))
8282

8383
def voice_message(self, id):
8484
"Retrieve the information of a specific voice message."
@@ -90,4 +90,4 @@ def voice_message_create(self, recipients, body, params={}):
9090
recipients = ','.join(recipients)
9191

9292
params.update({ 'recipients' : recipients, 'body' : body })
93-
return VoiceMessage().load(self.request('voicemessages', params))
93+
return VoiceMessage().load(self.request('voicemessages', 'POST', params))

0 commit comments

Comments
 (0)