public static function factory(RequestInterface $request, Response $response)
 {
     $e = new self('Not Found');
     $e->setResponse($response);
     $e->setRequest($request);
     return $e;
 }
 public static function fromBadResponseException(BadResponseException $old)
 {
     $new = new self($old->getMessage());
     $new->setRequest($old->getRequest());
     $new->setResponse($old->getResponse());
     return $new;
 }
 public static function factory(BadResponseException $exception)
 {
     $response = $exception->getResponse();
     $message = sprintf("This operation was forbidden; the API returned a %s status code with this message:\n%s", $response->getStatusCode(), (string) $response->getBody());
     $e = new self($message);
     $e->setResponse($response);
     $e->setRequest($exception->getRequest());
     return $e;
 }
 public static function factory(BadResponseException $exception)
 {
     $response = $exception->getResponse();
     $message = sprintf("This resource you were looking for could not be found; the API returned a %s status code with this message:\n%s", $response->getStatusCode(), (string) $response->getBody());
     $e = new self($message);
     $e->setResponse($response);
     $e->setRequest($exception->getRequest());
     return $e;
 }
 /**
  * Factory method to create an instance of this class from a FedEx response
  * object.
  *
  * @param  ResponseInterface $response The response object to get errors from
  *
  * @return ResponseErrorException
  */
 public static function createFromResponse(ResponseInterface $response)
 {
     $messages = array();
     foreach ($response->getNotifications()->getBySeverity(array('FAILURE', 'ERROR')) as $n) {
         $messages[] = sprintf('%s: (%s) %s', $n->severity, $n->code, $n->message);
     }
     $exception = new self(sprintf('FedEx API Request Failure: %s', implode(', ', $messages)));
     $exception->setResponse($response);
     return $exception;
 }
 /**
  * @param Response $response
  *
  * @return RepositoryResponse
  */
 public static function fromResponse(Response $response)
 {
     $self = new self();
     $error = new Error();
     $self->setSuccessful(false);
     $responseContent = self::getResponseContent($response);
     $self->setResponse($responseContent);
     $responseArray = json_decode($responseContent, true);
     if (isset($responseArray['response']['status'])) {
         $self->setSuccessful($responseArray['response']['status'] == self::STATUS_SUCCESS);
     }
     if (!$self->isSuccessful()) {
         $error = Error::fromArray($responseArray['response']);
     }
     $self->setError($error);
     return $self;
 }
 public static function factory(RequestInterface $request, Response $response)
 {
     if ($response->isClientError()) {
         $label = 'Client error response';
         $class = __NAMESPACE__ . '\\ClientErrorResponseException';
     } elseif ($response->isServerError()) {
         $label = 'Server error response';
         $class = __NAMESPACE__ . '\\ServerErrorResponseException';
     } else {
         $label = 'Unsuccessful response';
         $class = __CLASS__;
     }
     $message = $label . PHP_EOL . implode(PHP_EOL, array('[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
     $e = new self($message);
     $e->setResponse($response);
     $e->setRequest($request);
     return $e;
 }
 /**
  * Create instance of self
  *
  * @param string $response
  * @param string $url
  * @param array $post_data
  *
  * @return \Namecheap\Connect\NamecheapResponse
  */
 private static function instantiateSelf($response, $url, $post_data)
 {
     $instance = new self();
     $instance->setResponse($response);
     $instance->setUrl($url);
     $instance->setPostData($post_data);
     return $instance;
 }
 /**
  * {@inheritdoc}
  */
 public static function fromArray(array $values)
 {
     $message = new self();
     $values = array_merge(['type' => null, 'response' => null], $values);
     $message->setType($values['type']);
     $message->setResponse($values['response']);
     return $message;
 }