Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/infuse_iot/api_client/api/application/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Contains endpoint functions for accessing the API"""
194 changes: 194 additions & 0 deletions src/infuse_iot/api_client/api/application/create_application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,194 @@
from http import HTTPStatus
from typing import Any
from urllib.parse import quote
from uuid import UUID

import httpx

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.application import Application
from ...models.error import Error
from ...models.new_application import NewApplication
from ...types import Response


def _get_kwargs(
id: UUID,
*,
body: NewApplication,
) -> dict[str, Any]:
headers: dict[str, Any] = {}

_kwargs: dict[str, Any] = {
"method": "post",
"url": "/organisation/id/{id}/applications".format(
id=quote(str(id), safe=""),
),
}

_kwargs["json"] = body.to_dict()

headers["Content-Type"] = "application/json"

_kwargs["headers"] = headers
return _kwargs


def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Application | Error | None:
if response.status_code == 201:
response_201 = Application.from_dict(response.json())

return response_201

if response.status_code == 400:
response_400 = Error.from_dict(response.json())

return response_400

if response.status_code == 403:
response_403 = Error.from_dict(response.json())

return response_403

if response.status_code == 409:
response_409 = Error.from_dict(response.json())

return response_409

if response.status_code == 422:
response_422 = Error.from_dict(response.json())

return response_422

if client.raise_on_unexpected_status:
raise errors.UnexpectedStatus(response.status_code, response.content)
else:
return None


def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Application | Error]:
return Response(
status_code=HTTPStatus(response.status_code),
content=response.content,
headers=response.headers,
parsed=_parse_response(client=client, response=response),
)


def sync_detailed(
id: UUID,
*,
client: AuthenticatedClient | Client,
body: NewApplication,
) -> Response[Application | Error]:
"""Create a new application in an organisation

Args:
id (UUID):
body (NewApplication):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Application | Error]
"""

kwargs = _get_kwargs(
id=id,
body=body,
)

response = client.get_httpx_client().request(
**kwargs,
)

return _build_response(client=client, response=response)


def sync(
id: UUID,
*,
client: AuthenticatedClient | Client,
body: NewApplication,
) -> Application | Error | None:
"""Create a new application in an organisation

Args:
id (UUID):
body (NewApplication):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Application | Error
"""

return sync_detailed(
id=id,
client=client,
body=body,
).parsed


async def asyncio_detailed(
id: UUID,
*,
client: AuthenticatedClient | Client,
body: NewApplication,
) -> Response[Application | Error]:
"""Create a new application in an organisation

Args:
id (UUID):
body (NewApplication):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Response[Application | Error]
"""

kwargs = _get_kwargs(
id=id,
body=body,
)

response = await client.get_async_httpx_client().request(**kwargs)

return _build_response(client=client, response=response)


async def asyncio(
id: UUID,
*,
client: AuthenticatedClient | Client,
body: NewApplication,
) -> Application | Error | None:
"""Create a new application in an organisation

Args:
id (UUID):
body (NewApplication):

Raises:
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
httpx.TimeoutException: If the request takes longer than Client.timeout.

Returns:
Application | Error
"""

return (
await asyncio_detailed(
id=id,
client=client,
body=body,
)
).parsed
Loading
Loading