diff --git a/README.md b/README.md index 4162303..f8da646 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ # plentymarkets-rest-client + [![Latest Version on Packagist](https://img.shields.io/packagist/v/repat/plentymarkets-rest-client.svg?style=flat-square)](https://packagist.org/packages/repat/plentymarkets-rest-client) [![Total Downloads](https://img.shields.io/packagist/dt/repat/plentymarkets-rest-client.svg?style=flat-square)](https://packagist.org/packages/repat/plentymarkets-rest-client) @@ -8,7 +9,8 @@ I'm not in anyway affiliated with Plentymarkets, nor do I get paid for this by a You can find the Plentymarkets documentation [here](https://developers.plentymarkets.com/): -### Overview +## Overview + * Functions for the 4 HTTP verbs: GET, POST, PUT, DELETE * Automatic login and refresh if login is not valid anymore * Simple one-time configuration with PHP array (will be saved serialized in a file) @@ -16,11 +18,13 @@ You can find the Plentymarkets documentation [here](https://developers.plentymar * Handle rate limiting (thanks [hepisec](http://github.com/hepisec)) ## Installation + Available via composer on [Packagist](https://packagist.org/packages/repat/plentymarkets-rest-client): `composer require repat/plentymarkets-rest-client` ## Usage + ```php use repat\PlentymarketsRestClient\PlentymarketsRestClient; @@ -45,6 +49,7 @@ $client = new PlentymarketsRestClient($configFilePath); ``` It's possible to use the 4 HTTP verbs like this + ```php $client->get($path, $parameterArray); $client->post($path, $parameterArray); @@ -71,21 +76,27 @@ $client->singleCall("GET", $guzzleParameterArray); ``` ### Errors + * If there was an error with the call (=> guzzle throws an exception) all functions will return false * If the specified config file doesn't exist or doesn't include username/password/url, an exception will be thrown ## TODO + * Refresh without new login but refresh-token ## Dependencies + * [https://packagist.org/packages/nesbot/carbon](nesbot/carbon) for date comparison * [https://packagist.org/packages/guzzlehttp/guzzle](guzzlehttp/guzzle) for HTTP calls. * [https://packagist.org/packages/danielstjules/stringy](danielstjules/stringy) for string comparisons ## License + * see [LICENSE](https://github.com/repat/plentymarkets-rest-client/blob/master/LICENSE) file ## Changelog + +* 0.1.11 PHP 8 Support & wait in case of _short period read limit reached_ error (thx [fwehrhausen](https://github.com/repat/plentymarkets-rest-client/pull/15)) * 0.1.10 Allow dealing with Exceptions yourself by passing `true` as 3rd parameter * 0.1.9 Bugfix `isAccessTokenValid()` (thx [hochdruckspezialist](https://github.com/repat/plentymarkets-rest-client/pull/14)) * 0.1.8 Update, so Carbon 2.0 can be used (thx [stefnats](https://github.com/repat/plentymarkets-rest-client/pull/12)) @@ -99,7 +110,8 @@ $client->singleCall("GET", $guzzleParameterArray); * 0.1 initial release ## Contact -* Homepage: https://repat.de + +* Homepage: [https://repat.de](https://repat.de) * e-mail: repat@repat.de * Twitter: [@repat123](https://twitter.com/repat123 "repat123 on twitter") diff --git a/composer.json b/composer.json index 90b6e93..4f2f205 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "keywords": ["plentymarkets", "pm", "rest", "api", "client", "sdk"], "homepage": "https://github.com/repat/plentymarkets-rest-client", "license": "MIT", - "version" : "0.1.10", + "version" : "0.1.11", "authors": [ { "name": "repat", @@ -18,15 +18,18 @@ }, { "name": "daniel-mannheimer", - "email": "dm@actionmix.net", + "role": "Contributor" + }, + { + "name": "fwehrhausen", "role": "Contributor" } ], "require": { - "php": "^7.0|^8.0", - "guzzlehttp/guzzle": "^7.0.1", + "php": "^5.6 | ^7.0 | ^8.0", + "guzzlehttp/guzzle": "^6.0 | ^7.0", "nesbot/carbon": "^1.22.1 | ^2.0", - "danielstjules/stringy": "2.3.2" + "danielstjules/stringy": "^2.4 | ^3.0" }, "autoload": { "psr-4": { "repat\\PlentymarketsRestClient\\": "src/PlentymarketsRestClient" } diff --git a/src/PlentymarketsRestClient/PlentymarketsRestClient.php b/src/PlentymarketsRestClient/PlentymarketsRestClient.php index b1c2192..5e7dd24 100644 --- a/src/PlentymarketsRestClient/PlentymarketsRestClient.php +++ b/src/PlentymarketsRestClient/PlentymarketsRestClient.php @@ -16,6 +16,9 @@ class PlentymarketsRestClient const METHOD_PATCH = 'PATCH'; const METHOD_DELETE = 'DELETE'; + const WAIT_ERROR_SHORT_PERIOD_READ_LIMIT = 5; + const ERROR_SHORT_PERIOD_READ_LIMIT = 'short period read limit reached'; + const THROTTLING_PREFIX_LONG_PERIOD = 'X-Plenty-Global-Long-Period'; const THROTTLING_PREFIX_SHORT_PERIOD = 'X-Plenty-Global-Short-Period'; const THROTTLING_PREFIX_ROUTE = 'X-Plenty-Route'; @@ -87,16 +90,18 @@ public function singleCall($method, $path, $params = []) $response = $this->client->request($method, $this->config['url'] . $path, $params); } catch (\Exception $e) { - //for a better plentymarkets exception handling, sometimes the limit is not correctly - if (strpos('short period read limit reached', $e->getMessage())) { - sleep(5); + // For a better Plentymarkets exception handling. Sometimes the limit is not correct + if (s($e->getMessage())->contains(self::ERROR_SHORT_PERIOD_READ_LIMIT)) { + sleep(self::WAIT_ERROR_SHORT_PERIOD_READ_LIMIT); $this->singleCall($method, $path, $params); + // TODO possible handle recursion errors } if ($this->handleExceptions === true) { throw $e; } - return false; + + return null; } $this->throttledOnLastRequest = false;