|
@ -5,8 +5,8 @@ use Config; |
|
|
use DateTime, DateTimeZone; |
|
|
use DateTime, DateTimeZone; |
|
|
|
|
|
|
|
|
class Weather { |
|
|
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; |
|
|
if(!$data) return null; |
|
|
|
|
|
|
|
|
$current = $data->current_observation; |
|
|
$current = $data->current_observation; |
|
@ -87,9 +87,9 @@ class Weather { |
|
|
return $weather; |
|
|
return $weather; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static function _fetch($lat, $lng) { |
|
|
|
|
|
|
|
|
private static function _fetch($lat, $lng, $key) { |
|
|
$ch = curl_init(); |
|
|
$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_RETURNTRANSFER, TRUE); |
|
|
// curl_setopt($ch, CURLOPT_USERAGENT, '');
|
|
|
// curl_setopt($ch, CURLOPT_USERAGENT, '');
|
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 5); |
|
|