Skip to content

Commit

Permalink
more debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
fawaf committed Feb 10, 2015
1 parent 82c5020 commit 35e9bf5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
4 changes: 4 additions & 0 deletions cloudflare_v4/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# because everything logs
import logging

# all the exceptions
from exceptions import CloudFlareError, CloudFlareAPIError

from construct import CloudFlare
Expand Down
36 changes: 22 additions & 14 deletions cloudflare_v4/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,25 @@
import requests

def call(auth, method, endpoint, params=None):
response = requests.request(method,
'https://api.cloudflare.com/client/v4/' + endpoint,
headers={ "X-Auth-Email": auth['EMAIL'],
"X-Auth-Key": auth['TOKEN'] },
params=params
)
data = response.text
try:
data = json.loads(data)
return data
except ValueError:
raise CloudFlareAPIError('JSON parse failed.')
if data['result'] == 'error':
raise CloudFlareAPIError(data['msg'])
logging.debug('auth')
logging.debug('method')
logging.debug('endpoint')
logging.debug('params')
if (auth is None) or (method is None) or (endpoint is None):
raise CloudFlareError('You must specify auth, method, and endpoint')
else:
response = requests.request(method,
'https://api.cloudflare.com/client/v4/' + endpoint,
headers={ "X-Auth-Email": auth['EMAIL'],
"X-Auth-Key": auth['TOKEN'] },
params=params
)
data = response.text
logging.debug('data')
try:
data = json.loads(data)
return data
except ValueError:
raise CloudFlareAPIError('JSON parse failed.')
if data['result'] == 'error':
raise CloudFlareAPIError(data['msg'])
5 changes: 4 additions & 1 deletion cloudflare_v4/zones/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
ENDPOINT = 'zones'

def get(auth, params=None):
return util.call(auth, 'GET', ENDPOINT, params)
if type(params) is dict:
return util.call(auth, 'GET', ENDPOINT, params)
elif type(params) is str:
return util.call(auth)

0 comments on commit 35e9bf5

Please sign in to comment.