Laminas/Zend Framework module to consume iTunes API
Install the module using Composer into your application's vendor directory. Add the following line to your
composer.json
.
{
"require": {
"firelike/itunes-api": "^1.0"
}
}
Enable the module in your application.config.php
file.
return array(
'modules' => array(
'Firelike\ITunes'
)
);
Copy and paste the itunes.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 itunes.local.php
might look something like the following:
<?php
return [
'itunes_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\ITunes\Request\AbstractRequest;
use Firelike\ITunes\Request\Search as SearchRequest;
use Firelike\ITunes\Service\ITunesService;
$request = new SearchRequest();
$request->setTerm('micheal connelly')
->setMedia('audiobook')
->setLimit(25);
$service = new ITunesService();
$result = $service->search($request);
$numberOfRecords = $result->toArray()['resultCount'];
var_dump($numberOfRecords);
$records= $result->toArray()['results'];
var_dump($records);
Using the console:
php public/index.php itunes search -v
- search
- lookup
- feed
- availableFeeds
- genres