irkfdb / irkfdb-php-client
PHP 客户端用于互联网拉吉尼坎特事实数据库 - irkfdb.in
dev-master
2018-09-19 10:48 UTC
Requires (Dev)
- phpunit/phpunit: 6.5.x-dev
This package is not auto-updated.
Last update: 2024-09-15 02:41:11 UTC
README
互联网拉吉尼坎特事实数据库的 PHP API 客户端。它是一个用于由 irkfdb.in 托管的拉吉尼坎特事实免费数据库的包装类。
安装
使用 Composer
composer require irkfdb/irkfdb-php-client
用法
获取类别
require_once "vendor/autoload.php";
use Irkfdb\IrkfdbClient;
$irkfdbClient = new IrkfdbClient();
$irkfdbClient->getCategories()
示例响应
Array
(
[status] => OK
[resultSet] => Array
(
[data] => Array
(
[0] => nsfw
[1] => geeky
)
)
)
如果 API 失败,响应将如下所示 示例响应
Array
(
[status] => FAIL
[errMessage] => '<err message>'
)
获取随机事实
$irkfdbClient = new IrkfdbClient();
$irkfdbClient->getRandomFact()
示例响应
Array
(
[status] => OK
[resultSet] => Array
(
[data] => Array
(
[0] => Array
(
[hash_id] => 9a004def16176d9a2b258a15bf898119
[db_id] => 426
[fact] => Rajinikanth writes code that optimizes itself.
[categories] => Array
(
[0] => geeky
)
[sources] => Array
(
[0] => api.icndb.com
[1] => raw.githubusercontent.com/jenkinsci
)
)
)
[total_facts] => 9361
)
)
从所选类别/类别获取随机事实
$irkfdbClient = new IrkfdbClient();
// random fact belonging to one category
$irkfdbClient->fromCategories('geeky')->getRandomFact();
//or for multiple categories
$irkfdbClient->fromCategories('nsfw,geeky')->getRandomFact();
or
$irkfdbClient->fromCategories(['nsfw','geeky'])->getRandomFact();
排除特定类别/类别的事实
$irkfdbClient = new IrkfdbClient();
// random fact belonging to one category
$irkfdbClient->excludeCategories('geeky')->getRandomFact();
//or for multiple categories
$irkfdbClient->excludeCategories('nsfw,geeky')->getRandomFact();
or
$irkfdbClient->excludeCategories(['nsfw','geeky'])->getRandomFact();
运行测试
./vendor/bin/phpunit --configuration phpunit.xml