|
@@ -14,6 +14,16 @@ TOKEN = os.getenv('ASTOR_RECO_TOKEN') or 'xQ6dTveTtBpFmmZ7'
|
|
|
TOKEN_SECRET = os.getenv('ASTOR_RECO_TOKEN_SECRET') or 'T7rCUS2lFXNAXv6e'
|
|
|
|
|
|
|
|
|
+def check_response(response):
|
|
|
+ if response.status_code == 403:
|
|
|
+ raise PermissionError()
|
|
|
+ elif response.status_code == 404:
|
|
|
+ raise NotFoundError()
|
|
|
+ elif response.status_code != 200:
|
|
|
+ print response.text
|
|
|
+ raise ArbitraryError(response.status_code)
|
|
|
+
|
|
|
+
|
|
|
class Client(object):
|
|
|
def __init__(self, base_url=BASE_URL, key=KEY, secret=SECRET,
|
|
|
token=TOKEN, token_secret=TOKEN_SECRET):
|
|
@@ -63,7 +73,12 @@ class Client(object):
|
|
|
def create_object(self, investigation_id, label=None, uploader_id=None, note=None):
|
|
|
url = self.url('basemetadata/investigations', investigation_id, 'digitalObjects')
|
|
|
params = dict(label=label, uploader_id=uploader_id, note=note)
|
|
|
- response = requests.post(url, data=params)
|
|
|
+
|
|
|
+ try:
|
|
|
+ response = requests.post(url, data=params, timeout=5)
|
|
|
+ check_response(response)
|
|
|
+ except requests.exceptions.Timeout:
|
|
|
+ raise Timeout()
|
|
|
|
|
|
def get_organization(self, oid):
|
|
|
return Organization(self.get_response(self.url('dataorganization/organization', oid)))
|
|
@@ -87,15 +102,8 @@ class Client(object):
|
|
|
|
|
|
try:
|
|
|
response = requests.get(url, auth=self.auth, params=params, timeout=5)
|
|
|
+ check_response(response)
|
|
|
+ return ElementTree.fromstring(response.text)
|
|
|
except requests.exceptions.Timeout:
|
|
|
raise Timeout()
|
|
|
|
|
|
- if response.status_code == 403:
|
|
|
- raise PermissionError()
|
|
|
- elif response.status_code == 404:
|
|
|
- raise NotFoundError()
|
|
|
- elif response.status_code != 200:
|
|
|
- raise ArbitraryError(response.status_code)
|
|
|
-
|
|
|
- return ElementTree.fromstring(response.text)
|
|
|
-
|