anime-db / ani-db-browser-bundle
为动漫数据库Anime DB的AniDB插件
v2.2.1
2017-08-14 18:50 UTC
Requires
- php: >=5.5
- ext-zlib: *
- guzzlehttp/guzzle: ~6.2
Requires (Dev)
- phpunit/phpunit: ~4.8
- satooshi/php-coveralls: ^1.0
- scrutinizer/ocular: ~1.3
- symfony/config: ~2.3|~3.0
- symfony/dependency-injection: ~2.3|~3.0
- symfony/expression-language: ~2.3|~3.0
- symfony/http-kernel: ~2.3|~3.0
README
AniDB.net浏览器
在此处阅读API文档: http://wiki.anidb.net/w/HTTP_API_Definition
安装
使用Composer非常简单,运行
composer require anime-db/ani-db-browser-bundle
将AnimeDbAniDbBrowserBundle添加到您的应用程序内核
// app/appKernel.php public function registerBundles() { $bundles = array( // ... new AnimeDb\Bundle\AniDbBrowserBundle\AnimeDbAniDbBrowserBundle(), ); }
配置
# app/config/config.yml anime_db_ani_db_browser: api: # API host # As a default used 'http://api.anidb.net:9001' host: 'http://api.anidb.net:9001' # Prefix for API resurces # As a default used '/httpapi/' prefix: '/httpapi/' # API version # As a default used '1' protover: 1 # You must register a client and use it here. # See for more info: # - http://anidb.net/perl-bin/animedb.pl?show=client # - https://wiki.anidb.net/w/UDP_Clients # - https://wiki.anidb.net/w/UDP_API_Definition app: # Verion of your client. version: 1 # Your client name. # You point it at registration here: http://anidb.net/perl-bin/animedb.pl?show=client client: 'my_home_client' # Your client code. # You will receive it after registration. code: 'api-team-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
用法
首先获取浏览器
$browser = $this->get('anime_db.ani_db.browser');
获取动漫数据 Seikai no Monshou (wiki)
$content = $browser->get(['query' => ['request' => 'anime', 'aid' => 1]]);
捕获异常
use AnimeDb\Bundle\AniDbBrowserBundle\Exception\BannedException; use AnimeDb\Bundle\AniDbBrowserBundle\Exception\NotFoundException; try { $content = $browser->get('anime?aid=1'); } catch (BannedException $e) { // you are banned } catch (NotFoundException $e) { // anime not found } catch (\Exception $e) { // other exceptions }
您可以自定义请求选项。请参阅Guzzle文档。
许可证
此包遵循GPL v3许可证。请参阅文件中的完整许可证:LICENSE