11from json import JSONDecodeError
2+ from types import TracebackType
23from typing import Dict
34from typing import List
45from typing import Optional
5- from typing import Self
66from typing import Type
77from typing import TypeVar
88
99import httpx
1010from httpx import Request
1111from httpx import Response
12+ from httpx ._types import URLTypes
1213
1314from . import endpoints
1415from . import errors
@@ -32,7 +33,7 @@ def __init__(self, customer_code: str, base_url: str = "https://api.checkedid.eu
3233 self .access_token : Optional [str ] = None
3334 self .customer_code = customer_code
3435
35- def create_client (self , base_url ) :
36+ def create_client (self , base_url : URLTypes ) -> None :
3637 self .httpx = httpx .Client (base_url = base_url , auth = self .authenticate_request )
3738
3839 def authenticate_request (self , request : Request ) -> Request :
@@ -142,27 +143,35 @@ def map_exception(self, response: Response) -> Type[errors.CheckedIDError]:
142143class ClientAsync (Client ):
143144 """for asyncio"""
144145
145- def create_client (self , base_url ) -> None :
146- self .client = httpx .AsyncClient (base_url = base_url )
146+ aclient : httpx .AsyncClient
147147
148- async def dossier (self , dossier_number : str ) -> endpoints .DossierEndpoint .response :
149- response = await self .client .get (
148+ def create_client (self , base_url : URLTypes ) -> None :
149+ self .aclient = httpx .AsyncClient (base_url = base_url )
150+
151+ async def adossier (self , dossier_number : str ) -> Optional [models .ReportResponse ]:
152+ response = await self .aclient .get (
150153 url = endpoints .DossierEndpoint .url (dossier_number = dossier_number )
151154 )
152155
153156 return self .process_response (response , endpoints .DossierEndpoint .response )
154157
155- def close (self ) -> None :
156- self .client .aclose ()
158+ async def close (self ) -> None :
159+ if self .aclient :
160+ await self .aclient .aclose ()
157161
158162 def open (self ) -> None :
159163 self .create_client (self .base_url )
160164
161- def __enter__ (self ) -> Self :
165+ async def __aenter__ (self ) -> "ClientAsync" :
162166 """Open the httpx client"""
163167 self .open ()
164168 return self
165169
166- def __exit__ (self , exc_type , exc_val , exc_tb ) -> None :
170+ async def __aexit__ (
171+ self ,
172+ exc_type : Optional [Type [BaseException ]] = None ,
173+ exc_value : Optional [BaseException ] = None ,
174+ traceback : Optional [TracebackType ] = None ,
175+ ) -> None :
167176 """Close the httpx client"""
168- self .close ()
177+ await self .close ()
0 commit comments