A wrapper for Openweathermap One Call Api v1 -> Link.
⚡ Currently not working due to changes from openweathermap! |
---|
Read here -> https://openweathermap.org/one-call-transfer |
I will upgrade to version 3 as soon as possible |
I am not owner or maintainer of the API (https://openweathermap.org/api). This is only a wrapper for it. You need to get an api-key from their site to use the api.
You need a working environment with php >= 8.2 and composer.
composer require thomasboom89/openweathermap-one-call-api
Create an instance of the OneCallApi
$httpClient = new Client();
$httpFactory = new HttpFactory();
$owmoca = new OneCallApi("YOUR-API-KEY", $httpClient, $httpFactory);
// Optional use caching interface
$pool = new ArrayAdapter();
$cache = new Psr16Cache($pool);
$owmoca = new OneCallApi("YOUR-API-KEY", $httpClient, $httpFactory, $cache, 240);
Now you can use it to make a request
// lat , lon , language , unitsystem
try {
$forecast = $owmoca->getForecast(-78.944450, 19.458971, OneCallApi\Language::German, OneCallApi\Unit::Metric);
} catch (Exception $exception){
// handle exception
}
You will receive a forecast object
var_dump($forecast);
Q: Which language is currently supported?
A: You have to use Enum Thomasboom89\OpenWeatherMap\OneCallApi\Language
(If a language is missing, please open an issue)
Q: Which unitsystem is currently supported?
A: You have to use Enum Thomasboom89\OpenWeatherMap\OneCallApi\Unit \
Openweathermap One Call API Copyright (C) 2023 ThomasBoom89. MIT license.
Openweathermap One Call API includes several third-party Open-Source libraries, which are licensed under their own respective Open-Source licenses.
See composer license
for complete list of depending libraries.