Skip to content

Commit 30d8785

Browse files
committed
infuse_iot: api_client: regenerate client
Regenerate the cloud api client from the updated specification. Signed-off-by: Jordan Yates <jordan@embeint.com>
1 parent 0e49797 commit 30d8785

19 files changed

Lines changed: 1207 additions & 0 deletions

doc/APIClientRegen.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Regenerating the API Client
2+
3+
1. Download the latest API specification from https://api.infuse-iot.com/docs
4+
2. Delete the previous API client: `rm -r ./src/infuse-iot/api_client`
5+
3. Generate API client into the root directory: `openapi-python-client generate --path ./infuse-api.yaml`
6+
4. Move API client to desired directory: `mv infuse-api-client/infuse_api_client/ ./src/infuse_iot/api_client/`
7+
5. Move README: `mv infuse-api-client/README.md ./src/infuse_iot/api_client/`
8+
6. Remove extraneous files: `rm -r infuse-api-client`
9+
7. Manually fixup `README.md` for naming
10+
11+
Some of these steps can possibly be automated with the `openapi-python-client` `--config` parameter in the future.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
from http import HTTPStatus
2+
from typing import Any, Optional, Union, cast
3+
4+
import httpx
5+
6+
from ... import errors
7+
from ...client import AuthenticatedClient, Client
8+
from ...models.device_logger_state import DeviceLoggerState
9+
from ...types import Response
10+
11+
12+
def _get_kwargs(
13+
device_id: str,
14+
index: int,
15+
) -> dict[str, Any]:
16+
_kwargs: dict[str, Any] = {
17+
"method": "get",
18+
"url": f"/device/deviceId/{device_id}/loggerState/{index}",
19+
}
20+
21+
return _kwargs
22+
23+
24+
def _parse_response(
25+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
26+
) -> Optional[Union[Any, DeviceLoggerState]]:
27+
if response.status_code == 200:
28+
response_200 = DeviceLoggerState.from_dict(response.json())
29+
30+
return response_200
31+
if response.status_code == 404:
32+
response_404 = cast(Any, None)
33+
return response_404
34+
if client.raise_on_unexpected_status:
35+
raise errors.UnexpectedStatus(response.status_code, response.content)
36+
else:
37+
return None
38+
39+
40+
def _build_response(
41+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
42+
) -> Response[Union[Any, DeviceLoggerState]]:
43+
return Response(
44+
status_code=HTTPStatus(response.status_code),
45+
content=response.content,
46+
headers=response.headers,
47+
parsed=_parse_response(client=client, response=response),
48+
)
49+
50+
51+
def sync_detailed(
52+
device_id: str,
53+
index: int,
54+
*,
55+
client: Union[AuthenticatedClient, Client],
56+
) -> Response[Union[Any, DeviceLoggerState]]:
57+
"""Get logger state by DeviceID and index
58+
59+
Args:
60+
device_id (str):
61+
index (int):
62+
63+
Raises:
64+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
65+
httpx.TimeoutException: If the request takes longer than Client.timeout.
66+
67+
Returns:
68+
Response[Union[Any, DeviceLoggerState]]
69+
"""
70+
71+
kwargs = _get_kwargs(
72+
device_id=device_id,
73+
index=index,
74+
)
75+
76+
response = client.get_httpx_client().request(
77+
**kwargs,
78+
)
79+
80+
return _build_response(client=client, response=response)
81+
82+
83+
def sync(
84+
device_id: str,
85+
index: int,
86+
*,
87+
client: Union[AuthenticatedClient, Client],
88+
) -> Optional[Union[Any, DeviceLoggerState]]:
89+
"""Get logger state by DeviceID and index
90+
91+
Args:
92+
device_id (str):
93+
index (int):
94+
95+
Raises:
96+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
97+
httpx.TimeoutException: If the request takes longer than Client.timeout.
98+
99+
Returns:
100+
Union[Any, DeviceLoggerState]
101+
"""
102+
103+
return sync_detailed(
104+
device_id=device_id,
105+
index=index,
106+
client=client,
107+
).parsed
108+
109+
110+
async def asyncio_detailed(
111+
device_id: str,
112+
index: int,
113+
*,
114+
client: Union[AuthenticatedClient, Client],
115+
) -> Response[Union[Any, DeviceLoggerState]]:
116+
"""Get logger state by DeviceID and index
117+
118+
Args:
119+
device_id (str):
120+
index (int):
121+
122+
Raises:
123+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
124+
httpx.TimeoutException: If the request takes longer than Client.timeout.
125+
126+
Returns:
127+
Response[Union[Any, DeviceLoggerState]]
128+
"""
129+
130+
kwargs = _get_kwargs(
131+
device_id=device_id,
132+
index=index,
133+
)
134+
135+
response = await client.get_async_httpx_client().request(**kwargs)
136+
137+
return _build_response(client=client, response=response)
138+
139+
140+
async def asyncio(
141+
device_id: str,
142+
index: int,
143+
*,
144+
client: Union[AuthenticatedClient, Client],
145+
) -> Optional[Union[Any, DeviceLoggerState]]:
146+
"""Get logger state by DeviceID and index
147+
148+
Args:
149+
device_id (str):
150+
index (int):
151+
152+
Raises:
153+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
154+
httpx.TimeoutException: If the request takes longer than Client.timeout.
155+
156+
Returns:
157+
Union[Any, DeviceLoggerState]
158+
"""
159+
160+
return (
161+
await asyncio_detailed(
162+
device_id=device_id,
163+
index=index,
164+
client=client,
165+
)
166+
).parsed
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
from http import HTTPStatus
2+
from typing import Any, Optional, Union
3+
4+
import httpx
5+
6+
from ... import errors
7+
from ...client import AuthenticatedClient, Client
8+
from ...models.derive_device_key_body import DeriveDeviceKeyBody
9+
from ...models.error import Error
10+
from ...models.key import Key
11+
from ...types import Response
12+
13+
14+
def _get_kwargs(
15+
*,
16+
body: DeriveDeviceKeyBody,
17+
) -> dict[str, Any]:
18+
headers: dict[str, Any] = {}
19+
20+
_kwargs: dict[str, Any] = {
21+
"method": "post",
22+
"url": "/key/derived/device",
23+
}
24+
25+
_body = body.to_dict()
26+
27+
_kwargs["json"] = _body
28+
headers["Content-Type"] = "application/json"
29+
30+
_kwargs["headers"] = headers
31+
return _kwargs
32+
33+
34+
def _parse_response(
35+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
36+
) -> Optional[Union[Error, Key]]:
37+
if response.status_code == 200:
38+
response_200 = Key.from_dict(response.json())
39+
40+
return response_200
41+
if response.status_code == 400:
42+
response_400 = Error.from_dict(response.json())
43+
44+
return response_400
45+
if client.raise_on_unexpected_status:
46+
raise errors.UnexpectedStatus(response.status_code, response.content)
47+
else:
48+
return None
49+
50+
51+
def _build_response(
52+
*, client: Union[AuthenticatedClient, Client], response: httpx.Response
53+
) -> Response[Union[Error, Key]]:
54+
return Response(
55+
status_code=HTTPStatus(response.status_code),
56+
content=response.content,
57+
headers=response.headers,
58+
parsed=_parse_response(client=client, response=response),
59+
)
60+
61+
62+
def sync_detailed(
63+
*,
64+
client: Union[AuthenticatedClient, Client],
65+
body: DeriveDeviceKeyBody,
66+
) -> Response[Union[Error, Key]]:
67+
"""Derive a device key for encryption
68+
69+
Generate a derived key to use for device level encrpytion, if security state is provided, it will be
70+
used to derive the key, otherwise the last stored security state will be used.
71+
72+
Args:
73+
body (DeriveDeviceKeyBody):
74+
75+
Raises:
76+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
77+
httpx.TimeoutException: If the request takes longer than Client.timeout.
78+
79+
Returns:
80+
Response[Union[Error, Key]]
81+
"""
82+
83+
kwargs = _get_kwargs(
84+
body=body,
85+
)
86+
87+
response = client.get_httpx_client().request(
88+
**kwargs,
89+
)
90+
91+
return _build_response(client=client, response=response)
92+
93+
94+
def sync(
95+
*,
96+
client: Union[AuthenticatedClient, Client],
97+
body: DeriveDeviceKeyBody,
98+
) -> Optional[Union[Error, Key]]:
99+
"""Derive a device key for encryption
100+
101+
Generate a derived key to use for device level encrpytion, if security state is provided, it will be
102+
used to derive the key, otherwise the last stored security state will be used.
103+
104+
Args:
105+
body (DeriveDeviceKeyBody):
106+
107+
Raises:
108+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
109+
httpx.TimeoutException: If the request takes longer than Client.timeout.
110+
111+
Returns:
112+
Union[Error, Key]
113+
"""
114+
115+
return sync_detailed(
116+
client=client,
117+
body=body,
118+
).parsed
119+
120+
121+
async def asyncio_detailed(
122+
*,
123+
client: Union[AuthenticatedClient, Client],
124+
body: DeriveDeviceKeyBody,
125+
) -> Response[Union[Error, Key]]:
126+
"""Derive a device key for encryption
127+
128+
Generate a derived key to use for device level encrpytion, if security state is provided, it will be
129+
used to derive the key, otherwise the last stored security state will be used.
130+
131+
Args:
132+
body (DeriveDeviceKeyBody):
133+
134+
Raises:
135+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
136+
httpx.TimeoutException: If the request takes longer than Client.timeout.
137+
138+
Returns:
139+
Response[Union[Error, Key]]
140+
"""
141+
142+
kwargs = _get_kwargs(
143+
body=body,
144+
)
145+
146+
response = await client.get_async_httpx_client().request(**kwargs)
147+
148+
return _build_response(client=client, response=response)
149+
150+
151+
async def asyncio(
152+
*,
153+
client: Union[AuthenticatedClient, Client],
154+
body: DeriveDeviceKeyBody,
155+
) -> Optional[Union[Error, Key]]:
156+
"""Derive a device key for encryption
157+
158+
Generate a derived key to use for device level encrpytion, if security state is provided, it will be
159+
used to derive the key, otherwise the last stored security state will be used.
160+
161+
Args:
162+
body (DeriveDeviceKeyBody):
163+
164+
Raises:
165+
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
166+
httpx.TimeoutException: If the request takes longer than Client.timeout.
167+
168+
Returns:
169+
Union[Error, Key]
170+
"""
171+
172+
return (
173+
await asyncio_detailed(
174+
client=client,
175+
body=body,
176+
)
177+
).parsed

0 commit comments

Comments
 (0)