예제 #1
0
 public function httpDo($verb, $path, $query)
 {
     if (!in_array($verb, array('GET', 'POST'))) {
         return;
     }
     $ret = null;
     $auth = null;
     $url = $this->api_base_url . $path;
     if (isset($this->conf['API_KEY']) && $this->conf['API_KEY'] != '') {
         $auth = implode(':', array($this->conf['API_KEY'], $this->conf['API_SECRET']));
     }
     switch ($verb) {
         case 'GET':
             $headers = array('Accept: application/json');
             $query = http_build_query($query);
             $transfer = cURL::GET($url . '?' . $query, $auth, $headers, $this->user_agent);
             break;
         case 'POST':
             $headers = array('Content-Type: application/json', 'Accept: application/json', 'Content-Length: ' . strlen($query));
             $transfer = cURL::POST($url, $query, $auth, $headers, $this->user_agent);
             break;
     }
     if ($transfer['body'] === false) {
         $ret = array('errors' => array(array('code' => 'curl_error', 'status' => $transfer['error'])));
     } else {
         $ret = json_decode($transfer['body'], true);
     }
     return $ret;
 }