/**
  * @covers DNSMadeEasy\driver\Configuration::getURL
  */
 public function testGetURL()
 {
     $configuration = new Configuration($this->apiKey, $this->secretKey, true);
     $this->assertEquals('https://api.sandbox.dnsmadeeasy.com/V2.0', $configuration->getURL(), "The sandbox url should be returned");
     $configuration = new Configuration($this->apiKey, $this->secretKey, false);
     $this->assertEquals('https://api.dnsmadeeasy.com/V2.0', $configuration->getURL(), "The sandbox url should be returned");
 }
Example #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);
 }