示例#1
0
 /**
  * @covers DNSMadeEasy\debug\Debugger::request
  */
 public function testRequest()
 {
     $curlInfo = array('url' => 'http://api.sandbox.dnsmadeeasy.com/V2.0/dns/managed', 'content_type' => 'application/json', 'http_code' => 200, 'header_size' => 339, 'request_size' => 244, 'filetime' => -1, 'ssl_verify_result' => 1, 'redirect_count' => 0, 'total_time' => 1.230122, 'namelookup_time' => 0.629414, 'connect_time' => 0.904966, 'pretransfer_time' => 0.905243, 'size_upload' => 0, 'size_download' => 709, 'speed_download' => 576, 'speed_upload' => 0, 'download_content_length' => -1, 'upload_content_length' => 0, 'starttransfer_time' => 1.228725, 'redirect_time' => 0, 'certinfo' => array(), 'primary_ip' => '208.94.147.116', 'primary_port' => 80, 'local_ip' => '192.168.1.20', 'local_port' => 49636, 'redirect_url' => '', 'request_header' => "POST /V2.0/dns/managed HTTP/1.1\r\nHost: api.sandbox.dnsmadeeasy.com\r\nAccept: */*\r\nx-dnsme-apiKey: 123-456-789\r\nx-dnsme-requestDate: Wed, 22 May 2013 06:20:31 UTC\r\nx-dnsme-hmac: 7d4fc7bdsdfa3agd429f280b0289dbc7058cf7c4e");
     $data = json_encode(array('names' => array('test.com')));
     $request = new Request($curlInfo, $data);
     $this->setOutputCallback(function ($output) {
         $this->assertInternalType('string', $output);
     });
     //Fire off the debug request
     $this->debugger->request($request);
 }
示例#2
0
 /**
  * Sends the request to the server.
  * @param  string              $command       The URI to append after the base URL.
  * @param  array               $uriParameters An optional array of URI template parameters.
  * @param  string              $method        The request method.
  * @param  string              $content       The request body.
  * @throws RESTException
  * @return \DNSMadeEasy\Result
  */
 private function send($command, $uriParameters, $method, $content = NULL)
 {
     $url = $this->_config->getURL();
     $ch = curl_init($url . $this->_uriTemplate->expand($command, $uriParameters));
     curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
     curl_setopt($ch, CURLOPT_TIMEOUT, 300);
     curl_setopt($ch, CURLOPT_HTTPHEADER, $this->getAuthenticationHeaders());
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     if ($content !== NULL) {
         curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($content));
     }
     switch (strtolower($method)) {
         case "get":
             curl_setopt($ch, CURLOPT_HTTPGET, true);
             break;
         case "post":
             curl_setopt($ch, CURLOPT_POST, true);
             break;
         case "put":
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
             //CURL_OPTPUT requires INFILE and writing to ram/disk, which is annoying
             break;
         case "delete":
             curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
             break;
     }
     curl_setopt($ch, CURLINFO_HEADER_OUT, true);
     curl_setopt($ch, CURLOPT_HEADER, true);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
     if (true || $this->_config->usingSandbox()) {
         //TODO le true ajouté par DDC pour bypass le control
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
         //Temporary workaround because https://api.sandbox.dnsmadeeasy.com uses a bad certificate
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
     } else {
         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     }
     $result = curl_exec($ch);
     //Something bad has happened, for example the API is down, etc.
     if (curl_errno($ch)) {
         $errorNumber = curl_errno($ch);
         $error = curl_error($ch);
         throw new RESTException("Error: {$errorNumber} - {$error}");
     }
     $info = curl_getinfo($ch);
     $request = new Request($info, $content);
     $response = new Response($result, $info['total_time']);
     //If debug mode is on, output the debug messages.
     if ($this->_config->getDebug()) {
         $this->_debugger->request($request);
         $this->_debugger->response($response);
     }
     curl_close($ch);
     return new Result($response);
 }