Skip to content

Commit 15dde1a

Browse files
update system events and history default helpers
1 parent 4e63ed1 commit 15dde1a

File tree

2 files changed

+59
-44
lines changed

2 files changed

+59
-44
lines changed

conSys/part_2/system_events.py

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import requests
21
from pydantic import HttpUrl
32

43
from conSys.con_sys_api import ConnectedSystemsRequestBuilder
54
from conSys.constants import APITerms
65

76

8-
def list_system_events(server_addr: HttpUrl, api_root: str = APITerms.API.value):
7+
def list_system_events(server_addr: HttpUrl, api_root: str = APITerms.API.value, headers: dict = None):
98
"""
109
Lists all system events
1110
:return:
@@ -15,12 +14,14 @@ def list_system_events(server_addr: HttpUrl, api_root: str = APITerms.API.value)
1514
.with_api_root(api_root)
1615
.for_resource_type(APITerms.SYSTEM_EVENTS.value)
1716
.build_url_from_base()
17+
.with_headers(headers)
18+
.with_request_method('GET')
1819
.build())
19-
resp = requests.get(api_request.url, params=api_request.body, headers=api_request.headers)
20-
return resp.json()
20+
return api_request.make_request()
2121

2222

23-
def list_events_by_system_id(server_addr: HttpUrl, system_id: str, api_root: str = APITerms.API.value):
23+
def list_events_by_system_id(server_addr: HttpUrl, system_id: str, api_root: str = APITerms.API.value,
24+
headers: dict = None):
2425
"""
2526
Lists all events of a system
2627
:return:
@@ -30,14 +31,16 @@ def list_events_by_system_id(server_addr: HttpUrl, system_id: str, api_root: str
3031
.with_api_root(api_root)
3132
.for_resource_type(APITerms.SYSTEMS.value)
3233
.with_resource_id(system_id)
33-
.for_resource_type(APITerms.EVENTS.value)
34+
.for_sub_resource_type(APITerms.EVENTS.value)
3435
.build_url_from_base()
36+
.with_headers(headers)
37+
.with_request_method('GET')
3538
.build())
36-
resp = requests.get(api_request.url, params=api_request.body, headers=api_request.headers)
37-
return resp.json()
39+
return api_request.make_request()
40+
3841

3942
def add_new_system_events(server_addr: HttpUrl, system_id: str, request_body: dict,
40-
api_root: str = APITerms.API.value):
43+
api_root: str = APITerms.API.value, headers: dict = None):
4144
"""
4245
Adds a new system event to a system by its id
4346
:return:
@@ -47,14 +50,17 @@ def add_new_system_events(server_addr: HttpUrl, system_id: str, request_body: di
4750
.with_api_root(api_root)
4851
.for_resource_type(APITerms.SYSTEMS.value)
4952
.with_resource_id(system_id)
50-
.for_resource_type(APITerms.EVENTS.value)
53+
.for_sub_resource_type(APITerms.EVENTS.value)
5154
.with_request_body(request_body)
5255
.build_url_from_base()
56+
.with_headers(headers)
57+
.with_request_method('POST')
5358
.build())
54-
resp = requests.post(api_request.url, params=api_request.body, headers=api_request.headers)
55-
return resp.json()
59+
return api_request.make_request()
60+
5661

57-
def retrieve_system_event_by_id(server_addr: HttpUrl, system_id: str, event_id: str, api_root: str = APITerms.API.value):
62+
def retrieve_system_event_by_id(server_addr: HttpUrl, system_id: str, event_id: str,
63+
api_root: str = APITerms.API.value, headers: dict = None):
5864
"""
5965
Retrieves a system event by its id
6066
:return:
@@ -64,15 +70,17 @@ def retrieve_system_event_by_id(server_addr: HttpUrl, system_id: str, event_id:
6470
.with_api_root(api_root)
6571
.for_resource_type(APITerms.SYSTEMS.value)
6672
.with_resource_id(system_id)
67-
.for_resource_type(APITerms.EVENTS.value)
68-
.with_resource_id(event_id)
73+
.for_sub_resource_type(APITerms.EVENTS.value)
74+
.with_secondary_resource_id(event_id)
6975
.build_url_from_base()
76+
.with_headers(headers)
77+
.with_request_method('GET')
7078
.build())
71-
resp = requests.get(api_request.url, params=api_request.body, headers=api_request.headers)
72-
return resp.json()
79+
return api_request.make_request()
80+
7381

7482
def update_system_event_by_id(server_addr: HttpUrl, system_id: str, event_id: str, request_body: dict,
75-
api_root: str = APITerms.API.value):
83+
api_root: str = APITerms.API.value, headers: dict = None):
7684
"""
7785
Updates a system event by its id
7886
:return:
@@ -82,15 +90,18 @@ def update_system_event_by_id(server_addr: HttpUrl, system_id: str, event_id: st
8290
.with_api_root(api_root)
8391
.for_resource_type(APITerms.SYSTEMS.value)
8492
.with_resource_id(system_id)
85-
.for_resource_type(APITerms.EVENTS.value)
86-
.with_resource_id(event_id)
93+
.for_sub_resource_type(APITerms.EVENTS.value)
94+
.with_secondary_resource_id(event_id)
8795
.with_request_body(request_body)
8896
.build_url_from_base()
97+
.with_headers(headers)
98+
.with_request_method('PUT')
8999
.build())
90-
resp = requests.put(api_request.url, params=api_request.body, headers=api_request.headers)
91-
return resp.json()
100+
return api_request.make_request()
101+
92102

93-
def delete_system_event_by_id(server_addr: HttpUrl, system_id: str, event_id: str, api_root: str = APITerms.API.value):
103+
def delete_system_event_by_id(server_addr: HttpUrl, system_id: str, event_id: str, api_root: str = APITerms.API.value,
104+
headers: dict = None):
94105
"""
95106
Deletes a system event by its id
96107
:return:
@@ -100,9 +111,10 @@ def delete_system_event_by_id(server_addr: HttpUrl, system_id: str, event_id: st
100111
.with_api_root(api_root)
101112
.for_resource_type(APITerms.SYSTEMS.value)
102113
.with_resource_id(system_id)
103-
.for_resource_type(APITerms.EVENTS.value)
104-
.with_resource_id(event_id)
114+
.for_sub_resource_type(APITerms.EVENTS.value)
115+
.with_secondary_resource_id(event_id)
105116
.build_url_from_base()
117+
.with_headers(headers)
118+
.with_request_method('DELETE')
106119
.build())
107-
resp = requests.delete(api_request.url, params=api_request.body, headers=api_request.headers)
108-
return resp.json()
120+
return api_request.make_request()

conSys/part_2/system_history.py

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import requests
21
from pydantic import HttpUrl
32

43
from conSys.con_sys_api import ConnectedSystemsRequestBuilder
54
from conSys.constants import APITerms
65

76

8-
def list_system_history(server_addr: HttpUrl, system_id: str, api_root: str = APITerms.API.value):
7+
def list_system_history(server_addr: HttpUrl, system_id: str, api_root: str = APITerms.API.value, headers: dict = None):
98
"""
109
Lists all history versions of a system
1110
:return:
@@ -17,13 +16,14 @@ def list_system_history(server_addr: HttpUrl, system_id: str, api_root: str = AP
1716
.with_resource_id(system_id)
1817
.for_resource_type(APITerms.HISTORY.value)
1918
.build_url_from_base()
19+
.with_headers(headers)
20+
.with_request_method('GET')
2021
.build())
21-
resp = requests.get(api_request.url, params=api_request.body, headers=api_request.headers)
22-
return resp.json()
22+
return api_request.make_request()
2323

2424

2525
def retrieve_system_historical_description_by_id(server_addr: HttpUrl, system_id: str, history_id: str,
26-
api_root: str = APITerms.API.value):
26+
api_root: str = APITerms.API.value, headers: dict = None):
2727
"""
2828
Retrieves a historical system description by its id
2929
:return:
@@ -36,13 +36,14 @@ def retrieve_system_historical_description_by_id(server_addr: HttpUrl, system_id
3636
.for_resource_type(APITerms.HISTORY.value)
3737
.with_secondary_resource_id(history_id)
3838
.build_url_from_base()
39+
.with_headers(headers)
40+
.with_request_method('GET')
3941
.build())
40-
resp = requests.get(api_request.url, params=api_request.body, headers=api_request.headers)
41-
return resp.json()
42+
return api_request.make_request()
4243

4344

44-
def update_system_historical_description(server_addr: HttpUrl, system_id: str, history_id: str, request_body: dict,
45-
api_root: str = APITerms.API.value):
45+
def update_system_historical_description(server_addr: HttpUrl, system_id: str, history_rev_id: str, request_body: dict,
46+
api_root: str = APITerms.API.value, headers: dict = None):
4647
"""
4748
Updates a historical system description by its id
4849
:return:
@@ -53,16 +54,17 @@ def update_system_historical_description(server_addr: HttpUrl, system_id: str, h
5354
.for_resource_type(APITerms.SYSTEMS.value)
5455
.with_resource_id(system_id)
5556
.for_resource_type(APITerms.HISTORY.value)
56-
.with_secondary_resource_id(history_id)
57+
.with_secondary_resource_id(history_rev_id)
5758
.with_request_body(request_body)
5859
.build_url_from_base()
60+
.with_headers(headers)
61+
.with_request_method('PUT')
5962
.build())
60-
resp = requests.put(api_request.url, params=api_request.body, headers=api_request.headers)
61-
return resp.json()
63+
return api_request.make_request()
6264

6365

64-
def delete_system_historical_description_by_id(server_addr: HttpUrl, system_id: str, history_id: str,
65-
api_root: str = APITerms.API.value):
66+
def delete_system_historical_description_by_id(server_addr: HttpUrl, system_id: str, history_rev_id: str,
67+
api_root: str = APITerms.API.value, headers: dict = None):
6668
"""
6769
Deletes a historical system description by its id
6870
:return:
@@ -73,8 +75,9 @@ def delete_system_historical_description_by_id(server_addr: HttpUrl, system_id:
7375
.for_resource_type(APITerms.SYSTEMS.value)
7476
.with_resource_id(system_id)
7577
.for_resource_type(APITerms.HISTORY.value)
76-
.with_secondary_resource_id(history_id)
78+
.with_secondary_resource_id(history_rev_id)
7779
.build_url_from_base()
80+
.with_headers(headers)
81+
.with_request_method('DELETE')
7882
.build())
79-
resp = requests.delete(api_request.url, params=api_request.body, headers=api_request.headers)
80-
return resp.json()
83+
return api_request.make_request()

0 commit comments

Comments
 (0)