From fe7d02b21ede3e078b708f7dfe2a97a2bf1efd65 Mon Sep 17 00:00:00 2001 From: Jochen Klar Date: Thu, 6 Dec 2018 16:10:04 +0100 Subject: [PATCH] Add patch and tap --- daiquiri_client/auth.py | 5 ++++- daiquiri_client/client.py | 25 +++++++++++++++++++------ daiquiri_client/tap.py | 10 ++++++++++ 3 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 daiquiri_client/tap.py diff --git a/daiquiri_client/auth.py b/daiquiri_client/auth.py index 1ab693f..9099612 100644 --- a/daiquiri_client/auth.py +++ b/daiquiri_client/auth.py @@ -4,7 +4,7 @@ def __init__(self, client): self.client = client def get_profiles(self): - return self.client.get('/auth/api/profiles/')['results'] + return self.client.get('/auth/api/profiles/', {'page_size': 10000})['results'] def get_groups(self): return self.client.get('/auth/api/groups/') @@ -14,3 +14,6 @@ def get_group_map(self): def activate_profile(self, pk): return self.client.put('/auth/api/profiles/%d/activate/' % pk, {}) + + def update_profile_attributes(self, pk, attributes): + return self.client.patch('/auth/api/profiles/%d/' % pk, {'attributes': attributes}) diff --git a/daiquiri_client/client.py b/daiquiri_client/client.py index 3bd5f2b..1550336 100644 --- a/daiquiri_client/client.py +++ b/daiquiri_client/client.py @@ -4,6 +4,7 @@ from .auth import Auth from .metadata import Metadata from .query import Query +from .tap import Tap class Client(object): @@ -18,20 +19,22 @@ def __init__(self, base_url, token=None): self.auth = Auth(self) self.metadata = Metadata(self) self.query = Query(self) + self.tap = Tap(self) - def get(self, url): - response = requests.get(self.base_url + url, headers=self.headers) + def get(self, url, params={}, json=True): + response = requests.get(self.base_url + url, params=params, headers=self.headers) response.raise_for_status() - return response.json() + return response.json() if json else response.text - def post(self, url, data): + def post(self, url, data, json=True): response = requests.post(self.base_url + url, data, headers=self.headers) + try: response.raise_for_status() - return response.json() + return response.json() if json else response.text except requests.exceptions.HTTPError as e: try: - print(response.json()) + print(response.json() if json else response.text) except simplejson.scanner.JSONDecodeError: pass raise e @@ -45,6 +48,16 @@ def put(self, url, data): print(response.json()) raise e + def patch(self, url, data): + response = requests.patch(self.base_url + url, json=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() diff --git a/daiquiri_client/tap.py b/daiquiri_client/tap.py new file mode 100644 index 0000000..65c2afa --- /dev/null +++ b/daiquiri_client/tap.py @@ -0,0 +1,10 @@ +class Tap(): + + def __init__(self, client): + self.client = client + + def sync(self, query, query_language='ADQL'): + return self.client.post('/tap/sync', { + 'QUERY': query, + 'LANG': query_language + }, json=False)