Skip to content

Commit

Permalink
initial code commit
Browse files Browse the repository at this point in the history
  • Loading branch information
fawaf committed Jan 26, 2015
1 parent 948eed8 commit c933789
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cloudflare_v4/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from exceptions import CloudFlareError, CloudFlareAPIError

from construct import CloudFlare

# depends on exceptions
from util import call

# depends on util
from zones import get
from user import get

__all__ = [ 'CloudFlareError', 'CloudFlareAPIError' ]
5 changes: 5 additions & 0 deletions cloudflare_v4/construct.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from . import zones
class CloudFlare(object):
def __init__(self, email, token):
self.EMAIL = email
self.TOKEN = token
8 changes: 8 additions & 0 deletions cloudflare_v4/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CloudFlareError(Exception):
def __init__(self, value):
self.value = value
def __str__(self):
return self.value

class CloudFlareAPIError(CloudFlareError):
pass
6 changes: 6 additions & 0 deletions cloudflare_v4/user/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .. import util

ENDPOINT = 'user'

def get(auth, params=None):
return util.call(auth, 'GET', ENDPOINT, params)
20 changes: 20 additions & 0 deletions cloudflare_v4/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from . import CloudFlareError, CloudFlareAPIError

import json
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'])
6 changes: 6 additions & 0 deletions cloudflare_v4/zones/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from .. import util

ENDPOINT = 'zones'

def get(auth, params=None):
return util.call(auth, 'GET', ENDPOINT, params)
13 changes: 13 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from setuptools import setup, find_packages

setup(
name='python-cloudflare-v4',
version='1.0',
description='Python wrapper for the CloudFlare v4 API',
author='gnowxilef',
author_email='felix@fawong.com',
url='http://github.com/python-cloudflare/python-cloudflare-v4',
packages=find_packages()
)

package_dir = {'cloudflare_v4': 'lib'}

0 comments on commit c933789

Please sign in to comment.