66import json
77from typing import Dict , Any , Optional
88
9- from ..errors import DeepgramApiError , DeepgramUnknownApiError
9+ from ..options import DeepgramClientOptions
10+ from .errors import DeepgramError , DeepgramApiError , DeepgramUnknownApiError
1011
1112class AbstractRestfulClient :
1213 """
@@ -28,30 +29,27 @@ class AbstractRestfulClient:
2829 DeepgramApiError: Raised for known API errors.
2930 DeepgramUnknownApiError: Raised for unknown API errors.
3031 """
31- def __init__ (self , url : Dict [str , str ], headers : Optional [Dict [str , Any ]]):
32- self .url = url
32+ def __init__ (self , config : DeepgramClientOptions ):
33+ if config is None :
34+ raise DeepgramError ("Config are required" )
35+
36+ self .config = config
3337 self .client = httpx .AsyncClient ()
34- self .headers = headers
3538
3639 async def get (self , url : str , options = None ):
37- headers = self .headers
38- return await self ._handle_request ('GET' , url , params = options , headers = headers )
40+ return await self ._handle_request ('GET' , url , params = options , headers = self .config .headers )
3941
4042 async def post (self , url : str , options = None , ** kwargs ):
41- headers = self .headers
42- return await self ._handle_request ('POST' , url , params = options , headers = headers , ** kwargs )
43+ return await self ._handle_request ('POST' , url , params = options , headers = self .config .headers , ** kwargs )
4344
4445 async def put (self , url : str , options = None , ** kwargs ):
45- headers = self .headers
46- return await self ._handle_request ('PUT' , url , params = options , headers = headers , ** kwargs )
46+ return await self ._handle_request ('PUT' , url , params = options , headers = self .config .headers , ** kwargs )
4747
4848 async def patch (self , url : str , options = None , ** kwargs ):
49- headers = self .headers
50- return await self ._handle_request ('PATCH' , url , params = options , headers = headers , ** kwargs )
49+ return await self ._handle_request ('PATCH' , url , params = options , headers = self .config .headers , ** kwargs )
5150
5251 async def delete (self , url : str ):
53- headers = self .headers
54- return await self ._handle_request ('DELETE' , url , headers = headers )
52+ return await self ._handle_request ('DELETE' , url , headers = self .config .headers )
5553
5654 async def _handle_request (self , method , url , ** kwargs ):
5755 try :
0 commit comments