Skip to content

Commit 4325c56

Browse files
fixes to systems to enable requests to be made
1 parent d26119b commit 4325c56

24 files changed

Lines changed: 159 additions & 72 deletions

conSys/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
import part_1
2-
import part_2
1+
143 Bytes
Binary file not shown.
4.1 KB
Binary file not shown.
1.43 KB
Binary file not shown.
2.02 KB
Binary file not shown.

conSys/con_sys_api.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import requests
2-
from pydantic import BaseModel, HttpUrl
2+
from pydantic import BaseModel, HttpUrl, Field
33

44
from conSys.endpoints.endpoints import Endpoint
55
from conSys.request_bodies import RequestBody
66

77

88
class ConnectedSystemAPIRequest(BaseModel):
9-
url: HttpUrl
10-
request_body: RequestBody
11-
request_method: str = 'GET'
12-
headers: dict = None
9+
url: HttpUrl = Field(None)
10+
body: RequestBody = Field(default_factory=RequestBody)
11+
params: dict = Field(None)
12+
request_method: str = Field('GET')
13+
headers: dict = Field(None)
1314

1415
def make_request(self):
1516
match self.request_method:
1617
case 'GET':
17-
return requests.get(self.url, params=self.request_body, headers=self.headers)
18+
return requests.get(self.url, params=self.body, headers=self.headers)
1819
case 'POST':
1920
return self.post_request()
2021
case 'PUT':
@@ -26,9 +27,11 @@ def make_request(self):
2627

2728

2829
class ConnectedSystemsRequestBuilder(BaseModel):
29-
api_request: ConnectedSystemAPIRequest
30-
base_url: HttpUrl
31-
endpoint: Endpoint
30+
api_request: ConnectedSystemAPIRequest = Field(default_factory=ConnectedSystemAPIRequest)
31+
base_url: HttpUrl = None
32+
endpoint: Endpoint = Field(default_factory=Endpoint)
33+
34+
3235

3336
def with_api_url(self, url: HttpUrl):
3437
self.api_request.url = url
@@ -73,7 +76,7 @@ def with_secondary_resource_id(self, resource_id: str):
7376
return self
7477

7578
def with_request_body(self, request_body: RequestBody):
76-
self.api_request.request_body = request_body
79+
self.api_request.body = request_body
7780
return self
7881

7982
def with_request_method(self, request_method: str):
153 Bytes
Binary file not shown.
2.48 KB
Binary file not shown.

conSys/endpoints/endpoints.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
from enum import Enum
22

33
import requests
4-
import websockets
5-
from pydantic import BaseModel
4+
# import websockets
5+
from pydantic import BaseModel, Field
66

77
from conSys.constants import APITerms
88

99

1010
class Endpoint(BaseModel):
1111
api_root: str = APITerms.API.value
12-
base_resource: APITerms
13-
resource_id: str = None
14-
sub_component: APITerms = None
15-
secondary_resource_id: str = None
12+
base_resource: APITerms = Field(None)
13+
resource_id: str = Field(None)
14+
sub_component: APITerms = Field(None)
15+
secondary_resource_id: str = Field(None)
1616

1717
def create_endpoint(self):
1818
# TODO: Handle insertion of "/" in the right places
@@ -99,19 +99,19 @@ def handle_request(url, params=None, content_json=None, method='get', response_h
9999
return r
100100

101101

102-
async def handle_ws(url, params=None, json_data=None, method='get', response_handler=None):
103-
"""
104-
Handles a request to the API. Functionality is limited to receiving observations for now, but will be improved in
105-
future versions.
106-
:param url: The URL to make the request to
107-
:param params: The parameters to send with the request
108-
:param json_data: The JSON to send with the request
109-
:param method: The method to use for the request
110-
:param response_handler: callback function to handle the response msg
111-
:return: The response from the API
112-
"""
113-
114-
async with websockets.connect(url) as ws:
115-
while True:
116-
msg = await ws.recv()
117-
response_handler(msg)
102+
# async def handle_ws(url, params=None, json_data=None, method='get', response_handler=None):
103+
# """
104+
# Handles a request to the API. Functionality is limited to receiving observations for now, but will be improved in
105+
# future versions.
106+
# :param url: The URL to make the request to
107+
# :param params: The parameters to send with the request
108+
# :param json_data: The JSON to send with the request
109+
# :param method: The method to use for the request
110+
# :param response_handler: callback function to handle the response msg
111+
# :return: The response from the API
112+
# """
113+
#
114+
# async with websockets.connect(url) as ws:
115+
# while True:
116+
# msg = await ws.recv()
117+
# response_handler(msg)

conSys/part_1/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import capabilities
2-
import collections_ep
3-
import deployments
4-
import procedures
5-
import properties
6-
import sampling_features
7-
import systems
1+
# import capabilities
2+
# import collections_ep
3+
# import deployments
4+
# import procedures
5+
# import properties
6+
# import sampling_features
7+
# import systems

0 commit comments

Comments
 (0)