decole / yr-no
yr.no api php 客户端
1.0.1
2021-10-31 19:16 UTC
Requires
- php: ^7.4||^8.0
- ext-json: *
- guzzlehttp/guzzle: ^6.4||^7.0
This package is auto-updated.
Last update: 2024-09-29 06:14:32 UTC
README
使用composer安装
$ composer require decole/yr-no
一个用PHP编写并支持Laravel的客户端库。
此库使用了网站 https://www.yr.no 的非官方公开API端点,因此请注意,某些端点可能会随时停止工作。无论如何,如果出现损坏或缺失,请提交一个问题。
可选地,如果您使用 Laravel,可以使用以下命令发布此包的配置文件
$ php artisan vendor:publish --provider="Decole\YrNo\Adapters\Laravel\YrNoServiceProvider" --tag=config
配置
以下配置文件将发布在 config/yrno.php
中,设置 location
和 language
。示例配置已在默认设置中设置。
return [ 'location' => '2-553287', 'language' => 'en', ];
可能的语言
'language' => 'nb', - Ireland
'language' => 'nn', - Norwegian
'language' => 'en', - English
通过城市名称查找城市位置ID。例如,它是 'moscow'
(new YrNoClient('2-553287', 'en'))->location()->suggest('moscow');
响应:您需要找到将 "id"。在此示例中,这是 2-553287
查找ID: _embedded -> location -> 对象元素 -> id - ("2-524901")
查找区域: _embedded -> location -> 对象元素 -> region -> id - ("RU/48")
响应json
{ "totalResults": 5, "_links": { "self": { "href": "/api/v0/locations" }, "page": { "href": "/api/v0/locations{?page}", "templated": true }, "search": { "href": "/api/v0/locations/search{?q}", "templated": true }, "location": [ { "href": "/api/v0/locations/2-524901" }, ... ] }, "_embedded": { "location": [ { "category": { "id": "CA01", "name": "Capital" }, "id": "2-524901", "name": "Moscow", "position": { "lat": 55.75222, "lon": 37.61556 }, "elevation": 144, "timeZone": "Europe/Moscow", "urlPath": "Russia/Moscow/Moscow", "country": { "id": "RU", "name": "Russia" }, "region": { "id": "RU/48", "name": "Moscow" }, "isInOcean": false, "_links": { "self": { "href": "/api/v0/locations/2-524901" }, "celestialevents": { "href": "/api/v0/locations/2-524901/celestialevents" }, "forecast": { "href": "/api/v0/locations/2-524901/forecast" }, "mapfeature": { "href": "/api/v0/locations/2-524901/mapfeature" }, "currenthour": { "href": "/api/v0/locations/2-524901/forecast/currenthour" }, "observations": { "href": "/api/v0/locations/2-524901/observations" }, "auroraforecast": { "href": "/api/v0/locations/2-524901/auroraforecast" } } }, ... ] } }
如何使用
示例
use Decole\YrNo\YrNoClient; $location = '2-553287'; $lang = 'en'; $api = new YrNoClient($location, $lang); $data = $api->location()->suggest('moscow'); // Read on to explore all available methods
##使用Laravel外观的API方法
位置
//Get locations by current city YrNoClient::location()->get(); //Forecast by current city YrNoClient::location()->foreCast(); //Weather forecast current hour by current city YrNoClient::location()->currentHour(); //Celestial events by current city YrNoClient::location()->celestialEvents(); //Search city id, region id and another city params YrNoClient::location()->suggest('some city');
文章
//get article YrNoClient::article()->get();
区域
//Get region by region id YrNoClient::region()->get('NO'); //Get region water temperatures YrNoClient::region()->waterTemperatures('NO-42');
服务公告
//Service Announcement app by yr.no cite YrNoClient::serviceAnnouncement()->get();
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。