/** * 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); }
public function testAllowsNestedArrayExpansion() { $template = new URITemplate(); $result = $template->expand('http://example.com{+path}{/segments}{?query,data*,foo*}', array('path' => '/foo/bar', 'segments' => array('one', 'two'), 'query' => 'test', 'data' => array('more' => array('fun', 'ice cream')), 'foo' => array('baz' => array('bar' => 'fizz', 'test' => 'buzz'), 'bam' => 'boo'))); $this->assertEquals('http://example.com/foo/bar/one,two?query=test&more%5B0%5D=fun&more%5B1%5D=ice%20cream&baz%5Bbar%5D=fizz&baz%5Btest%5D=buzz&bam=boo', $result); }