-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
baf7b68
commit 8caa03b
Showing
8 changed files
with
150 additions
and
28 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 |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
*.swp | ||
.DS_Store | ||
|
||
*.egg-info/ | ||
dist/ | ||
build/ | ||
|
||
env | ||
env3 | ||
|
||
|
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,19 @@ | ||
Daiquiri Client | ||
=============== | ||
|
||
Daiquiri Client is a python library meant to be used with the Daiquiri Framework. | ||
|
||
Daiquiri can be downloaded from `https://github.com/aipescience/django-daiquiri <https://github.com/aipescience/django-daiquiri>`_. | ||
|
||
Daiquiri Client provides a set of functions which can be used to use the API of a Daiquiri powered website inside a script. The nessesarry HTTP requests are abstracted in a transparent way. | ||
|
||
A script for getting the emails of all users using Daiquiri Client could look like this: | ||
|
||
.. code:: python | ||
from daiquiri_client import Client | ||
client = Client('http://localhost:8000', '6f3d17e17e46c8e188b4c285ebb53a3fa3ce98c6') | ||
for profile in client.auth.get_profiles(): | ||
print(profile['user']['email']) |
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
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
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,50 @@ | ||
import requests | ||
import simplejson | ||
|
||
from auth import Auth | ||
from metadata import Metadata | ||
from query import Query | ||
|
||
|
||
class Client(object): | ||
|
||
def __init__(self, base_url, token=None): | ||
self.base_url = base_url | ||
|
||
self.headers = {} | ||
if token: | ||
self.headers['Authorization'] = 'Token %s' % token | ||
|
||
self.auth = Auth(self) | ||
self.metadata = Metadata(self) | ||
self.query = Query(self) | ||
|
||
def get(self, url): | ||
response = requests.get(self.base_url + url, headers=self.headers) | ||
response.raise_for_status() | ||
return response.json() | ||
|
||
def post(self, url, data): | ||
response = requests.post(self.base_url + url, data, headers=self.headers) | ||
try: | ||
response.raise_for_status() | ||
return response.json() | ||
except requests.exceptions.HTTPError as e: | ||
try: | ||
print(response.json()) | ||
except simplejson.scanner.JSONDecodeError: | ||
pass | ||
raise e | ||
|
||
def put(self, url, data): | ||
response = requests.put(self.base_url + url, data, headers=self.headers) | ||
try: | ||
response.raise_for_status() | ||
return response.json() | ||
except requests.exceptions.HTTPError as e: | ||
print(response.json()) | ||
raise e | ||
|
||
def delete(self, url): | ||
response = requests.delete(self.base_url + url, headers=self.headers) | ||
response.raise_for_status() |
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,25 @@ | ||
class Query(): | ||
|
||
def __init__(self, client): | ||
self.client = client | ||
|
||
def get_jobs(self): | ||
return self.client.get('/query/api/jobs/') | ||
|
||
def get_job(self, pk): | ||
return self.client.get('/query/api/jobs/%s/' % pk) | ||
|
||
def create_job(self, data): | ||
return self.client.post('/query/api/jobs/', data) | ||
|
||
def update_job(self, pk, data): | ||
return self.client.put('/query/api/jobs/%s/' % pk, { | ||
'table_name': data['table_name'] | ||
}) | ||
|
||
def delete_job(self, pk): | ||
self.client.delete('/query/api/jobs/%s/' % pk) | ||
return {'id': pk} | ||
|
||
def abort_job(self, pk): | ||
return self.client.put('/query/api/jobs/%s/abort/' % pk, {}) |
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,26 @@ | ||
from setuptools import setup, find_packages | ||
|
||
version = '0.1.0' | ||
|
||
author = 'Jochen Klar' | ||
email = '[email protected]' | ||
|
||
setup( | ||
name='django-daiquiri-client', | ||
version=version, | ||
author=author, | ||
author_email=email, | ||
maintainer=author, | ||
maintainer_email=email, | ||
license='Apache-2.0', | ||
url='https://github.com/aipescience/django-daiquiri-client', | ||
description=u'Daiquiri Client is a python library meant to be used with the Daiquiri Framework.', | ||
long_description=open('README.rst').read(), | ||
install_requires=[ | ||
'requests>=2.18.4', | ||
'simplejson>= 3.11.1', | ||
], | ||
classifiers=[], | ||
packages=find_packages(), | ||
include_package_data=True | ||
) |