Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit 3ae4626

Browse files
committed
added raw flag to class so that paging values can be returned
1 parent 00ef9f8 commit 3ae4626

1 file changed

Lines changed: 35 additions & 11 deletions

File tree

CloudFlare/cloudflare.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ class CloudFlare(object):
1919
class _base(object):
2020
""" Cloudflare v4 API"""
2121

22-
def __init__(self, email, token, certtoken, base_url, debug):
22+
def __init__(self, email, token, certtoken, base_url, debug, raw):
2323
""" Cloudflare v4 API"""
2424

2525
self.email = email
2626
self.token = token
2727
self.certtoken = certtoken
2828
self.base_url = base_url
29+
self.raw = raw
2930

3031
if debug:
3132
self.logger = Logger(debug).getLogger()
@@ -87,12 +88,10 @@ def call_with_certauth(self, method,
8788
identifier1, identifier2,
8889
params, data)
8990

90-
def _call(self, method, headers,
91-
api_call_part1,
92-
api_call_part2=None,
93-
api_call_part3=None,
94-
identifier1=None, identifier2=None,
95-
params=None, data=None):
91+
def _raw(self, method, headers,
92+
api_call_part1, api_call_part2=None, api_call_part3=None,
93+
identifier1=None, identifier2=None,
94+
params=None, data=None):
9695
""" Cloudflare v4 API"""
9796

9897
if api_call_part2 is not None or (data is not None and method == 'GET'):
@@ -171,16 +170,41 @@ def _call(self, method, headers,
171170
except ValueError:
172171
raise CloudFlareAPIError(0, 'JSON parse failed.')
173172

173+
return response_data
174+
175+
def _call(self, method, headers,
176+
api_call_part1,
177+
api_call_part2=None,
178+
api_call_part3=None,
179+
identifier1=None, identifier2=None,
180+
params=None, data=None):
181+
""" Cloudflare v4 API"""
182+
183+
response_data = self._raw(method, headers,
184+
api_call_part1, api_call_part2, api_call_part3,
185+
identifier1, identifier2,
186+
params, data)
174187
if response_data['success'] is False:
175188
code = response_data['errors'][0]['code']
176189
message = response_data['errors'][0]['message']
177190
if self.logger:
178191
self.logger.debug('Response: error %d %s' % (code, message))
179192
raise CloudFlareAPIError(code, message)
180193

181-
result = response_data['result']
182194
if self.logger:
183-
self.logger.debug('Response: %s' % (result))
195+
self.logger.debug('Response: %s' % (response_data.result))
196+
if self.raw:
197+
## no need to return success, errors, or messages as they return via an exception
198+
result = {}
199+
if 'result' in response_data:
200+
result['result'] = response_data['result']
201+
if 'result_info' in response_data:
202+
result['result_info'] = response_data['result_info']
203+
if 'total_count' in response_data:
204+
result['total_count'] = response_data['total_count']
205+
else:
206+
# theres always a result value
207+
result = response_data['result']
184208
return result
185209

186210
class add_unused(object):
@@ -337,7 +361,7 @@ def delete(self, identifier1=None, identifier2=None, params=None, data=None):
337361
identifier1, identifier2,
338362
params, data)
339363

340-
def __init__(self, email=None, token=None, certtoken=None, debug=False):
364+
def __init__(self, email=None, token=None, certtoken=None, debug=False, raw=False):
341365
""" Cloudflare v4 API"""
342366

343367
base_url = BASE_URL
@@ -352,7 +376,7 @@ def __init__(self, email=None, token=None, certtoken=None, debug=False):
352376
if certtoken is None:
353377
certtoken = conf_certtoken
354378

355-
self.base = self._base(email, token, certtoken, base_url, debug)
379+
self.base = self._base(email, token, certtoken, base_url, debug, raw)
356380

357381
# add the API calls
358382
api_v4(self)

0 commit comments

Comments
 (0)