summaryrefslogtreecommitdiffstats
path: root/pykolab/wap_client/request.py
diff options
context:
space:
mode:
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']
+