forked from clustersolutions/RESO-WebAPI-Client-Python
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli_example.py
More file actions
61 lines (50 loc) · 1.98 KB
/
Copy pathcli_example.py
File metadata and controls
61 lines (50 loc) · 1.98 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
import os
import json
from reso_api.reso import RESO
from reso_api.open_id import OpenIDAuthentication
from reso_api.request import HttpRequest
def read_file_to_dict():
file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config.json')
if os.path.isfile(file_path):
with open(file_path) as f:
config_dict = json.load(f)
return config_dict
else:
raise ValueError('configs file is missing')
def cli_example():
configs = read_file_to_dict()
reso = RESO(
client_id=configs['reso']['client_id'],
client_secret=configs['reso']['client_secret'],
# Some vendors bypass access_token by passing and supplying a static value
access_token=None if 'access_token' not in configs['reso'] else configs['reso']['access_token'],
api_auth_url=configs['reso']['api_auth_url'],
api_token_url=configs['reso']['api_token_url'],
verify_ssl=configs['reso']['verify_ssl'],
api_request_url=configs['reso']['api_request_url']
)
reso.set_logging_level('debug')
req_obj = OpenIDAuthentication(
redirect_uri=configs['open_id']['redirect_uri'],
scope=configs['open_id']['scope'],
reso=reso
)
response = req_obj.authorize(configs['username'], configs['password'])
req_obj.auth_code = response
if not reso.access_token: # User did not supply access_token (most common case)
auth_token = req_obj.request_access_token()
reso.access_token = auth_token
http_req = HttpRequest(
reso=reso,
)
http_req.request_to_file(
request_url=configs['http_request']['request_path'],
filename=configs['http_request']['filename'],
request_accept_type=configs['http_request']['accept_type'],
output_format=configs['http_request']['output_format'],
overwrite=True,
indent=4 # Set to None for pretty print not to be applied
)
if __name__ == '__main__':
cli_example()