Package Data | |
---|---|
Maintainer Username: | uberboom |
Maintainer Contact: | bernd@ennsfellner.at (Bernd Ennsfellner) |
Package Create Date: | 2014-04-25 |
Package Last Update: | 2014-05-02 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-08 03:24:48 |
Package Statistics | |
---|---|
Total Downloads: | 14 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 3 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Forecast.io API for PHP
You can register the ForecastServiceProvider to automatically use the Laravel built in cache functionality.
To do so, update the providers
array in your app/config/app.php
:
'providers' => array(
// ...
'Uberboom\Forecast\ForecastServiceProvider',
),
Next, update the class aliases in the aliases
array in your app/config/app.php
:
'providers' => array(
// ...
'Forecast' => 'Uberboom\Forecast\Facades\Forecast',
),
First, publish the configuration from the package:
php artisan config:publish uberboom/forecast
Get an API key at Forecast for Developers and add the API key to the app/config/packages/uberboom/forecast/config.php
file:
'api_key' => 'your-api-key-from-developer.forecast.io',
The package includes two difference HTTP client implementations: One is using the PHP Curl extension, the other one relies on file_get_contents()
, so make sure that either the Curl extension is loaded or allow_url_fopen
is enabled in your php.ini file.
'httpclient' => 'curl|file',
The package provides some Laravel Facade magic, so fetching the weather forecast is a piece of cake:
$weather = \Forecast::getWeatherByLocation($latitude, $longitude);
If you need to change the units, you can set the units used in the response by using the method setUnits()
:
$weather = \Forecast::setUnits(\Uberboom\Forecast\Forecast::UNITS_SI)->getWeatherByLocation($latitude, $longitude);
If you are not using Laravel, you have to set the API key manually:
$forecastApiKey = 'your-api-key-from-developer.forecast.io';
$forecast = new \Uberboom\Forecast\Forecast();
$forecast->setApiKey($forecastApiKey);
The package includes two difference HTTP client implementations: One is using the PHP Curl extension, the other one relies on file_get_contents
, so make sure that either the Curl extension is loaded or allow_url_fopen
is enabled in your php.ini file.
$forecast->setHttpClientWrapper(new \Uberboom\Forecast\HttpClient\Curl());
$forecast->setHttpClientWrapper(new \Uberboom\Forecast\HttpClient\File());
Currently, the package only includes an cache store implementation for the Laravel framework. If you want to use the package’s cache functionality, you need to build and inject your own cache store class, which has to implement the \Uberboom\Forecast\CacheStore\CacheStoreInterface
interface.
$forecast->setCacheStore(new YourCacheStore());
$forecast->getWeatherByLocation($latitude, $longitude);
If you need to change the units, you can set the units used in the response by using the method setUnits()
:
$weather = $forecast::setUnits(\Uberboom\Forecast\Forecast::UNITS_SI)->getWeatherByLocation($latitude, $longitude);