2023-05-04 00:58:06 -07:00
from typing import Any , Dict , Optional , Union
2022-06-15 18:18:19 -07:00
import httpx
from . . . client import Client
2023-05-04 00:58:06 -07:00
from . . . models . api_call_status import ApiCallStatus
2022-06-15 18:18:19 -07:00
from . . . models . async_api_call_results_page import AsyncApiCallResultsPage
from . . . models . created_at_sort_mode import CreatedAtSortMode
2023-05-04 00:58:06 -07:00
from . . . models . error import Error
2022-06-15 18:18:19 -07:00
from . . . types import Response
2023-05-04 00:58:06 -07:00
2022-06-15 18:18:19 -07:00
def _get_kwargs (
2023-05-04 00:58:06 -07:00
sort_by : CreatedAtSortMode ,
status : ApiCallStatus ,
* ,
client : Client ,
limit : Optional [ int ] = None ,
page_token : Optional [ str ] = None ,
2022-06-15 18:18:19 -07:00
) - > Dict [ str , Any ] :
2023-11-27 16:01:20 -08:00
url = " {} /async/operations " . format (
client . base_url ,
) # noqa: E501
2023-05-04 00:58:06 -07:00
if limit is not None :
2024-03-04 12:53:31 -08:00
2023-05-04 00:58:06 -07:00
if " ? " in url :
url = url + " &limit= " + str ( limit )
else :
url = url + " ?limit= " + str ( limit )
2023-11-27 16:01:20 -08:00
2023-05-04 00:58:06 -07:00
if page_token is not None :
2024-03-04 12:53:31 -08:00
2023-05-04 00:58:06 -07:00
if " ? " in url :
url = url + " &page_token= " + str ( page_token )
else :
url = url + " ?page_token= " + str ( page_token )
2023-11-27 16:01:20 -08:00
2023-05-04 00:58:06 -07:00
if sort_by is not None :
2024-03-04 12:53:31 -08:00
2023-05-04 00:58:06 -07:00
if " ? " in url :
url = url + " &sort_by= " + str ( sort_by )
else :
url = url + " ?sort_by= " + str ( sort_by )
2023-11-27 16:01:20 -08:00
2023-05-04 00:58:06 -07:00
if status is not None :
2024-03-04 12:53:31 -08:00
2023-05-04 00:58:06 -07:00
if " ? " in url :
url = url + " &status= " + str ( status )
else :
url = url + " ?status= " + str ( status )
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 ( ) ,
}
2023-11-27 16:01:20 -08:00
def _parse_response (
* , response : httpx . Response
) - > Optional [ Union [ AsyncApiCallResultsPage , Error ] ] :
if response . status_code == 200 :
2023-11-28 23:50:50 -08:00
response_200 = AsyncApiCallResultsPage ( * * response . json ( ) )
2023-11-27 16:01:20 -08:00
return response_200
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-05-04 00:58:06 -07:00
def _build_response (
* , response : httpx . Response
2023-11-27 16:01:20 -08:00
) - > Response [ Optional [ Union [ AsyncApiCallResultsPage , Error ] ] ] :
2023-05-04 00:58:06 -07:00
return Response (
status_code = response . status_code ,
content = response . content ,
headers = response . headers ,
parsed = _parse_response ( response = response ) ,
)
2022-06-15 18:18:19 -07:00
def sync_detailed (
2023-05-04 00:58:06 -07:00
sort_by : CreatedAtSortMode ,
status : ApiCallStatus ,
* ,
client : Client ,
limit : Optional [ int ] = None ,
page_token : Optional [ str ] = None ,
2023-11-27 16:01:20 -08:00
) - > Response [ Optional [ Union [ AsyncApiCallResultsPage , Error ] ] ] :
2023-05-04 00:58:06 -07:00
kwargs = _get_kwargs (
limit = limit ,
page_token = page_token ,
sort_by = sort_by ,
status = status ,
client = client ,
)
2022-06-15 18:18:19 -07:00
2023-05-04 00:58:06 -07:00
response = httpx . get (
verify = client . verify_ssl ,
* * kwargs ,
)
2022-06-15 18:18:19 -07:00
2023-05-04 00:58:06 -07:00
return _build_response ( response = response )
2022-06-15 18:18:19 -07:00
def sync (
2023-05-04 00:58:06 -07:00
sort_by : CreatedAtSortMode ,
status : ApiCallStatus ,
* ,
client : Client ,
limit : Optional [ int ] = None ,
page_token : Optional [ str ] = None ,
2023-11-27 16:01:20 -08:00
) - > Optional [ Union [ AsyncApiCallResultsPage , Error ] ] :
2023-05-04 00:58:06 -07:00
""" For async file conversion operations, this endpoint does not return the contents of converted files (`output`). To get the contents use the `/async/operations/ {id} ` endpoint.
2023-12-21 08:14:08 -08:00
This endpoint requires authentication by a Zoo employee . """ # noqa: E501
2022-06-15 18:18:19 -07:00
2023-05-04 00:58:06 -07:00
return sync_detailed (
limit = limit ,
page_token = page_token ,
sort_by = sort_by ,
status = status ,
client = client ,
) . parsed
2022-06-15 18:18:19 -07:00
async def asyncio_detailed (
2023-05-04 00:58:06 -07:00
sort_by : CreatedAtSortMode ,
status : ApiCallStatus ,
* ,
client : Client ,
limit : Optional [ int ] = None ,
page_token : Optional [ str ] = None ,
2023-11-27 16:01:20 -08:00
) - > Response [ Optional [ Union [ AsyncApiCallResultsPage , Error ] ] ] :
2023-05-04 00:58:06 -07:00
kwargs = _get_kwargs (
limit = limit ,
page_token = page_token ,
sort_by = sort_by ,
status = status ,
client = client ,
)
2022-06-15 18:18:19 -07:00
2023-05-04 00:58:06 -07:00
async with httpx . AsyncClient ( verify = client . verify_ssl ) as _client :
response = await _client . get ( * * kwargs )
2022-06-15 18:18:19 -07:00
2023-05-04 00:58:06 -07:00
return _build_response ( response = response )
2022-06-15 18:18:19 -07:00
async def asyncio (
2023-05-04 00:58:06 -07:00
sort_by : CreatedAtSortMode ,
status : ApiCallStatus ,
* ,
client : Client ,
limit : Optional [ int ] = None ,
page_token : Optional [ str ] = None ,
2023-11-27 16:01:20 -08:00
) - > Optional [ Union [ AsyncApiCallResultsPage , Error ] ] :
2023-05-04 00:58:06 -07:00
""" For async file conversion operations, this endpoint does not return the contents of converted files (`output`). To get the contents use the `/async/operations/ {id} ` endpoint.
2023-12-21 08:14:08 -08:00
This endpoint requires authentication by a Zoo employee . """ # noqa: E501
2023-05-04 00:58:06 -07:00
return (
await asyncio_detailed (
limit = limit ,
page_token = page_token ,
sort_by = sort_by ,
status = status ,
client = client ,
)
) . parsed