https://github.com/ircykk/allegro-api
A simple Allegro API client library.
https://github.com/ircykk/allegro-api
allegro allegro-api httplug php rest soap
Last synced: 29 days ago
JSON representation
A simple Allegro API client library.
- Host: GitHub
- URL: https://github.com/ircykk/allegro-api
- Owner: ircykk
- License: mit
- Created: 2018-04-24T13:41:06.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-12-21T13:34:21.000Z (about 1 year ago)
- Last Synced: 2025-11-27T15:12:48.628Z (3 months ago)
- Topics: allegro, allegro-api, httplug, php, rest, soap
- Language: PHP
- Homepage:
- Size: 212 KB
- Stars: 11
- Watchers: 4
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Allegro API
Allegro API client library, written with PHP.
## Requirements
* PHP >= 5.6 || PHP >= 7.0
* HTTP client
## Features
* REST and SOAP WebApi
* Sandbox support
* Auto-complete
* PSR compatible
## Installation
Via Composer:
```bash
composer require ircykk/allegro-api
```
Library is build on top of [HTTPlug](http://httplug.io/), we need to install HTTP client.
```bash
composer require php-http/guzzle6-adapter "^1.1"
```
## Developer Documentation
https://developer.allegro.pl/documentation/
## Usage of client
### Authentication with OAuth
```php
getAuthUrl());
} else {
$token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
// Store access token...
}
```
We have `$token->access_token` for authenticate all our future requests.
See [example](examples/authentication.php).
#### Client credentials flow
In order to access to public available resources such as categories or offers use client credentials flow:
```php
$token = $client->fetchAccessTokenWithClientCredentials();
```
#### Device flow
To use browserless device flow use `getAuthUserCode()` method to get `user_code` and verification uri:
```php
$code = $client->getAuthUserCode();
```
and then after user authenticate device you can fetch `acces_token`:
```php
$code = ...
$token = $client->fetchAccessTokenWithDeviceCode($code->device_code);
```
### Making Requests
```php
authenticate($token);
$categories = $client->sale()->categories()->all();
```
### Making SOAP Requests
```php
$credentials = ...
// WebApi SOAP client
$soapClient = new \Ircykk\AllegroApi\WebapiClient($credentials);
$categories = $soapClient->webApi()->getCatsDataLimit(0, 10);
```
### Sandbox
In order to use [Sandbox environment](https://allegro.pl.allegrosandbox.pl/) just set `Credentials` property `$sandbox` to true.
```php
$credentials = new \Ircykk\AllegroApi\Credentials(
...
true // Sandbox
);
```
### Cache usage
Use any PSR-6 compatible library to cache requests.
In this example we use Symfony Cache, to install just run:
```bash
$ composer require symfony/cache
```
```php
$credentials = ...
$client = new Client($credentials);
$cache = new FilesystemAdapter();
$client->addCache($cache, ['default_ttl' => 3600]);
```
See [example](examples/cache.php).
### Logger
Use any PSR-3 logger library for example Monolog, to install just run:
```bash
$ composer require monolog/monolog
```
```php
$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](examples/log.php).
### Customization
Thanks to HTTPlug library can be customized easily, for example to set language use [HeaderDefaultsPlugin](http://docs.php-http.org/en/latest/plugins/headers.html) plugin:
```php
...
$headerDefaultsPlugin = new HeaderDefaultsPlugin([
'Accept-Language' => 'en-US'
]);
$client->addPlugin($headerDefaultsPlugin);
```
See [full list](http://docs.php-http.org/en/latest/plugins/index.html) of available HTTPlug plugins.
## TO-DO
* Tests
* Documentation
## Contributing
Feel free to contribute.
## Credits
API client build on top of [HTTPlug](http://httplug.io/) and inspired by [KnpLabs](https://github.com/KnpLabs/) GitHub client.
Soap types generated by [wsdl2phpgenerator](https://github.com/wsdl2phpgenerator/wsdl2phpgenerator) library.