summaryrefslogtreecommitdiff
path: root/pylibchorus
diff options
context:
space:
mode:
authorkballou <kballou@devnulllabs.io>2015-04-24 19:05:11 -0600
committerkballou <kballou@devnulllabs.io>2015-04-24 19:05:11 -0600
commit0474c99b8a5c12666eb28191af103aa98cfd9934 (patch)
tree71c7b7a7e7e1d7787ff5ac69d01bf00e5dc0993d /pylibchorus
parent96968f9f2d38d45d3154fa3c95860091cc909dd9 (diff)
downloadpylibchorus-0474c99b8a5c12666eb28191af103aa98cfd9934.tar.gz
pylibchorus-0474c99b8a5c12666eb28191af103aa98cfd9934.tar.xz
Return only the necessary attributes
Change the internal `_perform_http_method_` return the status code, JSON object, and cookies dictionary. API functions should extract and return only the necessary attributes.
Diffstat (limited to 'pylibchorus')
-rw-r--r--pylibchorus/__init__.py8
-rw-r--r--pylibchorus/chorus_api.py18
2 files changed, 18 insertions, 8 deletions
diff --git a/pylibchorus/__init__.py b/pylibchorus/__init__.py
index f9f912d..079ae14 100644
--- a/pylibchorus/__init__.py
+++ b/pylibchorus/__init__.py
@@ -24,14 +24,16 @@ class ChorusSession(object):
'''create session and return sid and cookies'''
LOG.debug("Opening Chorus Session")
- post = login(
+ code, json, cookies = login(
self.config.get('alpine', 'username'),
self.config.get('alpine', 'password'),
self)
- json = post.json()
+
+ if code != 201:
+ raise RuntimeError("Chorus Session Login Failed")
self.sid = json['response']['session_id']
- self.cookies = dict(post.cookies)
+ self.cookies = dict(cookies)
return self
def __exit__(self, _type, _value, _traceback):
diff --git a/pylibchorus/chorus_api.py b/pylibchorus/chorus_api.py
index f9c5223..8319aff 100644
--- a/pylibchorus/chorus_api.py
+++ b/pylibchorus/chorus_api.py
@@ -20,36 +20,44 @@ def logout(session):
session.config.get('alpine', 'host'),
_logout_(session.sid, session.cookies))
+#pylint: disable=C0103
def check_login_status(session):
'''GET login request to chorus server'''
- return _perform_http_method_(
+ ok, json, _ = _perform_http_method_(
session.config.get('alpine', 'host'),
_check_login_(session.sid, session.cookies))
+ return (ok, json['response']['session_id'],)
+#pylint: disable=C0103
def create_workfile(workspace_id, workfile_name, session):
'''POST new workfile to workspace'''
- return _perform_http_method_(
+ ok, json, _ = _perform_http_method_(
session.config.get('alpine', 'host'),
_create_workfile_(workspace_id,
workfile_name,
session.sid,
session.cookies))
+ return (ok, json['response']['id'], json['response']['user_modified_at'],)
+#pylint: disable=C0103
def update_workfile_version(userid, workfile_id, workfile, session):
'''POST new workfile version'''
- return _perform_http_method_(
+ ok, json, _ = _perform_http_method_(
session.config.get('alpine', 'host'),
_update_workfile_version_(userid,
workfile_id,
workfile,
session.sid,
session.cookies))
+ return (ok, json['response']['id'], json['response']['user_modified_at'],)
+#pylint: disable=C0103
def delete_workfile(workfile_id, session):
'''DELETE workfile'''
- return _perform_http_method_(
+ ok, _, _ = _perform_http_method_(
session.config.get('alpine', 'host'),
_delete_workfile_(workfile_id, session.sid, session.cookies))
+ return ok
def _get_url_(host, endpoint=""):
'''Return the host and path for the chorus instance'''
@@ -69,7 +77,7 @@ def _perform_http_method_(host, request_data):
LOG.info("Request: %s status code: %d",
request_data['url'],
response.status_code)
- return response
+ return (response.status_code, response.json(), response.cookies,)
def _login_(username, password):
'''Create Request Data for ChorusSession'''