コード例 #1
0
ファイル: bc-mapi.php プロジェクト: ziw2013/PHP-MAPI-Wrapper
 /**
  * Retrieves API data from provided URL.
  * @access Private
  * @since 0.1.0
  * @param string [$url] The complete API request URL
  * @return object An object containing all API return data
  */
 private function getData($url)
 {
     if (class_exists('BCMAPICache')) {
         $cache = BCMAPICache::get($url);
         if ($cache !== FALSE) {
             $response_object = json_decode($cache);
             if (isset($response_object->items)) {
                 $data = $response_object->items;
             } else {
                 $data = $response_object;
             }
             $this->page_number = isset($response_object->page_number) ? $response_object->page_number : NULL;
             $this->page_size = isset($response_object->page_size) ? $response_object->page_size : NULL;
             $this->total_count = isset($response_object->total_count) ? $response_object->total_count : NULL;
             return $data;
         }
     }
     $this->timeout_current++;
     if (!isset($this->token_read)) {
         throw new BCMAPITokenError($this, self::ERROR_READ_TOKEN_NOT_PROVIDED);
     }
     $response = $this->curlRequest($url, TRUE);
     if ($response && $response != 'NULL') {
         $response_object = json_decode(preg_replace('/[[:cntrl:]]/u', '', $response));
         if (isset($response_object->error)) {
             if ($this->timeout_retry && $response_object->code == 103 && $this->timeout_current < $this->timeout_attempts) {
                 if ($this->timeout_delay > 0) {
                     if ($this->timeout_delay < 1) {
                         usleep($this->timeout_delay * 1000000);
                     } else {
                         sleep($this->timeout_delay);
                     }
                 }
                 return $this->getData($url);
             } else {
                 throw new BCMAPIApiError($this, self::ERROR_API_ERROR, $response_object);
             }
         } else {
             if (class_exists('BCMAPICache')) {
                 $cache = BCMAPICache::set($url, $response_object);
             }
             if (isset($response_object->items)) {
                 $data = $response_object->items;
             } else {
                 $data = $response_object;
             }
             $this->page_number = isset($response_object->page_number) ? $response_object->page_number : NULL;
             $this->page_size = isset($response_object->page_size) ? $response_object->page_size : NULL;
             $this->total_count = isset($response_object->total_count) ? $response_object->total_count : NULL;
             return $data;
         }
     } else {
         throw new BCMAPIApiError($this, self::ERROR_API_ERROR);
     }
 }