Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ pip-log.txt
.coverage
.tox
nosetests.xml
test.py
2 changes: 1 addition & 1 deletion kickbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .client import Client
from .api import Verification, Authentication
92 changes: 92 additions & 0 deletions kickbox/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import requests
from .errors import ErrorHandler
from .response_handler import ResponseHandler


class Client(object):

# Define base url
BASE_URL = "https://api.kickbox.io"

def make_request(self, url, method='get', params={}):
headers = {
'user-agent':
'kickbox-python/3.0.0 (https://github.com/kickboxio/kickbox-python)'
}

url = "%s%s" % (self.BASE_URL, url)

if method is 'get':
response = requests.get(
url, headers=headers, params=params, hooks=dict(
response=ErrorHandler.check_error
)
)
else:
response = requests.post(url, headers=headers, params=params)

return ResponseHandler.get_body(response)


class Verification(Client):

"""Verification."""

def __init__(self, api_key, version='v2'):
"""ad.

Args:
api_key: API key of the authentication app
"""
self.api_key = api_key
self.version = version

def verify(self, email, timeout=6000):
"""Verify an Email address.

Args:
email: email to be verified
"""
url = "/%s/verify" % (self.version)

response = self.make_request(
url=url, method="get", params={
'email': email, 'api_key': self.api_key, 'timeout': timeout
}
)
return response


class Authentication(Client):

def __init__(self, app_code, api_key):
"""
Args:
app_code: The code for the authentication app
api_key: Your API key of the authentication app
"""
self.app_code = app_code
self.api_key = api_key
super(Authentication, self).__init__()

def authenticate(self, fingerprint):
"""Send the authentication email.

Args:
fingerprint: The fingerprint for the email address
"""
url = "/v2/authenticate/%s" % (self.app_code)
params = {'api_key': self.api_key, 'fingerprint': fingerprint}
response = self.make_request(url=url, method='post', params=params)
return response

def getStatus(self, id):
"""Get the status of an authentication.

Args:
id: Authentication id returned from the authenticate request
"""
url = "/v2/authenticate/%s/%s" % (self.app_code, id)
params = {'api_key': self.api_key}
response = self.make_request(url=url, method='get', params=params)
return response
2 changes: 0 additions & 2 deletions kickbox/api/__init__.py

This file was deleted.

27 changes: 0 additions & 27 deletions kickbox/api/kickbox.py

This file was deleted.

16 changes: 0 additions & 16 deletions kickbox/client.py

This file was deleted.

1 change: 0 additions & 1 deletion kickbox/error/__init__.py

This file was deleted.

8 changes: 0 additions & 8 deletions kickbox/error/client_error.py

This file was deleted.

30 changes: 30 additions & 0 deletions kickbox/errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from .response_handler import ResponseHandler


class Error(Exception):
def __init__(self, message, code):
super(Error, self).__init__()
self.message = message
self.code = code


class ErrorHandler(object):
@staticmethod
def check_error(response, *args, **kwargs):
code = response.status_code
content_type = response.headers.get('content-type')

if code in range(500, 600):
raise Error('Error ' + str(code), code)

# handle rate limit
elif code is 429:
raise Error('Rate limit exceeded.')
elif code in range(400, 500):
body = ResponseHandler.get_body(response)
message = body

if content_type.find('json') != -1:
message = body['message']

raise Error(message, code)
134 changes: 0 additions & 134 deletions kickbox/http_client/__init__.py

This file was deleted.

38 changes: 0 additions & 38 deletions kickbox/http_client/auth_handler.py

This file was deleted.

34 changes: 0 additions & 34 deletions kickbox/http_client/error_handler.py

This file was deleted.

Loading