@@ -35,6 +35,8 @@ public function __construct(private string $clientAPIKey, private string $client
35
35
// default to all scopes
36
36
$ this ->scopes = \array_flip ($ this ->validScopes );
37
37
$ this ->host = $ _SERVER ['HTTP_HOST ' ] ?? '' ;
38
+ $ this ->guzzleHandler = \GuzzleHttp \HandlerStack::create ();
39
+ $ this ->guzzleHandler ->push (\Spatie \GuzzleRateLimiterMiddleware \RateLimiterMiddleware::perSecond (4 ));
38
40
}
39
41
40
42
public function getBody () : string
@@ -49,7 +51,7 @@ public function next() : array
49
51
return [];
50
52
}
51
53
52
- $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders ()]);
54
+ $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders (), ' handler ' => $ this -> guzzleHandler , ]);
53
55
$ response = $ guzzle ->request ('GET ' , 'https://api.cc.email ' . $ this ->next );
54
56
55
57
return $ this ->process ($ response );
@@ -177,12 +179,16 @@ public function put(string $url, array $parameters, string $method = 'PUT') : ar
177
179
try
178
180
{
179
181
$ json = \json_encode ($ parameters ['body ' ], JSON_PRETTY_PRINT );
180
- $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders ([
181
- 'Connection ' => 'keep-alive ' ,
182
- 'Content-Length ' => \strlen ($ json ),
183
- 'Accept-Encoding ' => 'gzip, deflate ' ,
184
- 'Host ' => $ this ->host ,
185
- 'Accept ' => '*/* ' ]),
182
+ $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders (
183
+ [
184
+ 'Connection ' => 'keep-alive ' ,
185
+ 'Content-Length ' => \strlen ($ json ),
186
+ 'Accept-Encoding ' => 'gzip, deflate ' ,
187
+ 'Host ' => $ this ->host ,
188
+ 'Accept ' => '*/* '
189
+ ]
190
+ ),
191
+ 'handler ' => $ this ->guzzleHandler ,
186
192
'body ' => $ json , ]);
187
193
188
194
$ response = $ guzzle ->request ($ method , $ url );
@@ -202,7 +208,7 @@ public function delete(string $url) : bool
202
208
{
203
209
try
204
210
{
205
- $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders ()]);
211
+ $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders (), ' handler ' => $ this -> guzzleHandler , ]);
206
212
$ response = $ guzzle ->request ('DELETE ' , $ url );
207
213
208
214
$ this ->process ($ response );
@@ -233,7 +239,7 @@ public function get(string $url, array $parameters) : array
233
239
}
234
240
}
235
241
236
- $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders ()]);
242
+ $ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders (), ' handler ' => $ this -> guzzleHandler , ]);
237
243
$ response = $ guzzle ->request ('GET ' , $ url );
238
244
239
245
return $ this ->process ($ response );
@@ -253,6 +259,7 @@ public function post(string $url, array $parameters) : array
253
259
{
254
260
$ json = \json_encode ($ parameters ['body ' ], JSON_PRETTY_PRINT );
255
261
$ guzzle = new \GuzzleHttp \Client (['headers ' => $ this ->getHeaders (),
262
+ 'handler ' => $ this ->guzzleHandler ,
256
263
'body ' => $ json , ]);
257
264
$ response = $ guzzle ->request ('POST ' , $ url );
258
265
0 commit comments