コード例 #1
0
 private function request($call, $otherQueries = false, $static = false)
 {
     //format the full URL
     $url = $this->format_url($call, $otherQueries);
     //caching
     if ($this->cache !== null && $this->cache->has($url)) {
         $result = $this->cache->get($url);
     } else {
         // Check rate-limiting queues if this is not a static call.
         if (!$static) {
             $this->updateLimitQueue($this->longLimitQueue, self::LONG_LIMIT_INTERVAL, self::RATE_LIMIT_LONG);
             $this->updateLimitQueue($this->shortLimitQueue, self::SHORT_LIMIT_INTERVAL, self::RATE_LIMIT_SHORT);
         }
         //call the API and return the result
         $ch = curl_init($url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
         $result = curl_exec($ch);
         $this->responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
         curl_close($ch);
         if ($this->responseCode == 200) {
             if ($this->cache !== null) {
                 $this->cache->put($url, $result, self::CACHE_LIFETIME_MINUTES * 60);
             }
             if (self::DECODE_ENABLED) {
                 $result = json_decode($result, true);
             }
         } else {
             throw new Exception(self::$errorCodes[$this->responseCode]);
         }
     }
     return $result;
 }