@@ -134,10 +134,11 @@ private function buildUrl($queryParams = null)
134
134
* @param string $url the final url to call
135
135
* @param array $body request body
136
136
* @param array $headers any additional request headers
137
+ * @param bool $retryOnLimit should retry if rate limit is reach?
137
138
*
138
139
* @return Response object
139
140
*/
140
- public function makeRequest ($ method , $ url , $ body = null , $ headers = null )
141
+ public function makeRequest ($ method , $ url , $ body = null , $ headers = null , $ retryOnLimit = true )
141
142
{
142
143
$ curl = curl_init ($ url );
143
144
@@ -169,8 +170,17 @@ public function makeRequest($method, $url, $body = null, $headers = null)
169
170
$ responseHeaders = array_map ('trim ' , $ responseHeaders );
170
171
171
172
curl_close ($ curl );
173
+
174
+ $ response = new Response ($ statusCode , $ responseBody , $ responseHeaders );
175
+
176
+ if ($ statusCode == 429 && $ retryOnLimit ) {
177
+ $ headers = $ response ->headers (true );
178
+ $ sleepDurations = $ headers ['X-Ratelimit-Reset ' ] - time ();
179
+ sleep ($ sleepDurations > 0 ? $ sleepDurations : 0 );
180
+ return $ this ->makeRequest ($ method , $ url , $ body , $ headers , false );
181
+ }
172
182
173
- return new Response ( $ statusCode , $ responseBody , $ responseHeaders ) ;
183
+ return $ response ;
174
184
}
175
185
176
186
/**
0 commit comments