Ejemplo n.º 1
0
 private function requestData($latitude, $longitude, $timestamp = false, $exclusions = false)
 {
     $validUnits = array('auto', 'us', 'si', 'ca', 'uk');
     if (in_array($this->units, $validUnits)) {
         $request_url = self::API_ENDPOINT . $this->api_key . '/' . $latitude . ',' . $longitude . ($timestamp ? ',' . $timestamp : '') . '?units=' . $this->units . '&lang=' . $this->language . ($exclusions ? '&exclude=' . $exclusions : '');
         /**
          * Use Buffer to cache API-requests if initialized
          * (if not, just get the latest data)
          *
          * More info: http://git.io/FoO2Qw
          */
         if (class_exists('Buffer')) {
             $cache = new Buffer();
             $content = $cache->data($request_url);
         } else {
             $content = file_get_contents($request_url);
         }
     } else {
         return false;
     }
     if (!empty($content)) {
         return json_decode($content);
     } else {
         return false;
     }
 }
Ejemplo n.º 2
0
 /**
  * Make the request to Forecast.io API
  * @param string $latitude $longitude $timestamp $exclusions
  * @return JSON data or false
  */
 private function requestData($latitude, $longitude, $timestamp = false, $exclusions = false)
 {
     $validUnits = array('auto', 'us', 'si', 'ca', 'uk', 'uk2');
     $validLangs = array('ar', 'bs', 'de', 'en', 'es', 'fr', 'it', 'nl', 'pl', 'pt', 'ru', 'sv', 'tet', 'tr', 'x-pig-latin', 'zh');
     // Ensure our data are valid, you never know
     if (in_array($this->units, $validUnits) and in_array($this->language, $validLangs)) {
         /**
          * If proxy set make a proxy call
          */
         if ($this->proxy) {
             $request_url = self::PROXY_API_ENDPOINT . $latitude . '/' . $longitude . '/' . $timestamp . '/' . $this->units . '/' . $this->language;
         } else {
             // Direct API call
             $request_url = self::API_ENDPOINT . $this->api_key . '/' . $latitude . ',' . $longitude . ($timestamp ? ',' . $timestamp : '') . '?units=' . $this->units . '&lang=' . $this->language . ($exclusions ? '&exclude=' . $exclusions : '');
         }
         /**
          * Use Buffer to cache API-requests if initialized
          * (if not, just get the latest data)
          *
          * More info: http://git.io/FoO2Qw
          */
         if (class_exists('Buffer')) {
             $cache = new Buffer();
             $content = $cache->data($request_url);
         } else {
             if (false !== ($content = @file_get_contents($request_url))) {
                 // all good
                 //return $content;
             } else {
                 // error happened
                 return false;
             }
         }
     } else {
         return false;
     }
     if (!empty($content)) {
         return json_decode($content);
     } else {
         return false;
     }
 }