|
| 1 | +import requests |
| 2 | +from pydantic import HttpUrl |
| 3 | + |
| 4 | +from conSys.con_sys_api import ConnectedSystemsRequestBuilder |
| 5 | +from conSys.constants import APITerms |
| 6 | + |
| 7 | + |
| 8 | +def list_all_constrol_streams(server_addr: HttpUrl, api_root: str = APITerms.API.value): |
| 9 | + """ |
| 10 | + Lists all control streams |
| 11 | + :return: |
| 12 | + """ |
| 13 | + builder = ConnectedSystemsRequestBuilder() |
| 14 | + api_request = (builder.with_server_url(server_addr) |
| 15 | + .with_api_root(api_root) |
| 16 | + .for_resource_type(APITerms.CONTROL_STREAMS.value) |
| 17 | + .build_url_from_base() |
| 18 | + .build()) |
| 19 | + resp = requests.get(api_request.url, params=api_request.body, headers=api_request.headers) |
| 20 | + return resp.json() |
| 21 | + |
| 22 | + |
| 23 | +def list_control_streams_of_system(server_addr: HttpUrl, system_id: str, api_root: str = APITerms.API.value): |
| 24 | + """ |
| 25 | + Lists all control streams of a system |
| 26 | + :return: |
| 27 | + """ |
| 28 | + builder = ConnectedSystemsRequestBuilder() |
| 29 | + api_request = (builder.with_server_url(server_addr) |
| 30 | + .with_api_root(api_root) |
| 31 | + .for_resource_type(APITerms.SYSTEMS.value) |
| 32 | + .with_resource_id(system_id) |
| 33 | + .for_resource_type(APITerms.CONTROL_STREAMS.value) |
| 34 | + .build_url_from_base() |
| 35 | + .build()) |
| 36 | + resp = requests.get(api_request.url, params=api_request.body, headers=api_request.headers) |
| 37 | + return resp.json() |
| 38 | + |
| 39 | + |
| 40 | +def add_control_streams_to_system(server_addr: HttpUrl, system_id: str, request_body: dict, |
| 41 | + api_root: str = APITerms.API.value): |
| 42 | + """ |
| 43 | + Adds a control stream to a system by its id |
| 44 | + :return: |
| 45 | + """ |
| 46 | + builder = ConnectedSystemsRequestBuilder() |
| 47 | + api_request = (builder.with_server_url(server_addr) |
| 48 | + .with_api_root(api_root) |
| 49 | + .for_resource_type(APITerms.SYSTEMS.value) |
| 50 | + .with_resource_id(system_id) |
| 51 | + .for_resource_type(APITerms.CONTROL_STREAMS.value) |
| 52 | + .with_request_body(request_body) |
| 53 | + .build_url_from_base() |
| 54 | + .build()) |
| 55 | + resp = requests.post(api_request.url, params=api_request.body, headers=api_request.headers) |
| 56 | + return resp.json() |
| 57 | + |
| 58 | + |
| 59 | +def retrieve_control_stream_description_by_id(server_addr: HttpUrl, control_stream_id: str, |
| 60 | + api_root: str = APITerms.API.value): |
| 61 | + """ |
| 62 | + Retrieves a control stream by its id |
| 63 | + :return: |
| 64 | + """ |
| 65 | + builder = ConnectedSystemsRequestBuilder() |
| 66 | + api_request = (builder.with_server_url(server_addr) |
| 67 | + .with_api_root(api_root) |
| 68 | + .for_resource_type(APITerms.CONTROL_STREAMS.value) |
| 69 | + .with_resource_id(control_stream_id) |
| 70 | + .build_url_from_base() |
| 71 | + .build()) |
| 72 | + resp = requests.get(api_request.url, params=api_request.body, headers=api_request.headers) |
| 73 | + return resp.json() |
| 74 | + |
| 75 | + |
| 76 | +def update_control_stream_description_by_id(server_addr: HttpUrl, control_stream_id: str, request_body: dict, |
| 77 | + api_root: str = APITerms.API.value): |
| 78 | + """ |
| 79 | + Updates a control stream by its id |
| 80 | + :return: |
| 81 | + """ |
| 82 | + builder = ConnectedSystemsRequestBuilder() |
| 83 | + api_request = (builder.with_server_url(server_addr) |
| 84 | + .with_api_root(api_root) |
| 85 | + .for_resource_type(APITerms.CONTROL_STREAMS.value) |
| 86 | + .with_resource_id(control_stream_id) |
| 87 | + .with_request_body(request_body) |
| 88 | + .build_url_from_base() |
| 89 | + .build()) |
| 90 | + resp = requests.put(api_request.url, params=api_request.body, headers=api_request.headers) |
| 91 | + return resp.json() |
| 92 | + |
| 93 | + |
| 94 | +def delete_control_stream_by_id(server_addr: HttpUrl, control_stream_id: str, api_root: str = APITerms.API.value): |
| 95 | + """ |
| 96 | + Deletes a control stream by its id |
| 97 | + :return: |
| 98 | + """ |
| 99 | + builder = ConnectedSystemsRequestBuilder() |
| 100 | + api_request = (builder.with_server_url(server_addr) |
| 101 | + .with_api_root(api_root) |
| 102 | + .for_resource_type(APITerms.CONTROL_STREAMS.value) |
| 103 | + .with_resource_id(control_stream_id) |
| 104 | + .build_url_from_base() |
| 105 | + .build()) |
| 106 | + resp = requests.delete(api_request.url, params=api_request.body, headers=api_request.headers) |
| 107 | + return resp.json() |
| 108 | + |
| 109 | + |
| 110 | +def retrieve_control_stream_schema_by_id(server_addr: HttpUrl, control_stream_id: str, |
| 111 | + api_root: str = APITerms.API.value): |
| 112 | + """ |
| 113 | + Retrieves a control stream schema by its id |
| 114 | + :return: |
| 115 | + """ |
| 116 | + builder = ConnectedSystemsRequestBuilder() |
| 117 | + api_request = (builder.with_server_url(server_addr) |
| 118 | + .with_api_root(api_root) |
| 119 | + .for_resource_type(APITerms.CONTROL_STREAMS.value) |
| 120 | + .with_resource_id(control_stream_id) |
| 121 | + .for_resource_type(APITerms.SCHEMA.value) |
| 122 | + .build_url_from_base() |
| 123 | + .build()) |
| 124 | + resp = requests.get(api_request.url, params=api_request.body, headers=api_request.headers) |
| 125 | + return resp.json() |
| 126 | + |
| 127 | + |
| 128 | +def update_control_stream_schema_by_id(server_addr: HttpUrl, control_stream_id: str, request_body: dict, |
| 129 | + api_root: str = APITerms.API.value): |
| 130 | + """ |
| 131 | + Updates a control stream schema by its id |
| 132 | + :return: |
| 133 | + """ |
| 134 | + builder = ConnectedSystemsRequestBuilder() |
| 135 | + api_request = (builder.with_server_url(server_addr) |
| 136 | + .with_api_root(api_root) |
| 137 | + .for_resource_type(APITerms.CONTROL_STREAMS.value) |
| 138 | + .with_resource_id(control_stream_id) |
| 139 | + .for_resource_type(APITerms.SCHEMA.value) |
| 140 | + .with_request_body(request_body) |
| 141 | + .build_url_from_base() |
| 142 | + .build()) |
| 143 | + resp = requests.put(api_request.url, params=api_request.body, headers=api_request.headers) |
| 144 | + return resp.json() |
0 commit comments