diff --git a/controllers/weather.php b/controllers/weather.php index ca06e76..cb53298 100644 --- a/controllers/weather.php +++ b/controllers/weather.php @@ -3,12 +3,13 @@ $app->get('/api/weather', function() use($app) { $params = $app->request()->params(); - if(k($params, 'latitude') !== null && k($params, 'longitude') !== null) { + if(k($params, 'latitude') !== null && k($params, 'longitude') !== null && k($params, 'apikey') !== null) { $lat = (float)$params['latitude']; $lng = (float)$params['longitude']; + $key = $params['apikey']; - $weather = \p3k\Weather::weather_for_location($lat, $lng); + $weather = \p3k\Weather::weather_for_location($lat, $lng, $key); if($weather) { json_response($app, $weather); diff --git a/p3k/Weather.php b/p3k/Weather.php index f46cb03..c0cfc91 100644 --- a/p3k/Weather.php +++ b/p3k/Weather.php @@ -5,8 +5,8 @@ use Config; use DateTime, DateTimeZone; class Weather { - public static function weather_for_location($lat, $lng) { - $data = self::_fetch($lat, $lng); + public static function weather_for_location($lat, $lng, $key) { + $data = self::_fetch($lat, $lng, $key); if(!$data) return null; $current = $data->current_observation; @@ -87,9 +87,9 @@ class Weather { return $weather; } - private static function _fetch($lat, $lng) { + private static function _fetch($lat, $lng, $key) { $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, 'http://api.wunderground.com/api/'.Config::$wundergroundAPIKey.'/conditions/q/'.$lat.','.$lng.'.json'); + curl_setopt($ch, CURLOPT_URL, 'http://api.wunderground.com/api/'.$key.'/conditions/q/'.$lat.','.$lng.'.json'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // curl_setopt($ch, CURLOPT_USERAGENT, ''); curl_setopt($ch, CURLOPT_TIMEOUT, 5); diff --git a/views/index.php b/views/index.php index 4a4f131..b7cd03d 100644 --- a/views/index.php +++ b/views/index.php @@ -28,10 +28,10 @@
Icon names reference the weather-icons icon font.
+You'll need to pass a Wunderground API key in the request. Icon names reference the weather-icons icon font.