/** * {@inheritdoc} * @see Scalr\Service\OpenStack\Client.ClientResponseInterface::hasError() */ public function hasError() { if (!isset($this->errorData)) { $this->errorData = false; $code = $this->response->getResponseCode(); if ($code < 200 || $code > 299) { $this->errorData = new ErrorData(); if ($this->format == AppFormat::APP_JSON) { $d = @json_decode($this->getContent()); if ($d === null) { $this->errorData->code = $code; $this->errorData->message = strip_tags($this->getContent()); $this->errorData->details = ''; } else { list(, $v) = each($d); if (is_object($v)) { $this->errorData->code = isset($v->code) ? $v->code : 0; $this->errorData->message = $v->message; $this->errorData->details = isset($v->details) ? (string) $v->details : ''; } else { //QuantumError $this->errorData->code = $code; $this->errorData->message = (string) $v; $this->errorData->details = ''; } } } else { if ($this->format == AppFormat::APP_XML) { $d = simplexml_load_string($this->getContent()); $this->errorData->code = $code; $this->errorData->message = isset($d->message) ? (string) $d->message : ''; $this->errorData->details = isset($d->details) ? (string) $d->details : ''; } else { throw new \InvalidArgumentException(sprintf('Unexpected application format "%s" in class %s', (string) $this->format, get_class($this))); } } throw OpenStackResponseErrorFactory::make($this->errorData); } } return $this->errorData; }
/** * Makes api request * * @param string $qid The id of the query. * @param array $options optional Query options for the request. * @param string $path optional Uri path for the request (/user by default) * @param string $method optional Http method (GET by default) * @return object Returns object that is an response data. * @throws CloudynException */ public function call($qid, array $options = array(), $path = '/user', $method = 'GET') { $options['qid'] = (string) $qid; $options['out'] = self::OUT_JSON; if (!isset($options['rqid'])) { $options['rqid'] = $this->getRequestId(); } if (!isset($options['apiversion'])) { $options['apiversion'] = '0.4'; } $this->request = $this->createNewRequest(); $this->request->setRequestUrl($this->getUrl() . $path); $this->request->setRequestMethod($method); $this->request->setOptions(array('redirect' => 10, 'cookiesession' => true)); $this->request->addQuery($options); $this->response = $this->tryCall($this->request); $json = $this->response->getBody()->toString(); $json = preg_replace('#^[^\\{\\[]+|[^\\}\\]]+$#', '', trim($json)); $obj = json_decode($json); if (isset($obj->status) && $obj->status != 'ok' && isset($obj->message)) { throw new CloudynException('Cloudyn error. ' . $obj->message); } return $obj; }
/** * Fetches properties from the response. * * @param \http\Client\Response $response Response * @return array */ protected function getProperties(\http\Client\Response $response) { // Process the XML with properties $properties = array(); $reader = new \Jyxo\XmlReader(); $reader->XML($response->getBody()->toString()); // Ignore warnings while (@$reader->read()) { if (\XMLReader::ELEMENT === $reader->nodeType && 'D:prop' === $reader->name) { while (@$reader->read()) { // Element must not be empty and has to look something like <lp1:getcontentlength>13744</lp1:getcontentlength> if (\XMLReader::ELEMENT === $reader->nodeType && !$reader->isEmptyElement) { if (preg_match('~^lp\\d+:(.+)$~', $reader->name, $matches)) { // Apache $properties[$matches[1]] = $reader->getTextValue(); } elseif (preg_match('~^D:(.+)$~', $reader->name, $matches)) { // Lighttpd $properties[$matches[1]] = $reader->getTextValue(); } } elseif (\XMLReader::END_ELEMENT === $reader->nodeType && 'D:prop' === $reader->name) { break; } } } } return $properties; }
public function getBody() { return $this->_response->getBody()->toString(); }
/** * {@inheritdoc} * @see \Scalr\Service\Azure\Client\ClientResponseInterface::getHeaders() */ public function getHeaders() { return $this->httpResponse->getHeaders(); }
/** * {@inheritdoc} * @see Scalr\Service\Aws\Client.ClientResponseInterface::getResponseStatus() */ public function getResponseStatus() { return $this->response->getResponseStatus(); }