apiship / apidq-client-php
PHP client for ApiDQ API
Requires
- php: >=7.4.0
- ext-json: *
- doctrine/annotations: ^1.8
- league/uri: ^6.5
- php-http/cache-plugin: ^1.7
- php-http/client-common: ^2.4.0
- php-http/discovery: ^1.14.1
- php-http/logger-plugin: ^1.2
- php-http/message: ^1.12.0
- php-http/message-factory: ^v1.0.2
- psr/cache: ^1.0 || ^2.0 || ^3.0
- symfony/cache: >=v3.1.0
- symfony/property-access: ^v5.3
- symfony/property-info: ^5.3
- symfony/serializer: ^5.3
Requires (Dev)
- neur0toxine/pock: ^0.10
- php-http/curl-client: ^2.2
- phpdocumentor/reflection-docblock: ^5.3
- phpmd/phpmd: ^2.10
- phpstan/phpstan: ^0.12.99
- phpunit/phpunit: ^9.5
- squizlabs/php_codesniffer: ^3.6
- vlucas/phpdotenv: ^5.3
Suggests
- ext-curl: Most HTTP clients need ext-curl to work properly.
- php-http/client-implementation: PSR-18 compatible client should be available to use this library.
- php-http/curl-client: Simplest PSR-18 client implementation.
- symfony/http-client: One of the most popular HTTP clients. Has PSR-18 compatible adapter.
README
ApiDQ API PHP Client
This is the PHP ApiDQ API client. This library allows using of the actual API version. You can find more info in the documentation.
Installation
Follow those steps to install the library:
- Download and install Composer package manager.
- Install the library from the Packagist by executing this command:
composer require apiship/apidq-client-php:"~1.0"
Note: API client uses php-http/client-implementation
as a PSR-18, PSR-17 implementation. You can replace those
implementations during installation by installing this library with the implementation of your choice, like this:
composer require symfony/http-client guzzlehttp/psr7 apiship/apidq-client-php:"~1.0"
Usage
Firstly, you should initialize the Client. The easiest way to do this is to use the SimpleClientFactory
:
$client = \ApiDQ\Factory\SimpleClientFactory::createClient('https://api.apidq.io', 'apiKey'); $client = \ApiDQ\Factory\SimpleClientFactory::createClientWithCache('https://api.apidq.io', 'apiKey', $psrCache); $client = \ApiDQ\Factory\SimpleClientFactory::createClientWithFileCache('https://api.apidq.io', 'apiKey', sys_get_temp_dir());
The client is separated into several resource groups, all of which are accessible through the Client's public properties. You can call API methods from those groups like this:
$cleanResponse = $client->address->clean( (new \ApiDQ\Model\Service\Address\CleanRequest()) ->setQuery('Москва') ->setCountryCode('RU') );
To handle errors you must use two types of exceptions:
ApiDQ\Exception\Service\ServiceException
for the api service error.ApiDQ\Exception\Client\BuilderException
for the client builder error.