sourceout / lastfm-php-sdk
LastFM SDK for PHP
1.0.0
2018-07-02 20:49 UTC
Requires
- php: ^7.1
- php-http/client-implementation: ^1.0
- php-http/discovery: ^1.0
- php-http/httplug: ^1.0
- php-http/message-factory: ^1.0
- psr/http-message: ^1.0
- tightenco/collect: ^5.6
Requires (Dev)
- limedeck/phpunit-detailed-printer: ^3.2
- mockery/mockery: ^1.0.0
- php-http/message: ^1.0
- php-http/mock-client: ^1.0
- phpdocumentor/phpdocumentor: ^2.9
- phpunit/phpunit: ^6.4
Suggests
- guzzlehttp/psr7: Option 1: Message Factory required by HTTP Client to create messages
- php-http/guzzle6-adapter: Library depends on HTTPlug, it requires virtual package php-http/client-implementation
- php-http/message: Required by HTTP Client Libraries for PSR-7 Implementation
- slim/slim: Option 2: Message Factory required by HTTP Client to create messages
- zendframework/zend-diactoros: Option 2: Message Factory required by HTTP Client to create messages
This package is not auto-updated.
Last update: 2024-09-20 08:15:46 UTC
README
该仓库包含库,允许您从您的PHP应用程序访问Last.fm平台。
有关如何认证和获取API密钥的详细信息,请参阅API简介下的入门指南
。
在https://www.last.fm/api/intro阅读官方API文档以获取更多信息。
功能
以下是该库提供的功能列表
- 支持自定义实现(提供者)
- 用于发送HTTP请求的库选择
- 框架无关
- 灵活且易于扩展
安装
您可以使用以下命令通过composer安装此包
composer require php-http/guzzle6-adapter guzzlehttp/psr7 php-http/message sourceout/lastfm-php-sdk
虽然默认安装说明推荐Guzzle Http客户端,但并非只能使用此客户端。有关客户端选择,请参阅以下列表php-http/client-implementation。
有关此方法的更多信息,请参阅此文档。
使用方法
use Sourceout\LastFm\ProviderInterface; use Sourceout\LastFm\Client as LastFmClient; use Sourceout\LastFm\Provider\LastFm\LastFm; /** @var ProviderInterface $provider */ $provider = new LastFm(['api_key' => 'your_api_key_here']); /** @var LastFmClient $lastFmClient */ $lastFmClient = new LastFmClient(); /** @var Collection $topArtists */ $topArtists = $lastFmClient ->getServiceFactory($provider) ->getGeoService() ->getTopArtists( 'united states', // location 1, // page number 50 // results per page );
您还可以注册自己的自定义提供者而不是使用默认提供者,例如。
use Sourceout\LastFm\Client as LastFmClient; $lastFmClient = new LastFmClient(); $lastFmClient->registerCustomProviders( [ \path\to\custom\provider::class ... ... ] );
此外,尽管该包具有自动发现http包/客户端的功能,但您也可以设置自己的HttpClient,以下示例展示了您提供Guzzle6实例的情况。
方法1
use Sourceout\LastFm\Http\Http; use Sourceout\LastFm\Http\HttpInterface; use Sourceout\LastFm\Client as LastFmClient; use Http\Adapter\Guzzle6\Client as GuzzleClient; use Http\Message\MessageFactory\GuzzleMessageFactory; /** @var HttpInterface $http */ $http = new Http(); $http->setHttpClient(new GuzzleClient()); $http->setMessageFactory(new GuzzleMessageFactory()); /** @var LastFmClient $lastFmClient */ $lastFmClient = new LastFmClient($http);
方法2
use Sourceout\LastFm\Http\Http; use Sourceout\LastFm\Http\HttpInterface; use Sourceout\LastFm\Client as LastFmClient; use Http\Adapter\Guzzle6\Client as GuzzleClient; use Http\Message\MessageFactory\GuzzleMessageFactory; /** @var HttpInterface $http */ $http = new Http(); $http->setHttpClient(new GuzzleClient()); $http->setMessageFactory(new GuzzleMessageFactory()); /** @var LastFmClient $lastFmClient */ $lastFmClient = new LastFmClient(); $lastFmClient->setHttpClient($http);
支持的方法
LastFm提供了大量API(参考:https://www.last.fm/api),以下是该库目前支持的方法列表
测试
您可以使用以下命令运行测试
vendor/bin/phpunit
贡献
有关详细信息,请参阅CONTRIBUTING。
安全性
如果您发现任何安全问题,请通过电子邮件pulkit.swarup@gmail.com而不是使用问题跟踪器。
许可证
有关更多信息,请参阅许可证文件。