/** * Factory method that allows for easy instantiation from a Response object. * * @param Response $response * @param AbstractService $service * @return static */ public static function fromResponse(Response $response, AbstractService $service) { $object = new static($service); if (null !== ($headers = $response->getHeaders())) { $object->setMetadata($headers, true); } return $object; }
public function setConfiguration(array $params = array()) { foreach ($params as $status => $config) { if (Response::isValidStatus($status)) { $this->template[$status] = $config; } } return $this; }
public function onRequestCompletion(Event $event) { $this->setResponse(Response::fromParent($event['response'])); if (null === $this->exceptionHandler) { $this->setExceptionHandler(); } $handlerResponse = $this->exceptionHandler->setRequest($event['request'])->setResponse($event['response'])->setExpectedResponse($this->expectedResponse)->handle(); if ($handlerResponse instanceof RequestException) { throw $handlerResponse; } elseif (is_callable($handlerResponse)) { // @codeCoverageIgnoreStart return call_user_func($handlerResponse, $event['response']); // @codeCoverageIgnoreEnd } }
/** * Takes a response and stocks common values from both the body and the headers. * * @param Response $response * @return $this */ public function populateFromResponse(Response $response) { $this->content = $response->getBody(); $headers = $response->getHeaders(); return $this->setMetadata($headers, true)->setContentType((string) $headers['Content-type'])->setLastModified((string) $headers['Last-Modified'])->setContentLength((string) $headers['Content-Length'])->setEtag((string) $headers['ETag']); }
/** * Construct a TransferPart from a HTTP response delivered by the API. * * @param Response $response * @param int $partNumber * @return TransferPart */ public static function fromResponse(Response $response, $partNumber = 1) { $responseUri = Url::factory($response->getEffectiveUrl()); $object = new self(); $object->setPartNumber($partNumber)->setContentLength($response->getHeader('Content-Length'))->setETag($response->getHeader('ETag'))->setPath($responseUri->getPath()); return $object; }
public function parseResponse(Response $response) { $body = $response->getDecodedBody(); $top = $this->jsonName(); if ($top && isset($body->{$top})) { $content = $body->{$top}; } else { $content = $body; } return $content; }