Zend Framework module to consume NY Times API
Install the module using Composer into your application's vendor directory. Add the following line to your
composer.json
.
{
"require": {
"firelike/nytimes-api": "^1.1"
}
}
Enable the module in your application.config.php
file.
return array(
'modules' => array(
'Firelike\NYTimes'
)
);
Copy and paste the nytimes.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 nytimes.local.php
might look something like the following:
<?php
return [
'nytimes_service' => [
'api_key' => '<your-api-key>',
]
];
Calling from your code:
use Firelike\NYTimes\Request\AbstractRequest;
use Firelike\NYTimes\Request\Books\Lists;
use Firelike\NYTimes\Service\BooksService;
$service = new BestSellersService();
$request = new Lists();
$request->setList('hardcover-fiction')
->setSortOrder(AbstractRequest::SORT_ORDER_ASC);
$result = $this->getService()->bestSellerList($request);
$numberOfRecords = $result->toArray()['num_results];
var_dump($numberOfRecords);
$records= $result->toArray()['results];
var_dump($records);
Using the console:
php public/index.php nytimes lists -v
- bestSellerList
- bestSellerHistoryList
- bestSellerListNames
- bestSellerListOverview
- bestSellerListByDate
- reviews