Skip to content

Commit b557c76

Browse files
Merge pull request #79 from michaeljdennis/refactor-make-request-method
Refactor makeRequest method
2 parents 0d23d92 + d350c2a commit b557c76

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

lib/Client.php

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -258,25 +258,14 @@ public function makeRequest($method, $url, $body = null, $headers = null, $retry
258258
$curlOpts = $this->createCurlOptions($method, $body, $headers);
259259
curl_setopt_array($curl, $curlOpts);
260260

261-
$response = curl_exec($curl);
262-
$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
263-
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
261+
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->headers);
264262

265-
$responseBody = substr($response, $headerSize);
266-
$responseHeaders = substr($response, 0, $headerSize);
267-
268-
$responseHeaders = explode("\n", $responseHeaders);
269-
$responseHeaders = array_map('trim', $responseHeaders);
263+
$response = $this->prepareResponse($curl);
270264

271265
curl_close($curl);
272-
273-
$response = new Response($statusCode, $responseBody, $responseHeaders);
274266

275-
if ($statusCode === 429 && $retryOnLimit) {
276-
$headers = $response->headers(true);
277-
$sleepDurations = $headers['X-Ratelimit-Reset'] - time();
278-
sleep($sleepDurations > 0 ? $sleepDurations : 0);
279-
return $this->makeRequest($method, $url, $body, $headers, false);
267+
if ($response->statusCode() == 429 && $retryOnLimit) {
268+
return $this->retryRequest($response->headers(true), $method, $url, $body, $headers);
280269
}
281270

282271
return $response;

0 commit comments

Comments
 (0)