Exemplo n.º 1
0
 /**
  * @param Event $event
  * @throws ApiLimitExceedException
  * @throws NotFoundException
  * @throws RuntimeException
  */
 public function onRequestError(Event $event)
 {
     /** @var $request \Guzzle\Http\Message\Request */
     $request = $event['request'];
     $response = $request->getResponse();
     if ($response->isClientError() || $response->isServerError()) {
         if (403 === $response->getStatusCode()) {
             $limit = (int) $response->getHeader('X-Rate-Limit-Limit');
             $remaining = (int) $response->getHeader('X-Rate-Limit-Remaining');
             $reset = (int) $response->getHeader('X-Rate-Limit-Reset');
             if ($limit === 0) {
                 throw new ApiLimitExceedException("X-Rate-Limit-Limit retched : 600 requests authorized", 403);
             } elseif ($remaining === 0) {
                 throw new ApiLimitExceedException("X-Rate-Limit-Remaining retched : 10 requests per second authorized. You need to wait {$reset} seconds", 403);
             }
         }
         if (404 === $response->getStatusCode() && $response->getHeader('reasonCode')) {
             throw new NotFoundException($response->getHeader('reasonCode'), 404);
         }
         $content = ResponseMediator::getContent($response);
         throw new RuntimeException(isset($content['message']) ? $content['message'] : $content, $response->getStatusCode());
     }
 }
Exemplo n.º 2
0
 /**
  * Send a DELETE request with JSON-encoded parameters.
  *
  * @param string $path           Request path.
  * @param array  $parameters     POST parameters to be JSON encoded.
  * @param array  $requestHeaders Request headers.
  */
 protected function delete($path, array $parameters = array(), $requestHeaders = array())
 {
     $response = $this->client->getHttpClient()->delete($path, $this->createJsonBody($parameters), $requestHeaders);
     return ResponseMediator::getContent($response);
 }