Skip to content

Commit

Permalink
posting dns_records to zone
Browse files Browse the repository at this point in the history
  • Loading branch information
fawaf committed Feb 14, 2015
1 parent 0dee0ba commit 8e79a53
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
28 changes: 16 additions & 12 deletions cloudflare_v4/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,28 @@
import json
import requests

logger = logger.Logger(logger.DEBUG).getLogger()
logger = logger.Logger(logger.INFO).getLogger()
BASE_URL = 'https://api.cloudflare.com/client/v4'

def call(auth, method, endpoint, params=None):
logger.debug(auth)
logger.debug(method)
logger.debug(endpoint)
logger.debug(params)
headers = { "X-Auth-Email": auth['EMAIL'], "X-Auth-Key": auth['TOKEN'] }
url = BASE_URL + '/' + endpoint
logger.debug("auth is: " + str(auth))
logger.debug("method type is: " + method)
logger.debug("url endpoint is: " + url)
logger.debug("optional params is: " + str(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
)
if method.upper() == 'GET':
logger.debug("headers being sent: " + str(headers))
response = requests.get(url, headers=headers, params=params)
elif method.upper() == 'POST':
headers['Content-Type'] = 'application/json'
logger.debug("headers being sent: " + str(headers))
response = requests.post(url, headers=headers, json=params)
data = response.text
logger.debug(data)
logger.debug("data received: " + data)
try:
data = json.loads(data)
return data
Expand Down
7 changes: 5 additions & 2 deletions cloudflare_v4/zones/dns_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@

ENDPOINT = 'dns_records'

def get(auth, params=None):
util.call(auth, 'GET', 'zones/' + params + '/' + ENDPOINT)
def get(auth, zone_id, params=None):
return util.call(auth, 'GET', 'zones/' + zone_id + '/' + ENDPOINT, params)

def post(auth, zone_id, params=None):
return util.call(auth, 'POST', 'zones/' + zone_id + '/' + ENDPOINT, params)

0 comments on commit 8e79a53

Please sign in to comment.