Source code for maptekblastlogic.api.loading_trucks.update_loading_truck

from http import HTTPStatus
from typing import Any, cast
from urllib.parse import quote

import httpx

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.error_model import ErrorModel
from ...models.loading_truck_model import LoadingTruckModel
from ...types import Response


def _get_kwargs(
    site_code: str,
    loading_truck_id: int,
    *,
    body: LoadingTruckModel,
    if_match: str,
) -> dict[str, Any]:
    headers: dict[str, Any] = {}
    headers["If-Match"] = if_match

    _kwargs: dict[str, Any] = {
        "method": "put",
        "url": "/site/{site_code}/truck/{loading_truck_id}".format(
            site_code=quote(str(site_code), safe=""),
            loading_truck_id=quote(str(loading_truck_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) -> Any | ErrorModel | None:
    if response.status_code == 204:
        response_204 = cast(Any, None)
        return response_204

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

        return response_400

    if response.status_code == 401:
        response_401 = ErrorModel.from_dict(response.json())

        return response_401

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

        return response_403

    if response.status_code == 404:
        response_404 = ErrorModel.from_dict(response.json())

        return response_404

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

        return response_409

    if response.status_code == 412:
        response_412 = ErrorModel.from_dict(response.json())

        return response_412

    if response.status_code == 503:
        response_503 = ErrorModel.from_dict(response.json())

        return response_503

    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[Any | ErrorModel]:
    return Response(
        status_code=HTTPStatus(response.status_code),
        content=response.content,
        headers=response.headers,
        parsed=_parse_response(client=client, response=response),
    )


[docs] def sync_detailed( site_code: str, loading_truck_id: int, *, client: AuthenticatedClient, body: LoadingTruckModel, if_match: str, ) -> Response[Any | ErrorModel]: """Update an existing loading truck. Requires permissions: Edit Site Resources Args: site_code (str): loading_truck_id (int): if_match (str): body (LoadingTruckModel): A truck used to load blast products into holes. 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[Any | ErrorModel] """ kwargs = _get_kwargs( site_code=site_code, loading_truck_id=loading_truck_id, body=body, if_match=if_match, ) response = client.get_httpx_client().request( **kwargs, ) return _build_response(client=client, response=response)
[docs] def sync( site_code: str, loading_truck_id: int, *, client: AuthenticatedClient, body: LoadingTruckModel, if_match: str, ) -> Any | ErrorModel | None: """Update an existing loading truck. Requires permissions: Edit Site Resources Args: site_code (str): loading_truck_id (int): if_match (str): body (LoadingTruckModel): A truck used to load blast products into holes. 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: Any | ErrorModel """ return sync_detailed( site_code=site_code, loading_truck_id=loading_truck_id, client=client, body=body, if_match=if_match, ).parsed
[docs] async def asyncio_detailed( site_code: str, loading_truck_id: int, *, client: AuthenticatedClient, body: LoadingTruckModel, if_match: str, ) -> Response[Any | ErrorModel]: """Update an existing loading truck. Requires permissions: Edit Site Resources Args: site_code (str): loading_truck_id (int): if_match (str): body (LoadingTruckModel): A truck used to load blast products into holes. 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[Any | ErrorModel] """ kwargs = _get_kwargs( site_code=site_code, loading_truck_id=loading_truck_id, body=body, if_match=if_match, ) response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response)
[docs] async def asyncio( site_code: str, loading_truck_id: int, *, client: AuthenticatedClient, body: LoadingTruckModel, if_match: str, ) -> Any | ErrorModel | None: """Update an existing loading truck. Requires permissions: Edit Site Resources Args: site_code (str): loading_truck_id (int): if_match (str): body (LoadingTruckModel): A truck used to load blast products into holes. 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: Any | ErrorModel """ return ( await asyncio_detailed( site_code=site_code, loading_truck_id=loading_truck_id, client=client, body=body, if_match=if_match, ) ).parsed