Zend Framework module to consume LitRes API
Install the module using Composer into your application's vendor directory. Add the following line to your
composer.json
.
{
"require": {
"firelike/litres-api": "^1.0"
}
}
Enable the module in your application.config.php
file.
return array(
'modules' => array(
'Firelike\LitRes'
)
);
Copy and paste the litres.local.php.dist
file to your config/autoload
folder and customize it with your credentials and
other configuration settings. Make sure to remove .dist
from your file.Your litres.local.php
might look something like the following:
<?php
return [
'litres_service' => [
'log'=>[
'enable'=>false,
'message_formats'=>[
'{method} {uri} HTTP/{version} {req_body}',
'RESPONSE: {code} - {res_body}',
],
'logger'=>[
'stream' => 'php://output',
]
]
]
];
Calling from your code:
use Firelike\LitRes\Request\AbstractRequest;
use Firelike\LitRes\Request\Browser as BrowserRequest;
use Firelike\LitRes\Service\LitResService;
$request = new BrowserRequest();
$request->setSearch('King')
->setLang('en')
->setLimit(25);
$service = new LitResService();
$result = $service->browser($request);
$numberOfRecords = $result->toArray()['results'];
var_dump($numberOfRecords);
$records= $result->toArray()['fb2-book'];
var_dump($records);
Using the console:
php public/index.php litres browser --search=King -v
- browser
- genres
- persons