-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExtendedExample.py
34 lines (26 loc) · 1.04 KB
/
ExtendedExample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/python
import REST_Connect
import config
import os
try:
import json
except:
import simplejson as json
class Connection(REST_Connect.Connection):
@classmethod
def factory(self, key):
_cfg = config.Config(file(os.path.join(os.path.dirname(__file__), 'example.cfg')))
_conn = _cfg.connection
return Connection(base_url = "%s://%s" %(_conn.scheme, _conn[key]))
def __init__(self, base_url, username=None, password=None):
super(Connection, self).__init__(base_url, username, password)
def request(self, resource, method = "get", args = None, body = None, filename=None, headers={}):
if body:
body = json.dumps(body)
response = super(Connection, self).request(resource, method, args, body, filename, headers)
body = response['body']
headers = response['headers']
content_type = headers['content-type']
if content_type == "application/json":
body = json.loads(body)
return {'headers':response['headers'], 'body':body}