1
0
mirror of synced 2024-11-22 04:46:02 +03:00
aliexpress-top-client/README.md
2020-09-30 13:37:31 +03:00

3.0 KiB

AliExpress TOP API client

Build Status Covarage Latest stable PHP from Packagist

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:
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.

  1. Instantiate client like that:
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:

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.