orthosie / theysaidso-quotes
该包最新版本(v1.0.0)没有可用的许可证信息。
为全球知名的They Said So名言平台提供的流畅PHP客户端。
v1.0.0
2024-08-15 16:57 UTC
Requires
- guzzlehttp/guzzle: ^7.0
Requires (Dev)
README
They Said So名言API的流畅php客户端库。您可以在这里获取API密钥。[https://theysaidso.com/api]
安装
composer require orthosie/theysaidso-quotes
获取每日名言
use TheySaidSo\QuoteOfTheDay;
$qod = QuoteOfTheDay::withCredential('<apikey>')->category('inspire')->get();
print "Quote of the day\n";
print $qod[0]['quote'] ." - " . $qod[0]['author'] . "\n";
获取随机名言
获取一个随机名言
use TheySaidSo\Quotes;
$quotes = Quotes::withCredential(<api-key>)->random()->limit(1)->get();
print "A quote by " . $quotes[0]['author'] . "\n";
print $quotes[0]['quote'] ."\n";
搜索名言
搜索有关设计的史蒂夫·乔布斯的名言
use TheySaidSo\Quotes;
$quotes = Quotes::withCredential(<api-key>)->search('design')->author('Steve Jobs')->get();
print "A quote by " . $quotes[0]['author'] . " on design\n";
print $quotes[0]['quote'] ."\n";
搜索的完整选项
以下是搜索API的完整选项。
use TheySaidSo\Quotes;
$quotes = Quotes::withCredential(<api-key>)
->search('design')
->author('Steve Jobs')
->category('experience') // quote should have a tag 'experience'
->minLength(10) // quote length should be > 10 characters
->maxLength(512) // quote length should be < 512 characters
->sfw(true) // Search only Safe for work quotes
->private(false) // Search public quotes not quotes added by you
->get();
print "A quote by " . $quotes[0]['author'] . " on design\n";
print $quotes[0]['quote'] ."\n";
速率限制数量
在调用服务器后,您可以从客户端库中获取速率限制数量。
use TheySaidSo\Quotes;
$theysaidso = Quotes::withCredential(<api-key>);
$quotes = $theysaidso->random()->limit(1)->get();
print "Total limit for this period " . $theysaidso->totalLimit() . "\n";
print "Limit remaining " . $theysaidso->limitRemaining() . "\n";