summaryrefslogtreecommitdiffstats
path: root/pykolab/wap_client/request.py
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-03-13 16:17:34 +0000
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2012-03-13 16:17:34 +0000
commit812920a2077860091bd003956fdf4296d187b329 (patch)
tree29af52cec5113e4ab19d4488f7b2b480b7ea1ec4 /pykolab/wap_client/request.py
parent3ee814c43398756b1756628ab8e1f9d09e1acec6 (diff)
downloadpykolab-812920a2077860091bd003956fdf4296d187b329.tar.gz
Split out connect.py and request.py
Diffstat (limited to 'pykolab/wap_client/request.py')
-rw-r--r--pykolab/wap_client/request.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/pykolab/wap_client/request.py b/pykolab/wap_client/request.py
new file mode 100644
index 0000000..0613333
--- /dev/null
+++ b/pykolab/wap_client/request.py
@@ -0,0 +1,29 @@
+def request(method, api_uri, params=None, headers={}):
+ global session_id
+
+ if not session_id == None:
+ headers["X-Session-Token"] = session_id
+
+ conn = connect()
+ conn.request(method.upper(), "%s/%s" % (API_BASE,api_uri), params, headers)
+ response = conn.getresponse()
+ data = response.read()
+
+ print method, api_uri, params
+ print data
+
+ try:
+ response_data = json.loads(data)
+ except ValueError, e:
+ # Some data is not JSON
+ print "Response data is not JSON"
+ sys.exit(1)
+
+ print response_data
+
+ if response_data['status'] == "OK":
+ del response_data['status']
+ return response_data['result']
+ else:
+ return response_data['result']
+