Skip to content

bnowak/allegro-api

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Allegro API

A simple Allegro API client library, written with PHP5.

Requirements

  • PHP >= 5.5
  • A HTTP client

Features

  • REST and SOAP WebApi
  • Sandbox support
  • Auto-complete
  • PSR compatible

Installation

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

PHP 5.x

For PHP 5.x we need to downgrade symfony/options-resolver to version 2.8:

composer require symfony/options-resolver:2.8

Developer Documentation

https://developer.allegro.pl/documentation/

Usage of client

Authentication with OAuth

<?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.

Making Requests

<?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();

Making SOAP Requests

$credentials = ...

// WebApi SOAP client
$soapClient = new \Ircykk\AllegroApi\WebapiClient($credentials);

$categories = $soapClient->webApi()->getCatsDataLimit(0, 10);

Sandbox

In order to use Sandbox environment just set Credentials property $sandbox to true.

$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:

$ composer require symfony/cache
$credentials = ...
$client = new Client($credentials);

$cache = new FilesystemAdapter();
$client->addCache($cache, ['default_ttl' => 3600]);

See example.

Logger

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.

Customization

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.

TO-DO

  • Tests
  • Documentation

Contributing

Feel free to contribute.

Credits

API client build on top of HTTPlug and inspired by KnpLabs GitHub client.

Soap types generated by wsdl2phpgenerator library.

About

A simple Allegro API client library.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%