Skip to content

Commit

Permalink
Code Quality + Documentation, change composer.json
Browse files Browse the repository at this point in the history
  • Loading branch information
repat committed Mar 22, 2021
1 parent 95cb7c8 commit 0401950
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
16 changes: 14 additions & 2 deletions 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)

Expand All @@ -8,19 +9,22 @@ 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)
* Functions return an associative array
* 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;

Expand All @@ -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);
Expand All @@ -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))
Expand All @@ -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")

Expand Down
13 changes: 8 additions & 5 deletions composer.json
Expand Up @@ -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",
Expand All @@ -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" }
Expand Down
13 changes: 9 additions & 4 deletions src/PlentymarketsRestClient/PlentymarketsRestClient.php
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0401950

Please sign in to comment.