readme update
This commit is contained in:
parent
15084614bf
commit
96ee257498
24
README.md
24
README.md
@ -6,7 +6,7 @@
|
|||||||
# AliExpress TOP API client
|
# AliExpress TOP API client
|
||||||
API client implementation for AliExpress TOP.
|
API client implementation for AliExpress TOP.
|
||||||
|
|
||||||
# Usage
|
## 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:
|
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
|
```sh
|
||||||
composer require php-http/curl-client nyholm/psr7 php-http/message retailcrm/aliexpress-top-client
|
composer require php-http/curl-client nyholm/psr7 php-http/message retailcrm/aliexpress-top-client
|
||||||
@ -18,15 +18,33 @@ Details about those third-party libraries and why you need to install them can b
|
|||||||
use RetailCrm\Component\AppData;
|
use RetailCrm\Component\AppData;
|
||||||
use RetailCrm\Builder\ClientBuilder;
|
use RetailCrm\Builder\ClientBuilder;
|
||||||
use RetailCrm\Builder\ContainerBuilder;
|
use RetailCrm\Builder\ContainerBuilder;
|
||||||
|
use RetailCrm\Component\Authenticator\TokenAuthenticator;
|
||||||
|
|
||||||
$appData = new AppData(AppData::OVERSEAS_ENDPOINT, 'appKey', 'appSecret');
|
$appData = new AppData(AppData::OVERSEAS_ENDPOINT, 'appKey', 'appSecret');
|
||||||
$client = ClientBuilder::create()
|
$client = ClientBuilder::create()
|
||||||
->setContainer(ContainerBuilder::create()->build())
|
->setContainer(ContainerBuilder::create()->build())
|
||||||
->setAppData($appData)
|
->setAppData($appData)
|
||||||
|
->setAuthenticator(new TokenAuthenticator('session token here'))
|
||||||
->build();
|
->build();
|
||||||
```
|
```
|
||||||
|
|
||||||
# Details
|
3. Create and fill request data. All requests and responses use the same naming: part of the namespace is the first word in the request name, and everything else is in the request DTO class name. Requests live under `RetailCrm\Model\Request` namespace, and responses can be found in the `RetailCrm\Model\Response` namespace.
|
||||||
|
Let's use `taobao.httpdns.get` request as an example. It's first word is the `taobao`, so, this request can be found under `RetailCrm\Model\Request\Taobao` namespace, and it's class name is `HttpDnsGetRequest`. You can instantiate it with this code:
|
||||||
|
```php
|
||||||
|
use RetailCrm\Model\Request\Taobao\HttpDnsGetRequest;
|
||||||
|
|
||||||
|
$request = new HttpDnsGetRequest();
|
||||||
|
```
|
||||||
|
4. Send request using `Client::sendRequest` or `Client::sendAuthenticatedRequest` (you can't send authenticated request using client without authenticator). `taobao.httpdns.get` can be sent like this:
|
||||||
|
```php
|
||||||
|
/** @var \RetailCrm\Model\Response\Taobao\HttpDnsGetResponse $response */
|
||||||
|
$response = $client->sendRequest(new HttpDnsGetRequest());
|
||||||
|
```
|
||||||
|
This particular request doesn't require authorization, so, it can be sent via `Client::sendRequest` method. For any other requests which require authorization you must use `Client::sendAuthenticatedRequest` method (an example of such request would be `aliexpress.solution.seller.category.tree.query`, which class FQN is `\RetailCrm\Model\Request\AliExpress\SolutionSellerCategoryTreeQuery`).
|
||||||
|
|
||||||
|
**Note:** use response type annotations. Both client methods which returns responses actually returns `ResponseInterface` (not the PSR one). Actual response type will be determined by the request model. Your IDE will not recognize any response options unless you put a proper type annotation for the response variable.
|
||||||
|
|
||||||
|
## Customization
|
||||||
This library uses Container pattern under the hood. You can pass additional dependencies using `ContainerBuilder`. For example:
|
This library uses Container pattern under the hood. You can pass additional dependencies using `ContainerBuilder`. For example:
|
||||||
```php
|
```php
|
||||||
use Http\Client\Curl\Client;
|
use Http\Client\Curl\Client;
|
||||||
@ -57,4 +75,4 @@ $client = ClientBuilder::create()
|
|||||||
```
|
```
|
||||||
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.
|
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.
|
||||||
|
|
||||||
You can use your own container - it must be compliant to PSR-11. But this is strongly discouraged because it'll be much easier to just integrate library with your own application, and your own DI system.
|
You can use your own container - it must be compliant to PSR-11. This is strongly discouraged because it'll be much easier to just integrate library with your own application, and your own DI system.
|
||||||
|
@ -15,9 +15,6 @@ namespace RetailCrm\Tests\TopClient;
|
|||||||
use Http\Message\RequestMatcher\CallbackRequestMatcher;
|
use Http\Message\RequestMatcher\CallbackRequestMatcher;
|
||||||
use Psr\Http\Message\RequestInterface;
|
use Psr\Http\Message\RequestInterface;
|
||||||
use RetailCrm\Builder\ClientBuilder;
|
use RetailCrm\Builder\ClientBuilder;
|
||||||
use RetailCrm\Component\AppData;
|
|
||||||
use RetailCrm\Component\Constants;
|
|
||||||
use RetailCrm\Component\Exception\ValidationException;
|
|
||||||
use RetailCrm\Model\Entity\CategoryInfo;
|
use RetailCrm\Model\Entity\CategoryInfo;
|
||||||
use RetailCrm\Model\Enum\FeedOperationTypes;
|
use RetailCrm\Model\Enum\FeedOperationTypes;
|
||||||
use RetailCrm\Model\Enum\FeedStatuses;
|
use RetailCrm\Model\Enum\FeedStatuses;
|
||||||
@ -34,14 +31,13 @@ use RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResp
|
|||||||
use RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList;
|
use RetailCrm\Model\Response\AliExpress\Data\SolutionSellerCategoryTreeQueryResponseDataChildrenCategoryList;
|
||||||
use RetailCrm\Model\Response\AliExpress\PostproductRedefiningCategoryForecastResponse;
|
use RetailCrm\Model\Response\AliExpress\PostproductRedefiningCategoryForecastResponse;
|
||||||
use RetailCrm\Model\Response\AliExpress\SolutionFeedListGetResponse;
|
use RetailCrm\Model\Response\AliExpress\SolutionFeedListGetResponse;
|
||||||
use RetailCrm\Model\Response\AliExpress\SolutionFeedSubmitResponse;
|
|
||||||
use RetailCrm\Model\Response\AliExpress\SolutionProductSchemaGetResponse;
|
use RetailCrm\Model\Response\AliExpress\SolutionProductSchemaGetResponse;
|
||||||
use RetailCrm\Model\Response\AliExpress\SolutionSellerCategoryTreeQueryResponse;
|
use RetailCrm\Model\Response\AliExpress\SolutionSellerCategoryTreeQueryResponse;
|
||||||
use RetailCrm\Model\Response\ErrorResponseBody;
|
use RetailCrm\Model\Response\ErrorResponseBody;
|
||||||
use RetailCrm\Model\Response\Taobao\HttpDnsGetResponse;
|
use RetailCrm\Model\Response\Taobao\HttpDnsGetResponse;
|
||||||
use RetailCrm\Test\FakeDataRequestDto;
|
use RetailCrm\Test\FakeDataRequestDto;
|
||||||
use RetailCrm\Test\TestCase;
|
|
||||||
use RetailCrm\Test\RequestMatcher;
|
use RetailCrm\Test\RequestMatcher;
|
||||||
|
use RetailCrm\Test\TestCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ClientTest
|
* Class ClientTest
|
||||||
|
Loading…
Reference in New Issue
Block a user