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

Commit c933789

Browse files
committed
initial code commit
1 parent 948eed8 commit c933789

File tree

7 files changed

+70
-0
lines changed

7 files changed

+70
-0
lines changed

cloudflare_v4/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from exceptions import CloudFlareError, CloudFlareAPIError
2+
3+
from construct import CloudFlare
4+
5+
# depends on exceptions
6+
from util import call
7+
8+
# depends on util
9+
from zones import get
10+
from user import get
11+
12+
__all__ = [ 'CloudFlareError', 'CloudFlareAPIError' ]

cloudflare_v4/construct.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from . import zones
2+
class CloudFlare(object):
3+
def __init__(self, email, token):
4+
self.EMAIL = email
5+
self.TOKEN = token

cloudflare_v4/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class CloudFlareError(Exception):
2+
def __init__(self, value):
3+
self.value = value
4+
def __str__(self):
5+
return self.value
6+
7+
class CloudFlareAPIError(CloudFlareError):
8+
pass

cloudflare_v4/user/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from .. import util
2+
3+
ENDPOINT = 'user'
4+
5+
def get(auth, params=None):
6+
return util.call(auth, 'GET', ENDPOINT, params)

cloudflare_v4/util.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from . import CloudFlareError, CloudFlareAPIError
2+
3+
import json
4+
import requests
5+
6+
def call(auth, method, endpoint, params=None):
7+
response = requests.request(method,
8+
'https://api.cloudflare.com/client/v4/' + endpoint,
9+
headers={ "X-Auth-Email": auth['EMAIL'],
10+
"X-Auth-Key": auth['TOKEN'] },
11+
params=params
12+
)
13+
data = response.text
14+
try:
15+
data = json.loads(data)
16+
return data
17+
except ValueError:
18+
raise CloudFlareAPIError('JSON parse failed.')
19+
if data['result'] == 'error':
20+
raise CloudFlareAPIError(data['msg'])

cloudflare_v4/zones/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from .. import util
2+
3+
ENDPOINT = 'zones'
4+
5+
def get(auth, params=None):
6+
return util.call(auth, 'GET', ENDPOINT, params)

setup.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from setuptools import setup, find_packages
2+
3+
setup(
4+
name='python-cloudflare-v4',
5+
version='1.0',
6+
description='Python wrapper for the CloudFlare v4 API',
7+
author='gnowxilef',
8+
author_email='felix@fawong.com',
9+
url='http://github.com/python-cloudflare/python-cloudflare-v4',
10+
packages=find_packages()
11+
)
12+
13+
package_dir = {'cloudflare_v4': 'lib'}

0 commit comments

Comments
 (0)