thatobabusi / laravel-lastfm
PHP 7+ 的 Last.fm API 客户端
dev-master / 1.0.x-dev
2020-11-06 07:06 UTC
Requires
- php: >=7.0
- guzzlehttp/guzzle: >=6.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.0
- phpunit/phpunit: ~5.0||~6.0
This package is auto-updated.
Last update: 2024-09-06 15:56:57 UTC
README
API密钥
您可以在 http://www.last.fm/api/account/create 创建一个last.fm API账户。
安装
通过Composer
$ composer require thatobabusi/laravel-lastfm
Laravel 安装
将 LASTFM_API_KEY 变量添加到 .env 配置文件中。您也可以发布默认配置并自行修改
php artisan vendor:publish --provider="Thatobabusi\LaravelLastFm\LastfmServiceProvider"
通过添加 LastfmServiceProvider 更新 config/app.php
'providers' => [ ... Thatobabusi\LaravelLastFm\LastfmServiceProvider::class, ];
如果您使用的是 Laravel 5.5,则服务提供器将由 Laravel 的 包发现 自动使用。
已测试与 Laravel 5.* 兼容,但可能适用于大多数版本,因为它非常简单。如果它对您不起作用,请创建一个问题。
使用
基本示例
use Thatobabusi\LaravelLastFm\Lastfm; use GuzzleHttp\Client; $lastfm = new Lastfm(new Client(), 'YourApiKey'); $albums = $lastfm->userTopAlbums('AnyUsername')->get();
Laravel 示例
use Thatobabusi\LaravelLastFm\Lastfm; public function index(Lastfm $lastfm) { $albums = $lastfm->userTopAlbums('AnyUsername')->get(); return view('home', compact('albums')); }
所有可用方法
// Get top albums for user $albums = $lastfm->userTopAlbums('AnyUsername')->get(); // Get top artists for user $artists = $lastfm->userTopArtists('AnyUsername')->get(); // Get recent tracks for user $tracks = $lastfm->userRecentTracks('AnyUsername')->get(); // Get user info $info = $lastfm->userInfo('AnyUsername')->get(); // Get track that user is now listening to, or FALSE $trackOrFalse = $lastfm->nowListening('AnyUsername'); // Get the weekly top albums given a starting day $albums = $lastfm->userWeeklyTopAlbums('AnyUsername', new \DateTime('2017-01-01')); // Get the weekly top artists given a starting day $artists = $lastfm->userWeeklyTopArtists('AnyUsername', new \DateTime('2017-01-01')); // Get the weekly top tracks given a starting day $tracks = $lastfm->userWeeklyTopTracks('AnyUsername', new \DateTime('2017-01-01'));
过滤结果
// Define time period for results $lastfm->userTopAlbums('AnyUsername') ->period(Thatobabusi\LaravelLastFm\Constants::PERIOD_WEEK) ->get(); // Limit number of results $lastfm->userTopAlbums('AnyUsername') ->limit(5) ->get(); // Retrieve paginated results $lastfm->userTopAlbums('AnyUsername') ->limit(5) ->page(2) ->get();
有效时间范围
// use these constants as an argument to ->period() Thatobabusi\LaravelLastFm\Constants::PERIOD_WEEK = '7day'; Thatobabusi\LaravelLastFm\Constants::PERIOD_MONTH = '1month'; Thatobabusi\LaravelLastFm\Constants::PERIOD_3_MONTHS = '3month'; Thatobabusi\LaravelLastFm\Constants::PERIOD_6_MONTHS = '6month'; Thatobabusi\LaravelLastFm\Constants::PERIOD_YEAR = '12month'; Thatobabusi\LaravelLastFm\Constants::PERIOD_OVERALL = 'overall';
官方API文档
请参阅 http://www.last.fm/api 上的官方API文档。
变更日志
请参阅 CHANGELOG 以获取有关最近更改的更多信息。
测试
将 phpunit.xml.dist
复制到 phpunit.xml
并填写您的 LASTFM_API_KEY。然后使用以下命令运行测试:
$ composer test
贡献
请参阅 CONTRIBUTING 和 CONDUCT 以获取详细信息。
安全性
如果您发现任何安全问题,请通过电子邮件 barryvanveen@gmail.com 而不是使用问题跟踪器。
鸣谢
许可协议
MIT 许可协议 (MIT)。有关更多信息,请参阅 许可文件。