marvelley/lastfm-api

last.fm API 客户端

v0.1 2013-11-26 23:49 UTC

This package is not auto-updated.

Last update: 2024-09-14 13:40:30 UTC


README

这是一个 last.fm API 的客户端。它使用 Guzzle 网络服务库。客户端 API 是基于 Guzzle\Service\Client 的自定义网络服务客户端。

Build Status

安装

使用 composer 安装库及其所有依赖项

composer require "marvelley/lastfm-api:1.0.*@dev" 

基本用法示例

在您可以使用库之前,您必须在 last.fm API 页面 上请求您的 API 密钥。
将密钥放入以下代码中,然后从命令行运行代码

require 'vendor/autoload.php';

use Marvelley\Lastfm\Api\LastfmApiClient;

$l = LastfmApiClient::factory(array('api_key' => 'your_api_key'));
$ai = $l->getCommand('artist.getInfo', array(
	'artist' => 'Elvis Presley', 
	"format" => "json"
));
$result = $ai->execute();
echo "Similar artists:\n";
foreach($result['artist']['similar']['artist'] as $artist) {
	printf("  - %s\n", $artist['name']);
}

## 运行集成测试

在运行测试套件之前,您需要使用有效的 last.fm API 密钥配置一个特定的环境变量。例如,从您的终端

$ export LAST_FM_PHP_CLIENT_API_KEY=your_api_key

或者添加类似的条目到您的 bash/zsh/等配置文件中。

然后,您可以通过以下方式运行测试套件

$ phpunit

从项目目录的根目录(假设您已安装并配置了 PHPUnit)。