forked from ircykk/allegro-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.php
43 lines (35 loc) · 959 Bytes
/
log.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* To log api requests you can use any PSR-3 logger library.
*
* In this example we use Monolog. Add this to your project with composer:
*
* composer require monolog/monolog
*/
use Ircykk\AllegroApi\Client;
use Http\Client\Common\Plugin\LoggerPlugin;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
include_once __DIR__.'/credentials.php';
include_once __DIR__.'/token.php';
$client = new Client($credentials);
/**
* Create logger instance and use HTTPlug plugin to add logger to client.
*/
$logger = new Logger('api');
$logger->pushHandler(
new StreamHandler(__DIR__.'/api.log', Logger::DEBUG)
);
$loggerPlugin = new LoggerPlugin($logger);
$client->addPlugin($loggerPlugin);
/**
* Authenticate with access token.
*/
$client->authenticate($token->access_token);
/**
* Fetch root categories.
*/
$response = $client->sale()->categories()->all();
foreach ($response->categories as $category) {
echo $category->name;
}