11import abc
22
3- from typing import List , Union
3+ from typing import List , Union , Optional
44
55from algoliasearch .exceptions import RequestException
66from algoliasearch .helpers import get_items , sleep_for
@@ -21,8 +21,8 @@ class Response(object):
2121 __metaclass__ = abc .ABCMeta
2222
2323 @abc .abstractmethod
24- def wait (self ):
25- # type:( ) -> Response
24+ def wait (self , request_options = None ):
25+ # type: (Optional[Union[RequestOptions, dict]] ) -> Response
2626
2727 pass # pragma: no cover
2828
@@ -36,12 +36,15 @@ def __init__(self, index, raw_responses):
3636 self .raw_responses = raw_responses
3737 self .waited = False
3838
39- def wait (self ):
40- # type: () -> IndexingResponse
39+ def wait (self , request_options = None ):
40+ # type: (Optional[Union[RequestOptions, dict]] ) -> IndexingResponse
4141
4242 if not self .waited :
4343 for raw_response in self .raw_responses :
44- self ._index ._sync ().wait_task (raw_response ['taskID' ])
44+ self ._index ._sync ().wait_task (
45+ raw_response ['taskID' ],
46+ request_options
47+ )
4548
4649 # No longer waits on this responses.
4750 self .waited = True
@@ -69,11 +72,11 @@ def push(self, response):
6972
7073 self ._waitable .append (response )
7174
72- def wait (self ):
73- # type: () -> MultipleResponse
75+ def wait (self , request_options = None ):
76+ # type: (Optional[Union[RequestOptions, dict]]) -> MultipleResponse
7477
7578 for response in self ._waitable :
76- response .wait ()
79+ response .wait (request_options )
7780
7881 # No longer waits on this responses.
7982 self ._waitable = []
@@ -95,14 +98,17 @@ def __init__(self, client, raw_response):
9598 self ._client = client
9699 self ._done = False
97100
98- def wait (self ):
99- # type: () -> AddApiKeyResponse
101+ def wait (self , request_options = None ):
102+ # type: (Optional[Union[RequestOptions, dict]] ) -> AddApiKeyResponse
100103
101104 retries_count = 1
102105
103106 while not self ._done :
104107 try :
105- self ._client ._sync ().get_api_key (self .raw_response ['key' ])
108+ self ._client ._sync ().get_api_key (
109+ self .raw_response ['key' ],
110+ request_options
111+ )
106112 self ._done = True
107113 except RequestException as e :
108114 if e .status_code != 404 :
@@ -131,15 +137,15 @@ def __init__(self, client, raw_response, request_options):
131137 self ._request_options = request_options
132138 self ._done = False
133139
134- def wait (self ):
135- # type: () -> UpdateApiKeyResponse
140+ def wait (self , request_options = None ):
141+ # type: (Optional[Union[RequestOptions, dict]] ) -> UpdateApiKeyResponse
136142
137143 retries_count = 1
138144
139145 while not self ._done :
140146 api_key = self ._client ._sync ().get_api_key (
141147 self .raw_response ['key' ],
142- self . _request_options
148+ request_options
143149 )
144150
145151 self ._done = self ._have_changed (api_key )
@@ -187,14 +193,17 @@ def __init__(self, client, raw_response, key):
187193 self ._key = key
188194 self ._done = False
189195
190- def wait (self ):
191- # type: () -> DeleteApiKeyResponse
196+ def wait (self , request_options = None ):
197+ # type: (Optional[Union[RequestOptions, dict]] ) -> DeleteApiKeyResponse
192198
193199 retries_count = 1
194200
195201 while not self ._done :
196202 try :
197- self ._client ._sync ().get_api_key (self ._key )
203+ self ._client ._sync ().get_api_key (
204+ self ._key ,
205+ request_options
206+ )
198207 except RequestException as e :
199208 self ._done = e .status_code == 404
200209
@@ -223,14 +232,17 @@ def __init__(self, client, raw_response, key):
223232 self ._key = key
224233 self ._done = False
225234
226- def wait (self ):
227- # type: () -> RestoreApiKeyResponse
235+ def wait (self , request_options = None ):
236+ # type: (Optional[Union[RequestOptions, dict]] ) -> RestoreApiKeyResponse # noqa: E501
228237
229238 retries_count = 1
230239
231240 while not self ._done :
232241 try :
233- self ._client ._sync ().get_api_key (self ._key )
242+ self ._client ._sync ().get_api_key (
243+ self ._key ,
244+ request_options
245+ )
234246 self ._done = True
235247 except RequestException as e :
236248 if e .status_code != 404 :
@@ -258,12 +270,16 @@ def __init__(self, client, raw_response):
258270 self ._client = client
259271 self ._done = False
260272
261- def wait (self ):
262- # type: () -> MultipleIndexBatchIndexingResponse
273+ def wait (self , request_options = None ):
274+ # type: (Optional[Union[RequestOptions, dict]] ) -> MultipleIndexBatchIndexingResponse # noqa: E501
263275
264276 while not self ._done :
265277 for index_name , task_id in get_items (self .raw_response ['taskID' ]):
266- self ._client ._sync ().wait_task (index_name , task_id )
278+ self ._client ._sync ().wait_task (
279+ index_name ,
280+ task_id ,
281+ request_options
282+ )
267283 self ._done = True
268284
269285 return self
0 commit comments