-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathclient.py
More file actions
38 lines (29 loc) · 956 Bytes
/
client.py
File metadata and controls
38 lines (29 loc) · 956 Bytes
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
34
35
36
37
38
import requests
import re
import json
class Client:
def __init__(
self,
apiKey,
nameSpace='data',
server='api-bdc.net'
):
self.apiKey=apiKey
self.nameSpace=nameSpace
self.server=server
def __getattr__(self,p):
def mm(params):
def conversion(m):
return "-"+m.group(1).lower()
key = re.sub('([A-Z])',conversion,p)
segs = key.split('-')
method = segs.pop(0).upper()
return self.communicate('-'.join(segs),method,params)
return mm
def communicate(self,endpoint,method,payload):
url='https://'+self.server+'/'+self.nameSpace+'/'+endpoint
headers={'X-BDC-Key':self.apiKey}
if (method=='POST' or method=='PUT' or method=='PATCH'):
headers['content-type']='application/x-www-form-urlencoded'
r=getattr(requests,method.lower())(url,headers=headers,params=payload,data=payload)
return [r.json(),r.status_code]