WeatherUndergroundBundle
Symfony2 bundle for working with Weather Underground API, (*1)
Introduction
This Bundle enables integration Weather Underground API with your Symfony 2 project., (*2)
Installation
...
{
"kriswallsmith/buzz": "0.7",
"suncat/weather-underground": "dev-master"
}
...
Add this bundle to your application's kernel:
//app/AppKernel.php
public function registerBundles()
{
return array(
// ...
new SunCat\WeatherUndergroundBundle\WeatherUndergroundBundle(),
// ...
);
}
#app/config/config.yml
weather_underground:
apikey: your_api_key
Full configuration
#app/config/config.yml
weather_underground:
apikey: your_api_key
format: json # json/xml
host_data_features: http://api.wunderground.com # default: http://api.wunderground.com
host_autocomlete: http://autocomplete.wunderground.com # default: http://autocomplete.wunderground.com
Usage example
``` php, (*3)
<?php
// src/Acme/YourBundle/Command/WUForecastCommand.php
class WUForecastCommand extends ContainerAwareCommand
{
/**
* @see Command
*/
protected function configure()
{
$this
->setName('weather_underground:forecast')
->setDescription('Import data forecast by cities from api.wunderground.com')
->addOption('city', 0, InputOption::VALUE_REQUIRED, 'City name')
->setHelp(<<weather_underground:forecast command import forecast data., (*4)
php app/console weather_underground:forecast --city=Moscow, (*5)
EOF
);
}, (*6)
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$wuApi = $this->getContainer()->get('weather_underground.data_features');
$wuApi->setFeatures(array('forecast'));
$cityName = $input->getOption('city');
if(!$cityName){
throw new \Exception('Enter city name');
}
$wuApi->setQuery('/Russia/' . $cityName, true);
$data = $wuApi->getData();
//
// put your code
//
}
}
Run command:
``` php
php app/console weather_underground:forecast --city=Moscow
Data Features examples
``` php
$wuApi->setRequestData(
array('forecast', 'geolookup'), // Features
array('lang' => 'RU'), // Settings
'Russia/Moscow' // Query
);
$data = $wuApi->getData();, (*7)
``` php
$wuApi->setFeatures(array('forecast', 'geolookup')); // Features
$wuApi->setQuery('Russia/Moscow', true); // Query
$data = $wuApi->getData();
AutoComplete example
php
$wuAutocomplete = $this->getContainer()->get('weather_underground.autocomplete');
$wuAutocomplete->setOptions(array('c' => 'RU', 'cities' => 1, 'query' => 'Mosc'));
$data = $wuAutocomplete->getData();
, (*8)
Weather Underground API Documentation
Data Features, (*9)
AutoComplete API, (*10)