oxy-coach / aliexpress-api-client-local
API client implementation for new AliExpress API version.
Requires
- php: >=7.3.0
- ext-curl: *
- ext-json: *
- cache/array-adapter: ^1.0
- doctrine/annotations: ^1.10
- doctrine/cache: ^1.10
- jms/serializer: ^3.9
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.12
- php-http/httplug: ^2.2
- php-http/message-factory: ^1.0
- php-http/multipart-stream-builder: ^1.1
- psr/cache: ^1.0
- psr/http-client: ^1.0
- psr/http-message: ^1.0
- psr/log: ^1.1
- symfony/expression-language: ^4.1|^5.1
- symfony/validator: ^4.1|^5.1
Requires (Dev)
- brainmaestro/composer-git-hooks: ^2.8
- dealerdirect/phpcodesniffer-composer-installer: ^0.7.0
- nyholm/psr7: ^1.3
- php-http/curl-client: ^2.1
- php-http/message: ^1.9
- php-http/mock-client: ^1.4
- phpcompatibility/php-compatibility: *
- phpmd/phpmd: ^2.9
- phpunit/phpunit: ^9.3
- squizlabs/php_codesniffer: ^3.5
- vlucas/phpdotenv: ^5.2
This package is auto-updated.
Last update: 2024-10-30 02:21:37 UTC
README
AliExpress API client for new API version
API client implementation for AliExpress local API.
Usage
- 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 via 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.
- Instantiate client using
ClientFactory
:
use Simla\Component\AppData; use Simla\Factory\ClientFactory; $client = ClientFactory::createClient( AppData::ENDPOINT, 'your jwt token' );
- Create and fill request data. All requests and responses use the same naming. Requests live under
RetailCrm\Model\Request
namespace, and responses can be found in theRetailCrm\Model\Response
namespace. For example, you can instantiate an order list request with this code:
use Simla\Model\Request\GetOrderListRequest; $request = new GetOrderListRequest();
- Send request using
Client::sendRequest
like this:
/** @var \Simla\Model\Response\GetOrderListResponse $response */ $response = $client->sendRequest(new GetOrderListRequest());
Each request uses provided jwt
token for authorization.
Friendly 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:
use Http\Client\Curl\Client; use Simla\Component\AppData; use Simla\Component\Environment; use Nyholm\Psr7\Factory\Psr17Factory; use Simla\Builder\ClientBuilder; use Simla\Builder\ContainerBuilder; use Simla\Component\Logger\StdoutLogger; $client = new Client(); $logger = new StdoutLogger(); $factory = new Psr17Factory(); $appData = new AppData(AppData::ENDPOINT, 'jwt token'); $container = ContainerBuilder::create() ->setEnv(Environment::TEST) ->setClient($client) ->setLogger($logger) ->setStreamFactory($factory) ->setRequestFactory($factory) ->setUriFactory($factory) ->build(); $client = ClientBuilder::create() ->setContainer($container) ->setAppData($appData) ->build();
Logger should implement Psr\Log\LoggerInterface
(PSR-3), HTTP client should implement Psr\Http\TopClient\TopClientInterface
(PSR-18), HTTP objects must be compliant to PSR-7.
You can use your own container if you want to - 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.
The simplest example of client initialization without using ClientFactory
looks like this:
use Simla\Component\AppData; use Simla\Builder\ClientBuilder; use Simla\Builder\ContainerBuilder; $appData = new AppData(AppData::ENDPOINT, 'jwt token'); $client = ClientBuilder::create() ->setContainer(ContainerBuilder::create()->build()) ->setAppData($appData) ->build();
In fact, ClientFactory
works just like this under the hood.