owenandrews/willyweather-php

A PHP client for WillyWeathers's v2 API.

v0.1.0 2017-05-22 01:13 UTC

This package is not auto-updated.

Last update: 2024-05-17 17:59:17 UTC


README

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.

Requirments

Installation

composer require owenandrews/willyweather-php

Usage

Get a location

Retrieve basic information for a given location ID.

use WillyWeather\Client;

$willyWeather = new Client('<API-KEY>');
$sydney = $willyWeather->location(4950);
$sydney->getName();

Get forecast and observational data

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();

Get custom forecast data

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]);

Shorthand

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

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];

Caching

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/');

Dates and Times

All date/time strings are converted to Carbon objects in the locations local timezone.

Contributing

Contributions are most welcome, just submit a pull request. 😄

License

This project is licensed under the MIT License - see the LICENSE file for details.

Built With

Authors