/** * Checks whether to handle this status code. * * @param HttpResponse $response * @return boolean */ public function checkStatusCode(HttpResponse $response) { // Only 200 responses are cached by default if (empty($this->config['http_codes_black_list'])) { return $response->isOk(); } $statusCode = $response->getStatusCode(); return !in_array($statusCode, (array) $this->config['http_codes_black_list']); }
/** * Send Http request to retrieve datas * @access protected * @param string $service Service to call * @param string $type Resource type to retrieve (for search service) * @param array $parameters Parameters used for request * @throws \Zend\Http\Exception\RuntimeException * @return \stdClass */ protected function send($service, $type, $parameters) { // reset old parameters $this->getHttpClient()->resetParameters(); // setup Http headers $headers = array(ContentTypeHeader::fromString('Content-Type: ' . HttpClient::ENC_URLENCODED)); // setup HttpClient $this->getHttpClient()->setMethod(HttpRequest::METHOD_GET); $this->getHttpClient()->setParameterGet($parameters); $this->getHttpClient()->setHeaders($headers); // generate URI and set to HttpClient $this->getHttpClient()->setUri($this->generateURI($service, $type)); // get HttpResponse $this->response = $this->getHttpClient()->send(); // is HttpRequest ok ? if (!$this->response->isOk()) { // throw RuntimeException throw new ZendRuntimeException(sprintf('Invalid status code: %d', $this->response->getStatusCode())); } // return decode object return \Zend\Json\Decoder::decode($this->response->getBody()); }