public function getWeather($postal_code, $country_code = NULL)
{
try {
$url = "https://home.nest.com/api/0.1/weather/forecast/{$postal_code}";
if (!empty($country_code)) {
$url .= ",{$country_code}";
}
$weather = $this->doGET($url);
} catch (RuntimeException $ex) {
// NESTAPI_ERROR_NOT_JSON_RESPONSE is kinda normal. The forecast API will often return a '502 Bad Gateway' response... meh.
if ($ex->getCode() != NESTAPI_ERROR_NOT_JSON_RESPONSE) {
throw new RuntimeException("Unexpected issue fetching forecast.", $ex->getCode(), $ex);
}
}
return (object) array('outside_temperature' => isset($weather->now) ? $this->temperatureInUserScale((double) $weather->now->current_temperature) : NULL, 'outside_humidity' => isset($weather->now) ? $weather->now->current_humidity : NULL);
}