Exemplo n.º 1
0
 public function doFetchCurrent(Point $point)
 {
     $content = file_get_contents('http://api.openweathermap.org/data/2.5/weather?q=Ulyanovsk,%20RU&units=metric&lang=ru');
     $result = json_decode($content, true);
     $cur = new Current();
     $cur->setData(['summary' => $result['weather'][0]['description'], 'temperature' => ['current' => $result['main']['temp'], 'min' => $result['main']['temp_min'], 'max' => $result['main']['temp_max']], 'wind' => ['speed' => $result['wind']['speed'], 'degree' => $result['wind']['deg']]]);
     return $cur;
 }
Exemplo n.º 2
0
 /**
  * @internal
  * @return \Forecast\Current
  */
 protected function doFetchCurrent(Point $point)
 {
     if ($point->getType() == Point::ADDRESS) {
         throw new \InvalidArgumentException();
     }
     $result = $this->doFetchAll($point);
     $result = $result['currently'];
     $cur = new Current();
     $precipType = self::PRECIP_TYPE_NONE;
     if ($result['precipProbability'] > 0) {
         switch ($result['precipType']) {
             case 'rain':
                 $precipType = self::PRECIP_TYPE_RAIN;
                 break;
             case 'snow':
                 $precipType = self::PRECIP_TYPE_SNOW;
                 break;
             case 'sleet':
                 $precipType = self::PRECIP_TYPE_SLEET;
                 break;
             case 'hail':
                 $precipType = self::PRECIP_TYPE_HAIL;
                 break;
             default:
                 throw new \Exception('Не известный тип precipType: ' . $result['precipType']);
         }
     }
     $cur->setData(['summary' => $result['summary'], 'temperature' => ['current' => $result['temperature'], 'apparent' => $result['apparentTemperature']], 'wind' => ['speed' => $result['windSpeed'], 'degree' => $result['windBearing']], 'precipitation' => ['intensity' => $result['precipIntensity'], 'probability' => $result['precipProbability'] * 100, 'type' => $precipType], 'humidity' => ['humidity' => $result['humidity']]]);
     return $cur;
 }