/** * Constructs the result object. * @param Response $response The driver response object. */ public function __construct(Response $response) { $decoded = json_decode($response->getBody()); //If things did not go well. if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 600) { $this->success = false; if (isset($decoded->error)) { $this->errors = $decoded->error; } if (!$this->errors) { // API calls don't always provide an error :( $this->errors[] = 'An error occurred, however, no error message was given. Use the response body, HTTP status code and URL to help troubleshoot the issue.'; } //If things went well. } else { $this->body = $decoded; } $this->statusCode = $response->getStatusCode(); //DME's request limit meta data. if (isset($response->getHeaders()['x-dnsme-requestId'])) { $this->requestId = $response->getHeaders()['x-dnsme-requestId']; } if (isset($response->getHeaders()['x-dnsme-requestsRemaining'])) { $this->requestsRemaining = $response->getHeaders()['x-dnsme-requestsRemaining']; } if (isset($response->getHeaders()['x-dnsme-requestLimit'])) { $this->requestLimit = $response->getHeaders()['x-dnsme-requestLimit']; } }
/** * Debug a response. * @param Response $response The driver response object. */ public function response(Response $response) { print '<td style="vertical-align: top; padding: 10px; padding-left: 20px; width: 400px"><h3>Response from server</h3>'; if ($response->getStatusCode() >= 400) { print '<p style="color: red"><strong>' . $response->getStatusCode() . '</strong> ' . $response->getStatus() . '</p>'; } else { print '<p style="color: green"><strong>' . $response->getStatusCode() . '</strong> ' . $response->getStatus() . '</p>'; } //Headers print "<pre>"; foreach ($response->getHeaders() as $header => $value) { print "{$header} : {$value}\n"; } print "</pre>"; //Body if ($response->getBody()) { $body = json_decode($response->getBody()); if ($body) { print "<pre>" . json_encode($body, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "</pre>"; } elseif ($response->getBody()) { print "<pre>" . $response->getBody() . "</pre>"; } } print '<p>Time taken: ' . $response->getTimeTaken() * 1000 . ' ms</pre>'; print "</td></tr></table>"; }
/** * @covers DNSMadeEasy\driver\Response::getHeaders */ public function testGetHeaders() { $this->assertInternalType('array', $this->response->getHeaders(), 'The headers should be an array'); $this->assertNotEmpty($this->response->getHeaders(), 'The headers array should not be empty'); }