2023-05-04 00:58:06 -07:00
from typing import Any , Dict , Optional , Union
2022-04-06 20:35:34 -07:00
import httpx
from . . . client import Client
from . . . models . created_at_sort_mode import CreatedAtSortMode
2023-05-04 00:58:06 -07:00
from . . . models . error import Error
from . . . models . user_results_page import UserResultsPage
2022-04-06 20:35:34 -07:00
from . . . types import Response
2023-05-04 00:58:06 -07:00
2022-04-06 20:35:34 -07:00
def _get_kwargs (
2023-05-04 00:58:06 -07:00
sort_by : CreatedAtSortMode ,
* ,
client : Client ,
limit : Optional [ int ] = None ,
page_token : Optional [ str ] = None ,
2022-04-06 20:35:34 -07:00
) - > Dict [ str , Any ] :
2023-11-27 16:01:20 -08:00
url = " {} /users " . format (
client . base_url ,
) # noqa: E501
2023-05-04 00:58:06 -07:00
if limit is not None :
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 :
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 :
if " ? " in url :
url = url + " &sort_by= " + str ( sort_by )
else :
url = url + " ?sort_by= " + str ( sort_by )
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 [ UserResultsPage , Error ] ] :
if response . status_code == 200 :
2023-11-28 23:50:50 -08:00
response_200 = UserResultsPage ( * * 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 [ UserResultsPage , 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-04-06 20:35:34 -07:00
def sync_detailed (
2023-05-04 00:58:06 -07:00
sort_by : CreatedAtSortMode ,
* ,
client : Client ,
limit : Optional [ int ] = None ,
page_token : Optional [ str ] = None ,
2023-11-27 16:01:20 -08:00
) - > Response [ Optional [ Union [ UserResultsPage , Error ] ] ] :
2023-05-04 00:58:06 -07:00
kwargs = _get_kwargs (
limit = limit ,
page_token = page_token ,
sort_by = sort_by ,
client = client ,
)
2022-04-06 20:35:34 -07:00
2023-05-04 00:58:06 -07:00
response = httpx . get (
verify = client . verify_ssl ,
* * kwargs ,
)
2022-04-06 20:35:34 -07:00
2023-05-04 00:58:06 -07:00
return _build_response ( response = response )
2022-04-06 20:35:34 -07:00
def sync (
2023-05-04 00:58:06 -07:00
sort_by : CreatedAtSortMode ,
* ,
client : Client ,
limit : Optional [ int ] = None ,
page_token : Optional [ str ] = None ,
2023-11-27 16:01:20 -08:00
) - > Optional [ Union [ UserResultsPage , Error ] ] :
2023-12-21 08:14:08 -08:00
""" This endpoint required authentication by a Zoo employee. The users are returned in order of creation, with the most recently created users first. """ # noqa: E501
2022-04-06 20:35:34 -07:00
2023-05-04 00:58:06 -07:00
return sync_detailed (
limit = limit ,
page_token = page_token ,
sort_by = sort_by ,
client = client ,
) . parsed
2022-04-06 20:35:34 -07:00
async def asyncio_detailed (
2023-05-04 00:58:06 -07:00
sort_by : CreatedAtSortMode ,
* ,
client : Client ,
limit : Optional [ int ] = None ,
page_token : Optional [ str ] = None ,
2023-11-27 16:01:20 -08:00
) - > Response [ Optional [ Union [ UserResultsPage , Error ] ] ] :
2023-05-04 00:58:06 -07:00
kwargs = _get_kwargs (
limit = limit ,
page_token = page_token ,
sort_by = sort_by ,
client = client ,
)
2022-04-06 20:35:34 -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-04-06 20:35:34 -07:00
2023-05-04 00:58:06 -07:00
return _build_response ( response = response )
2022-04-06 20:35:34 -07:00
async def asyncio (
2023-05-04 00:58:06 -07:00
sort_by : CreatedAtSortMode ,
* ,
client : Client ,
limit : Optional [ int ] = None ,
page_token : Optional [ str ] = None ,
2023-11-27 16:01:20 -08:00
) - > Optional [ Union [ UserResultsPage , Error ] ] :
2023-12-21 08:14:08 -08:00
""" This endpoint required authentication by a Zoo employee. The users are returned in order of creation, with the most recently created users first. """ # noqa: E501
2023-05-04 00:58:06 -07:00
return (
await asyncio_detailed (
limit = limit ,
page_token = page_token ,
sort_by = sort_by ,
client = client ,
)
) . parsed