Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix headers after retry due to rate limits #42

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"keywords": [
"picqer",
"api",
"php",
"wms"
],
"homepage": "https://github.com/picqer/picqer-php",
Expand Down
44 changes: 18 additions & 26 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,28 @@

namespace Picqer\Api;

/**
* Picqer PHP API Client
*
* @author Casper Bakker <[email protected]>
* @license http://creativecommons.org/licenses/MIT/ MIT
*/
class Client
{
protected $company;
protected $apiKey;
protected $password;
protected string $company;
protected string $apiKey;
protected string $password;

protected $protocol = 'https';
protected $apiHost = 'picqer.com';
protected $apiLocation = '/api';
protected $apiVersion = 'v1';
protected $userAgent = 'Picqer PHP API Client (picqer.com)';
protected string $protocol = 'https';
protected string $apiHost = 'picqer.com';
protected string $apiLocation = '/api';
protected string $apiVersion = 'v1';
protected string $userAgent = 'Picqer PHP API Client (picqer.com)';

protected $clientVersion = '0.23.0';
protected string $clientVersion = '0.23.0';

protected $debug = false;
protected $skipSslVerification = false;
protected bool $debug = false;
protected bool $skipSslVerification = false;

protected $timeoutInSeconds = 60;
protected $waitOnRateLimit = false;
protected $sleepTimeOnRateLimitHitInSeconds = 20;
protected int $timeoutInSeconds = 60;
protected bool $waitOnRateLimit = false;
protected int $sleepTimeOnRateLimitHitInSeconds = 20;

protected $entityBaseMethodNameMap = [
protected array $entityBaseMethodNameMap = [
'product' => 'getProducts',
'picklistBatch' => 'getPicklistBatches',
'returnStatus' => 'getReturnStatuses',
Expand All @@ -40,7 +34,7 @@ class Client
const METHOD_PUT = 'PUT';
const METHOD_DELETE = 'DELETE';

protected $rawResponseHeaders;
protected array $rawResponseHeaders = [];

public function __construct($company, $apikey = '', $password = 'X')
{
Expand Down Expand Up @@ -1185,16 +1179,14 @@ public function sendRequest($endpoint, $params = [], $method = self::METHOD_GET,
curl_close($curlSession);

if ($headerInfo['http_code'] == '429') {
$result = $this->handleRateLimitReached($endpoint, $params, $method, $filters);
return $this->handleRateLimitReached($endpoint, $params, $method, $filters);
}

// API returns error
if (! in_array($headerInfo['http_code'], ['200', '201', '204'])) {
$result['error'] = true;
$result['errorcode'] = $headerInfo['http_code'];
if (isset($apiResult)) {
$result['errormessage'] = $apiResult;
}
$result['errormessage'] = $apiResult;

return $result;
}
Expand Down