Skip to content

Commit

Permalink
fix get as well
Browse files Browse the repository at this point in the history
  • Loading branch information
fawaf committed Aug 30, 2015
1 parent efefa62 commit 985ef56
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions cloudflare_v4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def __init__(self, email, token, debug):

def call(self, method, main_endpoint, endpoint=None, params=None, data=None):
headers = { "X-Auth-Email": self.EMAIL, "X-Auth-Key": self.TOKEN }
if endpoint is not None:
if endpoint is not None or (data is not None and method == 'GET'):
url = BASE_URL + '/' + main_endpoint + '/' + params + '/' + endpoint
else:
url = BASE_URL + '/' + main_endpoint
Expand All @@ -33,7 +33,12 @@ def call(self, method, main_endpoint, endpoint=None, params=None, data=None):
else:
self.logger.debug("headers being sent: " + str(headers))
if method == 'GET':
response = requests.get(url, headers=headers, params=params)
if data:
params_to_send = data
else:
params_to_send = params
response = requests.get(url, headers=headers,
params=params_to_send)
elif method == 'POST':
headers['Content-Type'] = 'application/json'
response = requests.post(url, headers=headers, json=data)
Expand All @@ -46,7 +51,7 @@ def call(self, method, main_endpoint, endpoint=None, params=None, data=None):
if data['success'] is False:
raise CloudFlareAPIError(data['errors'][0]['message'])
else:
return data
return data['result']
except ValueError:
raise CloudFlareAPIError('JSON parse failed.')

Expand All @@ -59,9 +64,9 @@ def __init__(self, base_client, main_endpoint, endpoint=None):
self.main_endpoint = main_endpoint
self.endpoint = endpoint

def get(self, params=None):
def get(self, params=None, data=None):
return self.base_client.call('GET', self.main_endpoint,
self.endpoint, params)
self.endpoint, params, data)

def post(self, params=None, data=None):
return self.base_client.call('POST', self.main_endpoint,
Expand Down

0 comments on commit 985ef56

Please sign in to comment.