Exemplo n.º 1
0
 /**
  * @param string            $message
  * @param RequestInterface  $request
  * @param ResponseInterface $response
  */
 public function __construct($message = null, RequestInterface $request = null, ResponseInterface $response = null)
 {
     $message = $message ?: $this->message;
     if ($request !== null && $response !== null) {
         $details = "[url] " . $request->getUrl();
         $details .= " [status code] " . $response->getStatusCode();
         $details .= " [reason phrase] " . $response->getReasonPhrase();
         $details .= ApiResponseException::getErrorDetails($response);
         $message .= "\nDetails:\n  " . wordwrap($details);
     }
     parent::__construct($message, $this->code);
 }
 /**
  * Get account information for the logged-in user.
  *
  * @param bool $reset
  *
  * @return array
  */
 public function getAccountInfo($reset = false)
 {
     if (!isset($this->accountInfo) || $reset) {
         $client = $this->connector->getClient();
         $url = $this->accountsEndpoint . 'me';
         try {
             $this->accountInfo = (array) $client->get($url)->json();
         } catch (BadResponseException $e) {
             throw ApiResponseException::create($e->getRequest(), $e->getResponse(), $e->getPrevious());
         }
     }
     return $this->accountInfo;
 }
 /**
  * Send a Guzzle request.
  *
  * Using this method allows exceptions to be standardized.
  *
  * @param RequestInterface $request
  * @param ClientInterface  $client
  *
  * @return array
  */
 public static function send(RequestInterface $request, ClientInterface $client)
 {
     $response = null;
     try {
         $response = $client->send($request);
         $data = $response->json();
         return (array) $data;
     } catch (BadResponseException $e) {
         throw ApiResponseException::create($e->getRequest(), $e->getResponse());
     } catch (ParseException $e) {
         throw ApiResponseException::create($request, $response);
     }
 }