Source code for maptekblastlogic.api.backfilling_entries.get_backfilling_entry_by_id

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

import httpx

from ... import errors
from ...client import AuthenticatedClient, Client
from ...models.backfilling_entry_model import BackfillingEntryModel
from ...models.error_model import ErrorModel
from ...types import Response


def _get_kwargs(
    site_code: str,
    backfilling_entry_id: int,
) -> dict[str, Any]:

    _kwargs: dict[str, Any] = {
        "method": "get",
        "url": "/site/{site_code}/backfillingEntry/{backfilling_entry_id}".format(
            site_code=quote(str(site_code), safe=""),
            backfilling_entry_id=quote(str(backfilling_entry_id), safe=""),
        ),
    }

    return _kwargs


def _parse_response(
    *, client: AuthenticatedClient | Client, response: httpx.Response
) -> BackfillingEntryModel | ErrorModel | None:
    if response.status_code == 200:
        response_200 = BackfillingEntryModel.from_dict(response.json())

        return response_200

    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 == 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[BackfillingEntryModel | 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, backfilling_entry_id: int, *, client: AuthenticatedClient, ) -> Response[BackfillingEntryModel | ErrorModel]: """Get a backfilling entry. Requires permissions: View Blasts Args: site_code (str): backfilling_entry_id (int): 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[BackfillingEntryModel | ErrorModel] """ kwargs = _get_kwargs( site_code=site_code, backfilling_entry_id=backfilling_entry_id, ) response = client.get_httpx_client().request( **kwargs, ) return _build_response(client=client, response=response)
[docs] def sync( site_code: str, backfilling_entry_id: int, *, client: AuthenticatedClient, ) -> BackfillingEntryModel | ErrorModel | None: """Get a backfilling entry. Requires permissions: View Blasts Args: site_code (str): backfilling_entry_id (int): 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: BackfillingEntryModel | ErrorModel """ return sync_detailed( site_code=site_code, backfilling_entry_id=backfilling_entry_id, client=client, ).parsed
[docs] async def asyncio_detailed( site_code: str, backfilling_entry_id: int, *, client: AuthenticatedClient, ) -> Response[BackfillingEntryModel | ErrorModel]: """Get a backfilling entry. Requires permissions: View Blasts Args: site_code (str): backfilling_entry_id (int): 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[BackfillingEntryModel | ErrorModel] """ kwargs = _get_kwargs( site_code=site_code, backfilling_entry_id=backfilling_entry_id, ) response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response)
[docs] async def asyncio( site_code: str, backfilling_entry_id: int, *, client: AuthenticatedClient, ) -> BackfillingEntryModel | ErrorModel | None: """Get a backfilling entry. Requires permissions: View Blasts Args: site_code (str): backfilling_entry_id (int): 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: BackfillingEntryModel | ErrorModel """ return ( await asyncio_detailed( site_code=site_code, backfilling_entry_id=backfilling_entry_id, client=client, ) ).parsed