-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrelaykeysclient.py
31 lines (27 loc) · 1011 Bytes
/
relaykeysclient.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
import requests
import json
import functools
class RelayKeysClient (object):
def __init__(self, url=None, host=None, port=None,
username=None, password=None):
if (host is None or port is None) and url is None:
raise ValueError("url and host:port is not defined!")
if url is None:
auth = "{}:{}@".format(username,
password) if username is not None else ""
self.url = "http://{}{}:{}/".format(auth, host, port)
else:
self.url = url
def call(self, name, *args):
payload = {
"method": name,
"params": [args],
"jsonrpc": "2.0",
"id": 0,
}
headers = {'content-type': 'application/json'}
data = json.dumps(payload)
resp = requests.post(self.url, data, headers=headers, timeout=10.00)
return resp.json()
def __getattr__(self, attr):
return functools.partial(self.call, attr)