A PHP client for WillyWeathers's v2 API. http://www.willyweather.com.au/info/api.html
Note: This is not an official library, nor is it fully featured.
- PHP 7 or newer
- A WillyWeather API key
composer require owenandrews/willyweather-php
Retrieve basic information for a given location ID.
use WillyWeather\Client;
$willyWeather = new Client('<API-KEY>');
$sydney = $willyWeather->location(4950);
$sydney->getName();
Retrieve a location's basic forecast and observational data.
use WillyWeather\Client;
$willyWeather = new Client('<API-KEY>');
$sydney = $willyWeather->location(4950);
$sydney->getForecasts();
$sydney->getObservational();
By default, only the basic 7 day weather forecast is returned. To override this, just add an array of forecast types to the function call. Check out the API documentation for all available forecast types. Keep in mind you must enable each forecast type for your API key, otherwise the request will fail.
use WillyWeather\Client;
$willyWeather = new Client('<API-KEY>');
$sydney = $willyWeather->location(4950);
$sydney->getForecasts(["forecasts" => ["temperature", "wind", "rainfallprobability"], "days" => 3]);
So far we've recieved location, forecast and observational data, each time making a seperate API request. Thankfully, we can bundle that up into one API call.
use WillyWeather\Client;
$willyWeather = new Client('<API-KEY>');
$sydney = $willyWeather->location(4950, ["forecasts" => ["temperature", "wind", "rainfallprobability"], "days" => 3, "observational" => true]);
$sydney->getForecasts();
$sydney->getObservational();
This time only one API call was made.
Search for locations based on placename or postcode.
use WillyWeather\Client;
$willyWeather = new Client('<API-KEY>');
$sydney = $willyWeather->searchByQuery("Sydney")[0];
Search for locations based on proximity to a set of coordinates.
use WillyWeather\Client;
$willyWeather = new Client('<API-KEY>');
$mackenziesBay = $willyWeather->searchByCoordinates(["lat" => -33.8996141, "lng" => 151.272962])[0];
A basic file-based cache is included, this can help reduce repetitive API calls. To enable it, just pass in a suitable path while constructing the client.
use WillyWeather\Client;
$willyWeather = new Client('<API-KEY>', '/tmp/');
All date/time strings are converted to Carbon objects in the locations local timezone.
Contributions are most welcome, just submit a pull request. 😄
This project is licensed under the MIT License - see the LICENSE file for details.
- Guzzle - HTTP client
- GuzzleCache - Guzzle caching middleware
- Carbon - Date time library
- Flysystem - Filesystem abstraction