firelike / nytimes-api
用于消耗纽约时报API的Zend Framework模块
v1.1.3
2016-12-21 00:52 UTC
Requires
- php: ^5.6 || ^7.0
- guzzlehttp/guzzle-services: ^1.0
- zendframework/zend-mvc-console: ^1.1
- zendframework/zend-servicemanager: ^3.1
Requires (Dev)
- phpunit/phpunit: ^5.7
README
简介
用于消耗纽约时报API的Zend Framework模块
安装
使用Composer在您的应用程序的vendor目录中安装该模块。将以下行添加到您的composer.json文件中。
{
"require": {
"firelike/nytimes-api": "^1.1"
}
}
配置
在您的application.config.php文件中启用该模块。
return array( 'modules' => array( 'Firelike\NYTimes' ) );
将nytimes.local.php.dist文件复制并粘贴到您的config/autoload文件夹中,并使用您的凭据和其他配置设置进行自定义。确保从您的文件中删除.dist。您的nytimes.local.php可能看起来像以下内容
<?php return [ 'nytimes_service' => [ 'api_key' => '<your-api-key>', ] ];
用法
从您的代码中调用
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);
使用控制台
php public/index.php nytimes lists -v
实现的服务方法
- bestSellerList
- bestSellerHistoryList
- bestSellerListNames
- bestSellerListOverview
- bestSellerListByDate
- reviews