amsaid / world-news-api
用于世界新闻API的Laravel客户端
v0.1.1
2024-08-30 13:01 UTC
Requires
- php: ^8.2
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- orchestra/testbench: ^9.0.0||^8.22.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-arch: ^2.7
- pestphp/pest-plugin-laravel: ^2.3
README
支持我们
如果您喜欢这个包,请考虑通过捐赠来支持我们的开发。您的支持将受到极大的欢迎!🙏
安装
您可以通过composer安装此包
composer require amsaid/world-news-api
您可以使用以下命令发布配置文件和服务提供者
php artisan world-news-api:install
这是发布配置文件的内容
return [ 'apikey' => env('NEWS_API_KEY', 'your-api-key'), ];
使用方法
use Amsaid\WorldNewsApi\Facades\NewsApi; $news = NewsApi::search(query: 'Messi', countries: 'us', language: 'en'); // returns a collection of news items $newsItem = $news->first(); // returns a single news item collection // All news items are Laravel collections $newsItem->toJson(); /* returns { "summary": "Joan Monfort never believed in fate...", "image": "https://a.espncdn.com/photo/2024/0710/r1356881_1296x729_16-9.jpg", "sentiment": -0.456, "author": "Sid Lowe", "language": "en", "video": null, "title": "Photographer didn't believe in destiny...", "url": "https://www.espn.com/soccer/story/_/id/4088...", "source_country": "US", "id": 254279758, "text": "...", "category": null, "publish_date": "2024-08-16 18:40:10", "authors": [ "Sid Lowe" ] } */ // Access the summary of the first news item $newsItem->get('summary'); // 'Joan Monfort never believed in fate...' // Access the author of the first news item $newsItem->get('author'); // 'Sid Lowe' // Loop through each news item foreach ($news as $item) { // Access the title of each news item echo $item->get('title'); }
致谢
许可协议
MIT许可(MIT)。请参阅许可文件以获取更多信息。