binarythinking / lastfm-bundle
在您的 Symfony 2 应用程序中使用 Last.fm API。
dev-master
2016-08-22 08:44 UTC
Requires
- php: >=5.3.2
- symfony/framework-bundle: 2.*
This package is not auto-updated.
Last update: 2024-09-23 10:49:33 UTC
README
用于 Last.fm API 的 Symfony 2 Bundle
这是一个帮助您与 Last.fm API 通信的 Bundle。
状态
此 Bundle 处理以下上下文的 API 方法(请参阅 github 上的 里程碑)
- 专辑
- 艺术家
- 图表
- 地理
- 图书馆
- 标签
- 用户
敬请期待更多即将到来。
安装
如果您使用 composer,只需添加
{ "require": { "binarythinking/lastfm-bundle": "dev-master" } }
如果您使用 deps 文件,只需添加
[BinaryThinkingLastfmBundle]
target=/bundles/BinaryThinking/LastfmBundle
git=http://github.com/karolsojko/BinaryThinkingLastfmBundle.git
在 autoload.php 中注册 BinaryThinking 命名空间
<?php $loader->add('BinaryThinking', __DIR__ . '/../vendor/bundles');
并在 AppKernel.php 中添加此 Bundle
<?php $bundles = array( // ... new BinaryThinking\LastfmBundle\BinaryThinkingLastfmBundle() );
配置
安装后,只需使用您的 Last.fm API 密钥和密钥对应用程序进行配置。
在配置中定义这两个参数为
binary_thinking_lastfm: client_apikey: "my_api_key" client_secret: "my_secret"
使用
在控制器中,如果您想获取专辑 API 上下文的客户端,可以这样获取服务
<?php $albumClient = $this->get('binary_thinking_lastfm.client.album');
或者,您可以通过客户端工厂请求特定的客户端,例如专辑
<?php $clientFactory = $this->get('binary_thinking_lastfm.client_factory'); $albumClient = $clientFactory->getClient('album', $apiKey, $apiSecret);
一旦您有了客户端,您就可以使用它调用 Last.fm API 中可用的方法,例如
<?php // search for an album $albums = $albumClient->search('Sound of perseverance'); // get detailed info on an album $album = $albumClient->getInfo('Cynic', 'Focus');