From 38e9b2ad110c85dff30f1e1c3ff3361aa07c6d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=B0=D0=B2=D0=B5=D0=BB?= Date: Wed, 30 Sep 2020 13:37:31 +0300 Subject: [PATCH] readme --- README.md | 60 +++++++++++++++++++++++++++++++++++ src/Builder/ClientBuilder.php | 2 -- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a7d6c5d..8583aef 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,63 @@ # AliExpress TOP API client +[![Build Status](https://img.shields.io/travis/retailcrm/aliexpress-top-client/master.svg?style=for-the-badge)](https://travis-ci.org/rretailcrm/aliexpress-top-client) +[![Covarage](https://img.shields.io/codecov/c/gh/retailcrm/aliexpress-top-client/master.svg?style=for-the-badge)](https://codecov.io/gh/rretailcrm/aliexpress-top-client) +[![Latest stable](https://img.shields.io/packagist/v/retailcrm/aliexpress-top-client.svg?style=for-the-badge)](https://packagist.org/packages/rretailcrm/aliexpress-top-client) +[![PHP from Packagist](https://img.shields.io/packagist/php-v/retailcrm/aliexpress-top-client.svg?style=for-the-badge)](https://packagist.org/packages/rretailcrm/aliexpress-top-client) API client implementation for AliExpress TOP. + +# Usage +1. This library uses `php-http/httplug` under the hood. If you don't want to bother with details, just install library and it's dependencies through Composer: +```sh +composer require php-http/curl-client nyholm/psr7 php-http/message retailcrm/aliexpress-top-client +``` +Details about those third-party libraries and why you need to install them can be found [here](http://docs.php-http.org/en/latest/httplug/users.html). + +2. Instantiate client like that: +```php +use RetailCrm\Component\AppData; +use RetailCrm\Builder\ClientBuilder; +use RetailCrm\Builder\ContainerBuilder; +use RetailCrm\Component\Authenticator\TokenAuthenticator; + +$authenticator = new TokenAuthenticator('appKey', 'token'); +$appData = new AppData(AppData::OVERSEAS_ENDPOINT, 'appKey', 'appSecret'); +$client = ClientBuilder::create() + ->setContainer(ContainerBuilder::create()->build()) + ->setAppData($appData) + ->setAuthenticator($authenticator) + ->build(); +``` + +# Details +This library uses Container pattern under the hood. You can pass additional dependencies using `ContainerBuilder`. For example: +```php +use Http\Client\Curl\Client; +use Nyholm\Psr7\Factory\Psr17Factory; +use RetailCrm\Component\AppData; +use RetailCrm\Component\Environment; +use RetailCrm\Component\Logger\StdoutLogger; +use RetailCrm\Builder\ClientBuilder; +use RetailCrm\Builder\ContainerBuilder; +use RetailCrm\Component\Authenticator\TokenAuthenticator; + +$client = new Client(); +$logger = new StdoutLogger(); +$factory = new Psr17Factory(); +$authenticator = new TokenAuthenticator('appKey', 'token'); +$appData = new AppData(AppData::OVERSEAS_ENDPOINT, 'appKey', 'appSecret'); +$container = ContainerBuilder::create() + ->setEnv(Environment::TEST) + ->setClient($client) + ->setLogger($logger) + ->setStreamFactory($factory) + ->setRequestFactory($factory) + ->setUriFactory($factory) + ->build(); +$client = ClientBuilder::create() + ->setContainer($container) + ->setAppData($appData) + ->setAuthenticator($authenticator) + ->build(); +``` +Logger should implement `Psr\Log\LoggerInterface` (PSR-3), HTTP client should implement `Psr\Http\Client\ClientInterface` (PSR-18), HTTP objects must be compliant to PSR-7. diff --git a/src/Builder/ClientBuilder.php b/src/Builder/ClientBuilder.php index 84b858c..91060f2 100644 --- a/src/Builder/ClientBuilder.php +++ b/src/Builder/ClientBuilder.php @@ -14,13 +14,11 @@ namespace RetailCrm\Builder; use RetailCrm\Component\Constants; use RetailCrm\Component\ServiceLocator; -use RetailCrm\Factory\TopRequestFactory; use RetailCrm\Interfaces\AppDataInterface; use RetailCrm\Interfaces\AuthenticatorInterface; use RetailCrm\Interfaces\BuilderInterface; use RetailCrm\Interfaces\ContainerAwareInterface; use RetailCrm\Interfaces\TopRequestFactoryInterface; -use RetailCrm\Interfaces\RequestTimestampProviderInterface; use RetailCrm\Interfaces\TopRequestProcessorInterface; use RetailCrm\TopClient\Client; use RetailCrm\Traits\ContainerAwareTrait;