예제 #1
0
 public function send($method, $url, $body = null, $headers = array())
 {
     $curl = curl_init();
     $method = strtolower($method);
     switch ($method) {
         case 'post':
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
             break;
         case 'get':
             curl_setopt($curl, CURLOPT_HTTPGET, true);
             break;
         case 'put':
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
             break;
         case 'delete':
             curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE");
             break;
         default:
             throw new Castle_RequestError();
     }
     $curlOptions = array();
     if (!empty($body)) {
         $curlOptions[CURLOPT_POSTFIELDS] = $body;
     }
     $curlOptions[CURLOPT_CAINFO] = self::caCerts();
     $curlOptions[CURLOPT_URL] = $url;
     $curlOptions[CURLOPT_USERPWD] = ":" . Castle::getApiKey();
     $curlOptions[CURLOPT_RETURNTRANSFER] = true;
     $curlOptions[CURLOPT_USERAGENT] = "Castle/v1 PHPBindings/" . Castle::VERSION;
     $curlOptions[CURLOPT_CONNECTTIMEOUT] = 3;
     $curlOptions[CURLOPT_TIMEOUT] = 10;
     $curlOptions[CURLOPT_HTTPHEADER] = $headers;
     $curlOptions[CURLOPT_HEADER] = true;
     curl_setopt_array($curl, $curlOptions);
     $this->setResponse($curl);
     curl_close($curl);
 }
예제 #2
0
 public function preFlightCheck()
 {
     $key = Castle::getApiKey();
     if (empty($key)) {
         throw new Castle_ConfigurationError();
     }
 }
예제 #3
0
 public function testSetApiKey()
 {
     $this->assertContains('secretkey', Castle::getApiKey());
 }