A simple Allegro API client library, written with PHP5.
- PHP >= 5.5
- A HTTP client
- REST and SOAP WebApi
- Sandbox support
- Auto-complete
- PSR compatible
Via Composer:
composer require ircykk/allegro-api
Library is build on top of HTTPlug, we need to install HTTP client.
composer require php-http/guzzle6-adapter
For PHP 5.x we need to downgrade symfony/options-resolver
to version 2.8
:
composer require symfony/options-resolver:2.8
https://developer.allegro.pl/documentation/
<?php
// Composer autoload
require_once __DIR__.'/vendor/autoload.php';
$credentials = ...
$client = new \Ircykk\AllegroApi\Client($credentials);
// Redirect to allegro for authenticate and get back with code
if (!isset($_GET['code'])) {
header('Location: '.$client->getAuthUrl());
} else {
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
// Store access token...
}
We have $token->access_token
for authenticate all our future requests.
See example.
<?php
// Composer autoload
require_once __DIR__.'/vendor/autoload.php';
$credentials = ...
$token = ...
$client = new \Ircykk\AllegroApi\Client($credentials);
$client->authenticate($token);
$categories = $client->sale()->categories()->all();
$credentials = ...
// WebApi SOAP client
$soapClient = new \Ircykk\AllegroApi\WebapiClient($credentials);
$categories = $soapClient->webApi()->getCatsDataLimit(0, 10);
In order to use Sandbox environment just set Credentials
property $sandbox
to true.
$credentials = new \Ircykk\AllegroApi\Credentials(
...
true // Sandbox
);
Use any PSR-6 compatible library to cache requests.
In this example we use Symfony Cache, to install just run:
$ composer require symfony/cache
$credentials = ...
$client = new Client($credentials);
$cache = new FilesystemAdapter();
$client->addCache($cache, ['default_ttl' => 3600]);
See example.
Use any PSR-3 logger library for example Monolog, to install just run:
$ composer require monolog/monolog
$credentials = ...
$client = new Client($credentials);
$logger = new Logger('api');
$logger->pushHandler(
new StreamHandler(__DIR__.'/api.log', Logger::DEBUG)
);
$loggerPlugin = new LoggerPlugin($logger);
$client->addPlugin($loggerPlugin);
See example.
Thanks to HTTPlug library can be customized easily, for example to set language use HeaderDefaultsPlugin plugin:
...
$headerDefaultsPlugin = new HeaderDefaultsPlugin([
'Accept-Language' => 'en-US'
]);
$client->addPlugin($headerDefaultsPlugin);
See full list of available HTTPlug plugins.
- Tests
- Documentation
Feel free to contribute.
API client build on top of HTTPlug and inspired by KnpLabs GitHub client.
Soap types generated by wsdl2phpgenerator library.