-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrest_service.py
More file actions
44 lines (38 loc) · 1.47 KB
/
rest_service.py
File metadata and controls
44 lines (38 loc) · 1.47 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
import requests
class RestService(object):
def __init__(self, headers={}, auth_provider=None):
# https://realpython.com/python-requests/#authentication
self.auth_provider = auth_provider
self.baseHeaders = headers
def get(self, url, params={}, headers={}):
# TODO Perform Logging of both request parameters and response before returning it.
# ensure auth token is not in the logs.
return requests.get(
url=url,
params=params,
headers=self.__accumulateHeaders(headers),
auth=self.auth_provider,
verify=False
)
def post(self, url, body, headers={}):
# TODO Perform Logging of both request parameters and response before returning it.
# ensure auth token is not in the logs.
return requests.post(
url=url,
data=body,
headers=self.__accumulateHeaders(headers),
auth=self.auth_provider,
verify=False
)
def put(self, url, params={}, headers={}):
# TODO Perform Logging of both request parameters and response before returning it.
# ensure auth token is not in the logs.
return requests.get(
url=url,
params=params,
headers=self.__accumulateHeaders(headers),
auth=self.auth_provider,
verify=False
)
def __accumulateHeaders(self, headers):
return {**self.baseHeaders, **headers}