Source code for pydelfini.delfini_core.api.account.account_get_account

"""Retrieve a single account definition"""
from http import HTTPStatus
from typing import Any
from typing import Dict
from typing import Union

import httpx

from ... import errors
from ...client import AuthenticatedClient
from ...client import Client
from ...models.account import Account
from ...models.server_error import ServerError
from ...types import Response


def _get_kwargs(
    account_id: str,
) -> Dict[str, Any]:
    _kwargs: Dict[str, Any] = {
        "method": "get",
        "url": "/account/{account_id}".format(
            account_id=account_id,
        ),
    }

    return _kwargs


def _parse_response(
    *, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Union[Account, ServerError]:
    if response.status_code == HTTPStatus.OK:
        response_200 = Account.from_dict(response.json())

        return response_200
    if response.status_code == HTTPStatus.NOT_FOUND:
        response_404 = ServerError.from_dict(response.json())

        return response_404
    if response.status_code == HTTPStatus.INTERNAL_SERVER_ERROR:
        response_500 = ServerError.from_dict(response.json())

        return response_500

    raise errors.UnexpectedStatus(response.status_code, response.content)


def _build_response(
    *, client: Union[AuthenticatedClient, Client], response: httpx.Response
) -> Response[Union[Account, ServerError]]:
    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( account_id: str, *, client: AuthenticatedClient, ) -> Response[Union[Account, ServerError]]: """Retrieve a single account definition Args: account_id (str): 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[Union[Account, ServerError]] """ kwargs = _get_kwargs( account_id=account_id, ) response = client.get_httpx_client().request( **kwargs, ) return _build_response(client=client, response=response)
[docs] def sync( account_id: str, *, client: AuthenticatedClient, ) -> Union[Account]: """Retrieve a single account definition Args: account_id (str): Raises: errors.UnexpectedStatus: If the server returns a status code greater than or equal to 300. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: Union[Account] """ response = sync_detailed( account_id=account_id, client=client, ) if isinstance(response.parsed, ServerError): raise errors.UnexpectedStatus(response.status_code, response.content) return response.parsed
[docs] async def asyncio_detailed( account_id: str, *, client: AuthenticatedClient, ) -> Response[Union[Account, ServerError]]: """Retrieve a single account definition Args: account_id (str): 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[Union[Account, ServerError]] """ kwargs = _get_kwargs( account_id=account_id, ) response = await client.get_async_httpx_client().request(**kwargs) return _build_response(client=client, response=response)
[docs] async def asyncio( account_id: str, *, client: AuthenticatedClient, ) -> Union[Account]: """Retrieve a single account definition Args: account_id (str): Raises: errors.UnexpectedStatus: If the server returns a status code greater than or equal to 300. httpx.TimeoutException: If the request takes longer than Client.timeout. Returns: Union[Account] """ response = await asyncio_detailed( account_id=account_id, client=client, ) if isinstance(response.parsed, ServerError): raise errors.UnexpectedStatus(response.status_code, response.content) return response.parsed