-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_manager.py
46 lines (40 loc) · 1.41 KB
/
data_manager.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
import requests
class DataManager:
def __init__(self, endpoint, token):
self.endpoint = endpoint
self.bearer_token = f"Bearer {token}"
self.header = {
"Content-Type": "application/json",
"Authorization": self.bearer_token
}
self.data = []
def get_flight_data(self):
response = requests.get(url=f"{self.endpoint}/prices", headers=self.header)
result = response.json()
self.data = result['prices']
return result['prices']
def update_flight_data(self, row_id, payload):
url = f"{self.endpoint}/prices/{row_id}"
body = {
"price": {key: payload[key] for key in payload}
}
response = requests.put(url=url, json=body, headers=self.header)
result = response.json()
print(result)
def add_user(self, user):
url = f"{self.endpoint}/users"
body = {
"user": {
"firstName": user.first_name,
"lastName": user.last_name,
"email": user.email
}
}
response = requests.post(url=url, json=body, headers=self.header)
result = response.json()
print(result)
def get_users(self):
response = requests.get(url=f"{self.endpoint}/users", headers=self.header)
result = response.json()
self.data = result['users']
return result['users']