rakibdevs / covid19-laravel-api
Laravel 包,用于连接 https://rapidapi.com/api-sports/api/,获取全球任何地点的即时新冠统计数据
v1.2
2021-08-23 03:37 UTC
Requires
- php: ^7.0|^8.0
- guzzlehttp/guzzle: ^6.3.1|^7.0.1
This package is not auto-updated.
Last update: 2024-09-24 19:29:39 UTC
README
Laravel Covid-19 API (covid19-laravel-api) 是一个 Laravel 包,用于连接 Open Covid-19 APIs ( https://rapidapi.com/api-sports/api/covid-193 ),方便地访问免费 API 服务。
支持的 API
安装
通过 Composer 安装包。在命令行
composer require rakibdevs/covid19-laravel-api
配置
如果 Laravel > 7,则无需添加提供者
将以下内容添加到您的 providers
数组中的 config/app.php
'providers' => [ // ... RakibDevs\Covid19\Covid19ServiceProvider::class, ], 'aliases' => [ //... 'Covid19' => RakibDevs\Covid19\Covid19::class, ];
使用 artisan 命令发布所需的包配置文件
$ php artisan vendor:publish
编辑 config/openCovid19.php
文件,并使用您的 Open Covid19 Map API 密钥修改 api_key
值。
在此处获取 API 密钥 here
return [ 'api_key' => '' ];
使用方法
这里您可以查看一些使用此包的示例,它非常简单。
use RakibDevs\Covid19\Covid19; use RakibDevs\Covid19\Facades\Covid; // Get current Covid19 by city name // 1. The traditional way $wt = new Covid19(); $info = $wt->getCountries('ban'); // 2. The Facade way $info = Covid::getCountries('ban');
输出
{
"get":"countries"
"parameters":{
"search":"ban"
}
"errors":[]
"results":3
"response":[
0:"Albania"
1:"Bangladesh"
2:"Lebanon"
]
}
可用国家
获取所有国家的当前统计数据
// By country name or portion of string $info = $wt->getCountries('ban'); // Get all countries $info = $wt->getAllCountries();
输出
{
"get":"countries"
"parameters":[]
"errors":[]
"results":225
"response":[
0:"Afghanistan"
1:"Albania"
........
]
}
统计数据
此端点反映了所有国家冠状病毒传播的当前状态。
可以按国家过滤以获取其当前状态。
对于全球现状,使用 所有
// By country name $info = $wt->getStatistics(); // Get statistics $info = $wt->getAllStatistics();
输出
{
"get":"statistics"
"parameters":{
"country":"bangladesh"
}
"errors":[]
"results":1
"response":[
0:{
"continent":"Asia"
"country":"Bangladesh"
"population":165545725
"cases":{
"new":"+692"
"active":47562
"critical":NULL
"recovered":466064
"1M_pop":"3149"
"total":521382
}
"deaths":{
"new":"+22"
"1M_pop":"47"
"total":7756
}
"tests":{
"1M_pop":"20202"
"total":3344399
}
"day":"2021-01-10"
"time":"2021-01-10T05:30:06+00:00"
}
]
}
历史记录
此函数指的是一个国家的统计数据的全部历史。
对于全球结果,使用 .
// By country name [required] and date $info = $wt->getHistory('bangladesh', '2020-01-01');
输出
{
"get":"history"
"parameters":{
"country":"Bangladesh"
"day":"2020-06-02"
}
"errors":[]
"results":1
"response":[
0:{
"continent":"Asia"
"country":"Bangladesh"
"population":164551275
"cases":{
"new":"+2381"
"active":38265
....
全球摘要
获取截至当前日期的全球新冠摘要。
$info = $wt->getSummary();
输出
{
"cases_new": 777635
"cases_active": 67908362
"cases_critical": 325531
"cases_recovered": 193258167
"cases_total": 270304615
"deaths_new": 14668
"deaths_total": 5805634
"tests_total": 1282221510
"time": "2020-03-25T06:00:07+00:00"
}
许可
Laravel Open Covid19 API 采用 MIT 许可证 (MIT) 许可。