-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRequestHandler.py
More file actions
32 lines (24 loc) · 1.04 KB
/
RequestHandler.py
File metadata and controls
32 lines (24 loc) · 1.04 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
import json
from requests import Response
class RequestHandler:
def __init__(self, requester):
self.requester = requester
def get_jsondict(self, url):
response = self.perform_get_request(url)
decoded_string = response.content.decode("utf-8")
dict_obj = json.loads(decoded_string)
return dict_obj
def perform_get_request(self, url) -> Response:
return self.requester.get(url=url)
def perform_post_request(self, url, json_data=None, **kwargs) -> Response:
if json_data is not None:
kwargs['json'] = json_data
return self.requester.post(url=url, **kwargs)
def perform_put_request(self, url, json_data=None, **kwargs) -> Response:
if json_data is not None:
kwargs['json'] = json_data
return self.requester.put(url=url, **kwargs)
def perform_patch_request(self, url, json_data=None, **kwargs) -> Response:
if json_data is not None:
kwargs['json'] = json_data
return self.requester.patch(url=url, **kwargs)