/** * Sends a request and returns a response * * @param CartRecover_Request $request * @return Cart_Recover_Response */ public function sendRequest(CartRecover_Request $request) { $this->client->setUri($request->getUri()); $this->client->setParameterGet($request->getParams()); $this->client->setMethod($request->getMethod()); $this->client->setHeaders(array('Accept' => 'application/json')); $this->response = $this->client->send(); if ($this->response->getHeaders()->get('Content-Type')->getFieldValue() != 'application/json') { throw new CartRecover_Exception_UnexpectedValueException("Unknown response format."); } $body = json_decode($this->response->getContent(), true); $response = new CartRecover_Response(); $response->setRawResponse($this->response->toString()); $response->setBody($body); $response->setHeaders($this->response->getHeaders()->toArray()); $response->setStatus($this->response->getReasonPhrase(), $this->response->getStatusCode()); return $response; }