2024-07-28 15:21:51 -07:00
from typing import Any , Dict , Optional , Union
2023-11-27 16:01:20 -08:00
import httpx
from . . . client import Client
from . . . models . error import Error
2024-08-22 14:11:23 -07:00
from . . . models . text_to_cad_iteration import TextToCadIteration
from . . . models . text_to_cad_iteration_body import TextToCadIterationBody
2023-11-27 16:01:20 -08:00
from . . . types import Response
def _get_kwargs (
2024-08-22 14:11:23 -07:00
body : TextToCadIterationBody ,
2023-11-27 16:01:20 -08:00
* ,
client : Client ,
) - > Dict [ str , Any ] :
2024-08-22 14:11:23 -07:00
url = " {} /ml/text-to-cad/iteration " . format (
2023-11-27 16:01:20 -08:00
client . base_url ,
) # noqa: E501
headers : Dict [ str , Any ] = client . get_headers ( )
cookies : Dict [ str , Any ] = client . get_cookies ( )
return {
" url " : url ,
" headers " : headers ,
" cookies " : cookies ,
" timeout " : client . get_timeout ( ) ,
2024-08-22 14:11:23 -07:00
" content " : body . model_dump_json ( ) ,
2023-11-27 16:01:20 -08:00
}
2024-08-22 14:11:23 -07:00
def _parse_response (
* , response : httpx . Response
) - > Optional [ Union [ TextToCadIteration , Error ] ] :
if response . status_code == 201 :
response_201 = TextToCadIteration ( * * response . json ( ) )
return response_201
2023-11-27 16:01:20 -08:00
if response . status_code == 400 :
2023-11-28 23:50:50 -08:00
response_4XX = Error ( * * response . json ( ) )
2023-11-27 16:01:20 -08:00
return response_4XX
if response . status_code == 500 :
2023-11-28 23:50:50 -08:00
response_5XX = Error ( * * response . json ( ) )
2023-11-27 16:01:20 -08:00
return response_5XX
2023-11-28 23:50:50 -08:00
return Error ( * * response . json ( ) )
2023-11-27 16:01:20 -08:00
def _build_response (
* , response : httpx . Response
2024-08-22 14:11:23 -07:00
) - > Response [ Optional [ Union [ TextToCadIteration , Error ] ] ] :
2023-11-27 16:01:20 -08:00
return Response (
status_code = response . status_code ,
content = response . content ,
headers = response . headers ,
parsed = _parse_response ( response = response ) ,
)
def sync_detailed (
2024-08-22 14:11:23 -07:00
body : TextToCadIterationBody ,
2023-11-27 16:01:20 -08:00
* ,
client : Client ,
2024-08-22 14:11:23 -07:00
) - > Response [ Optional [ Union [ TextToCadIteration , Error ] ] ] :
2023-11-27 16:01:20 -08:00
kwargs = _get_kwargs (
2024-08-22 14:11:23 -07:00
body = body ,
2023-11-27 16:01:20 -08:00
client = client ,
)
2024-08-22 14:11:23 -07:00
response = httpx . post (
2023-11-27 16:01:20 -08:00
verify = client . verify_ssl ,
* * kwargs ,
)
return _build_response ( response = response )
def sync (
2024-08-22 14:11:23 -07:00
body : TextToCadIterationBody ,
2023-11-27 16:01:20 -08:00
* ,
client : Client ,
2024-08-22 14:11:23 -07:00
) - > Optional [ Union [ TextToCadIteration , Error ] ] :
""" This operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/ {id} ` endpoint. """ # noqa: E501
2023-11-27 16:01:20 -08:00
return sync_detailed (
2024-08-22 14:11:23 -07:00
body = body ,
2023-11-27 16:01:20 -08:00
client = client ,
) . parsed
async def asyncio_detailed (
2024-08-22 14:11:23 -07:00
body : TextToCadIterationBody ,
2023-11-27 16:01:20 -08:00
* ,
client : Client ,
2024-08-22 14:11:23 -07:00
) - > Response [ Optional [ Union [ TextToCadIteration , Error ] ] ] :
2023-11-27 16:01:20 -08:00
kwargs = _get_kwargs (
2024-08-22 14:11:23 -07:00
body = body ,
2023-11-27 16:01:20 -08:00
client = client ,
)
async with httpx . AsyncClient ( verify = client . verify_ssl ) as _client :
2024-08-22 14:11:23 -07:00
response = await _client . post ( * * kwargs )
2023-11-27 16:01:20 -08:00
return _build_response ( response = response )
async def asyncio (
2024-08-22 14:11:23 -07:00
body : TextToCadIterationBody ,
2023-11-27 16:01:20 -08:00
* ,
client : Client ,
2024-08-22 14:11:23 -07:00
) - > Optional [ Union [ TextToCadIteration , Error ] ] :
""" This operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/ {id} ` endpoint. """ # noqa: E501
2023-11-27 16:01:20 -08:00
return (
await asyncio_detailed (
2024-08-22 14:11:23 -07:00
body = body ,
2023-11-27 16:01:20 -08:00
client = client ,
)
) . parsed