Skip to content

Commit

Permalink
Add patch and tap
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Dec 6, 2018
1 parent 2f6874a commit fe7d02b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
5 changes: 4 additions & 1 deletion daiquiri_client/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/')
Expand All @@ -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})
25 changes: 19 additions & 6 deletions daiquiri_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .auth import Auth
from .metadata import Metadata
from .query import Query
from .tap import Tap


class Client(object):
Expand All @@ -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
Expand All @@ -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()
10 changes: 10 additions & 0 deletions daiquiri_client/tap.py
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit fe7d02b

Please sign in to comment.