Skip to content

Commit

Permalink
Merge pull request #31 from picqer/reset-raw-headers-before-request
Browse files Browse the repository at this point in the history
Flush response headers
  • Loading branch information
kleiram authored Mar 9, 2021
2 parents 93f1d11 + 2d00def commit 84ee617
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ public function addProductPart($idproduct, $params)
public function updateProductPartAmount($idproduct, $idproductpart, $amount)
{
$params = ['amount' => $amount];

return $this->sendRequest('/products/' . $idproduct . '/parts/'.$idproductpart, $params, self::METHOD_PUT);
}

Expand Down Expand Up @@ -497,7 +497,7 @@ public function getSuppliers($filters = [])
{
return $this->sendRequest('/suppliers', null, null, $filters);
}

public function getAllSuppliers($filters = [])
{
return $this->getAllResults('supplier', $filters);
Expand Down Expand Up @@ -699,7 +699,7 @@ public function getTags($filters = [])
{
return $this->sendRequest('/tags', [], self::METHOD_GET, $filters);
}

public function getAllTags($filters = [])
{
return $this->getAllResults('tag', $filters);
Expand Down Expand Up @@ -763,7 +763,7 @@ public function processBackorders()
{
return $this->sendRequest('/backorders/process', null, self::METHOD_POST);
}

public function deleteBackorder($idbackorder)
{
return $this->sendRequest('/backorders/' . $idbackorder, null, self::METHOD_DELETE);
Expand Down Expand Up @@ -807,7 +807,7 @@ public function getShippingProviders()
{
return $this->sendRequest('/shippingproviders');
}

/*
* Product fields
*/
Expand All @@ -820,7 +820,7 @@ public function getProductField($idproductfield)
{
return $this->sendRequest('/productfields/' . $idproductfield);
}

/*
* Order fields
*/
Expand All @@ -833,7 +833,7 @@ public function getOrderField($idorderfield)
{
return $this->sendRequest('/orderfields/' . $idorderfield);
}

/*
* Customer fields
*/
Expand Down Expand Up @@ -953,7 +953,7 @@ public function getAllResults($entity, $filters = [])

return ['success' => true, 'data' => $collection];
}

/*
* Yield all results from the API
*/
Expand Down Expand Up @@ -1051,6 +1051,7 @@ public function enableRetryOnRateLimitHit()
public function sendRequest($endpoint, $params = [], $method = self::METHOD_GET, $filters = [])
{
$endpoint = $this->getEndpoint($endpoint, $filters);

$this->debug('URL: ' . $this->getUrl($endpoint));

$curlSession = curl_init();
Expand Down Expand Up @@ -1081,6 +1082,7 @@ public function sendRequest($endpoint, $params = [], $method = self::METHOD_GET,

$apiResultJson = json_decode($apiResult, true);
$apiResultHeaders = $this->parseRawHeaders();
$this->resetRawHeaders();

$result = [];
$result['success'] = false;
Expand Down Expand Up @@ -1171,6 +1173,11 @@ protected function parseRawHeaders()
return $parsedHeaders;
}

protected function resetRawHeaders()
{
$this->rawResponseHeaders = [];
}

protected function getRemainingRateLimit(array $apiResultHeaders)
{
return (array_key_exists('x-ratelimit-remaining', $apiResultHeaders)) ? $apiResultHeaders['x-ratelimit-remaining'] : null;
Expand Down

0 comments on commit 84ee617

Please sign in to comment.