-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathhelpers.py
47 lines (44 loc) · 1.51 KB
/
helpers.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import json
import requests
def call_api_get(url, access_token, return_raw=True):
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
response = requests.get(url, headers=headers)
if return_raw:
return response
else:
# Check the response status
if response.status_code == 200:
return json.dumps(response.json(), indent=4)
else:
return "{}: {} {}".format("Error", response.status_code, response.text)
def call_api_post(url, data, access_token, return_raw=True):
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
response = requests.post(url, headers=headers, data=json.dumps(data))
if return_raw:
return response
else:
# Check the response status
if response.status_code == 201:
return json.dumps(response.json(), indent=4)
else:
return "{}: {} {}".format("Error", response.status_code, response.text)
def call_api_delete(url, access_token, return_raw=True):
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
response = requests.delete(url, headers=headers)
if return_raw:
return response
else:
# Check the response status
if response.status_code == 204:
return response
else:
return "{}: {} {}".format("Error", response.status_code, response.text)