forked from cloudflare-api/python-cloudflare-v4
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'} |