Exemplo n.º 1
0
 public function __construct(TransportResponse $response)
 {
     if (!$response->isSuccessful()) {
         throw new TransportException($response);
     }
     $this->response = $response;
 }
Exemplo n.º 2
0
 public function rev(Response $response)
 {
     if ($response->isSuccessful()) {
         return $this->decode($response->getHeader('Etag'));
     }
     throw new RugException('not_found', 'The specified document or revision cannot be found or has been deleted');
 }
Exemplo n.º 3
0
 public function isSuccessful()
 {
     if (parent::isSuccessful()) {
         $result = $this->getArrayResult();
         return !array_key_exists('error', $result);
     }
     return false;
 }
Exemplo n.º 4
0
 /**
  * @param FormRequest $request
  *
  * @throws HttpException
  *
  * @return array
  */
 protected function doRequest(FormRequest $request)
 {
     $request->setMethod('POST');
     $request->fromUrl($this->getApiEndpoint());
     $this->client->send($request, $response = new Response());
     if (false == $response->isSuccessful()) {
         throw HttpException::factory($request, $response);
     }
     $result = array();
     parse_str($response->getContent(), $result);
     foreach ($result as &$value) {
         $value = urldecode($value);
     }
     return $result;
 }
Exemplo n.º 5
0
Arquivo: Client.php Projeto: rgies/dsp
 /**
  * @param \Buzz\Message\Response $response
  * @throws \InvalidArgumentException
  */
 private function assertRequestIsSuccessful(\Buzz\Message\Response $response)
 {
     $data = json_decode($response->getContent(), true);
     if (!$response->isSuccessful() || !isset($data['success']) || $data['success'] != "true") {
         //XXX Invent Exception fitting here
         throw new \InvalidArgumentException($response->getContent());
     }
 }
Exemplo n.º 6
0
 /**
  * @param \Buzz\Message\Response $response
  *
  * @throws HttpException if status not OK
  * @throws HttpException if content not json
  *
  * @return \stdClass|\stdClass[]|null
  */
 protected function getResult(Response $response)
 {
     if (false == $response->isSuccessful()) {
         throw new HttpException($response->getStatusCode(), sprintf("The api call finished with status %s but it was expected 200. Response content:\n\n%s", $response->getStatusCode(), $response->getContent()));
     }
     $content = $response->getContent();
     $result = null;
     if (false == empty($content)) {
         $result = json_decode($response->getContent());
         if (null === $result) {
             throw new LogicException(sprintf("The response status is successful but the content is not a valid json object:\n\n%s", $response->getContent()));
         }
     }
     return $result;
 }
Exemplo n.º 7
0
 /**
  * @param Response $response
  *
  * @throws HttpException
  */
 protected function handleResponse(Response $response)
 {
     if ($response->isSuccessful()) {
         return;
     }
     $this->handleError($response);
 }
 /**
  * @return bool
  */
 public function isSuccessful()
 {
     return $this->response->isSuccessful();
 }