public function test1() { $city = 'Los Angeles '; $country = 'USA'; $x = YahooQueryClient::geocode($city, $country); // d($x); $this->assertEquals($x->name, "Los Angeles"); $this->assertEquals($x->country, "US"); }
/** * @param place, city or Yahoo WOEID of location */ function getWeather($place, $country = '') { if (self::isWoeid($place)) { $woeid = $place; } else { $x = YahooQueryClient::geocode($place, $country); if (!$x->woeid) { throw new \Exception('location not found'); } $woeid = $x->woeid; } $temp = TempStore::getInstance(); $key = 'WeatherClient//' . $woeid; $data = $temp->get($key); if ($data) { return unserialize($data); } $url = 'http://weather.yahooapis.com/forecastrss' . '?w=' . $woeid . '&u=c'; // unit = celcius $this->parse($url); $items = $this->getItems(); if (count($items) != 1) { throw new \Exception('unexpected number of results'); } if (!$this->city) { return false; } $res = new WeatherResult(); $res->city = $this->city; $res->region = $this->region; $res->country = $this->country; //XXXX what is the unit types? $res->wind_chill = $this->wind_chill; $res->wind_direction = $this->wind_direction; $res->wind_speed = $this->wind_speed; $res->coord_lat = $this->coord_lat; $res->coord_long = $this->coord_long; $res->time = $this->time; $res->visibility = $this->visibility; $res->celcius = $this->celcius; $locale = LocaleHandler::getInstance(); $res->skycond = $locale->getSkycondition($this->skycond); $temp->set($key, serialize($res), '1h'); return $res; }