vinelab / itunes
iTunes Store 搜索 API 库
v1.0.4
2014-08-19 09:30 UTC
Requires
- php: >=5.4.0
- illuminate/cache: 4.*
- illuminate/config: 4.*
- illuminate/support: 4.*
- vinelab/http: 1.*
Requires (Dev)
- mockery/mockery: dev-master
- phpunit/phpunit: 4.2.*
README
iTunes
一个简单但功能全面的具有缓存功能的 iTunes API 客户端。
安装
Composer
"vinelab/itunes": "dev-master"
或者参考 Packagist 上的 vinelab/itunes
// change this to point correctly according // to your folder structure. require './vendor/autoload.php'; use Vinelab\ITunes\Agent as iTunes; $iTunes = new iTunes(); $response = $iTunes->search('Porcupine Tree')); // The original iTunes response $json = json_encode($response);
Laravel
- 编辑 app.php 并将
'Vinelab\ITunes\ITunesServiceProvider'
添加到'providers'
数组中。它将自动别名为ITunes
,可以用作 Facade 类。 - 运行
php artisan vendor:publish
发布配置文件。
此库支持 Laravel 4 和 Laravel 5.x,要在 L4 中安装,请使用版本 1.1.x。
用法
搜索
<?php // Search the iTunes Store ITunes::search('Metallica'); // Search the iTunes Store with custom parameters ITunes::search('Cannibal Corpse', array('limit'=>25, 'entity'=>'...')); /** * Search for media * * check (http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html#searching) * for all supported media types (the media parameter) */ ITunes::music('Rolling Stones'); ITunes::musicVideo('Immolation'); ITunes::tvShow('Sex and The City');
在区域中
您可以通过简单地给任何媒体搜索方法名加上 InRegion
后缀来在特定区域中进行搜索
ITunes::musicInRegion('LB', 'Myriam Fares'); ITunes::musicVideoInRegion('US', 'Immolation');
查找
<?php // Lookup defaults to id=... ITunes::lookup(490326927); // You can also specify the lookup request ITunes::lookup('amgVideoId', 17120); // Multiple items lookup ITunes::lookup('amgAlbumId', '15175,15176,15177,15178,15183,15184,15187,1519,15191,15195,15197,15198');
缓存
您可以根据以下方式指定每次请求的缓存持续时间(以分钟为单位)
注意:最后设置的缓存持续时间值将保持对所有剩余请求的其余部分,因此请确保之后重置。
<?php ITunes::cacheFor(10); ITunes::search('Gangnam Style'); // will be cached for 10 min. ITunes::cacheFor(1); ITunes::search('Yesterday'); // will be cached for 1 min. // To bypass caching pass 0 ITunes::cacheFor(0); ITunes::search('Hallelujah'); // won't be cached