2022-06-16 12:02:16 -07:00
from typing import Any , Dict , Optional , Union , cast
import httpx
from . . . client import Client
2022-07-25 22:46:48 +00:00
from . . . models . unit_magnetic_field_strength_conversion import UnitMagneticFieldStrengthConversion
2022-06-16 12:02:16 -07:00
from . . . models . error import Error
2022-07-25 22:46:48 +00:00
from . . . models . unit_magnetic_field_strength_format import UnitMagneticFieldStrengthFormat
from . . . models . unit_magnetic_field_strength_format import UnitMagneticFieldStrengthFormat
2022-06-16 12:02:16 -07:00
from . . . types import Response
def _get_kwargs (
2022-07-25 22:46:48 +00:00
output_format : UnitMagneticFieldStrengthFormat ,
src_format : UnitMagneticFieldStrengthFormat ,
2022-06-16 12:02:16 -07:00
value : float ,
* ,
client : Client ,
) - > Dict [ str , Any ] :
2022-07-25 22:46:48 +00:00
url = " {} /unit/conversion/magnetic-field-strength/ {src_format} / {output_format} ?value= {value} " . format ( client . base_url , output_format = output_format , src_format = src_format , value = value )
2022-06-16 12:02:16 -07:00
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 ( ) ,
}
2022-07-25 22:46:48 +00:00
def _parse_response ( * , response : httpx . Response ) - > Optional [ Union [ Any , UnitMagneticFieldStrengthConversion , Error ] ] :
if response . status_code == 200 :
response_200 = UnitMagneticFieldStrengthConversion . from_dict ( response . json ( ) )
return response_200
2022-06-16 12:02:16 -07:00
if response . status_code == 400 :
response_4XX = Error . from_dict ( response . json ( ) )
return response_4XX
if response . status_code == 500 :
response_5XX = Error . from_dict ( response . json ( ) )
return response_5XX
return None
2022-07-25 22:46:48 +00:00
def _build_response ( * , response : httpx . Response ) - > Response [ Union [ Any , UnitMagneticFieldStrengthConversion , Error ] ] :
2022-06-16 12:02:16 -07:00
return Response (
status_code = response . status_code ,
content = response . content ,
headers = response . headers ,
parsed = _parse_response ( response = response ) ,
)
def sync_detailed (
2022-07-25 22:46:48 +00:00
output_format : UnitMagneticFieldStrengthFormat ,
src_format : UnitMagneticFieldStrengthFormat ,
2022-06-16 12:02:16 -07:00
value : float ,
* ,
client : Client ,
2022-07-25 22:46:48 +00:00
) - > Response [ Union [ Any , UnitMagneticFieldStrengthConversion , Error ] ] :
2022-06-16 12:02:16 -07:00
kwargs = _get_kwargs (
output_format = output_format ,
src_format = src_format ,
value = value ,
client = client ,
)
2022-07-25 22:46:48 +00:00
response = httpx . get (
2022-06-16 12:02:16 -07:00
verify = client . verify_ssl ,
* * kwargs ,
)
return _build_response ( response = response )
def sync (
2022-07-25 22:46:48 +00:00
output_format : UnitMagneticFieldStrengthFormat ,
src_format : UnitMagneticFieldStrengthFormat ,
2022-06-16 12:02:16 -07:00
value : float ,
* ,
client : Client ,
2022-07-25 22:46:48 +00:00
) - > Optional [ Union [ Any , UnitMagneticFieldStrengthConversion , Error ] ] :
2022-07-26 00:49:02 +00:00
""" Convert a magnetic field strength unit value to another magnetic field strength unit value. This is a nice endpoint to use for helper functions. """
2022-06-16 12:02:16 -07:00
return sync_detailed (
output_format = output_format ,
src_format = src_format ,
value = value ,
client = client ,
) . parsed
async def asyncio_detailed (
2022-07-25 22:46:48 +00:00
output_format : UnitMagneticFieldStrengthFormat ,
src_format : UnitMagneticFieldStrengthFormat ,
2022-06-16 12:02:16 -07:00
value : float ,
* ,
client : Client ,
2022-07-25 22:46:48 +00:00
) - > Response [ Union [ Any , UnitMagneticFieldStrengthConversion , Error ] ] :
2022-06-16 12:02:16 -07:00
kwargs = _get_kwargs (
output_format = output_format ,
src_format = src_format ,
value = value ,
client = client ,
)
async with httpx . AsyncClient ( verify = client . verify_ssl ) as _client :
2022-07-25 22:46:48 +00:00
response = await _client . get ( * * kwargs )
2022-06-16 12:02:16 -07:00
return _build_response ( response = response )
async def asyncio (
2022-07-25 22:46:48 +00:00
output_format : UnitMagneticFieldStrengthFormat ,
src_format : UnitMagneticFieldStrengthFormat ,
2022-06-16 12:02:16 -07:00
value : float ,
* ,
client : Client ,
2022-07-25 22:46:48 +00:00
) - > Optional [ Union [ Any , UnitMagneticFieldStrengthConversion , Error ] ] :
2022-07-26 00:49:02 +00:00
""" Convert a magnetic field strength unit value to another magnetic field strength unit value. This is a nice endpoint to use for helper functions. """
2022-06-16 12:02:16 -07:00
return (
await asyncio_detailed (
output_format = output_format ,
src_format = src_format ,
value = value ,
client = client ,
)
) . parsed