/** * {@inheritDoc} */ public function execute(Request $request) { $this->client->setCookieJar(); $this->client->resetParameters(); $this->client->setUri($this->getUri($request->getMethod(), $request->getParam('apikey'))); $this->client->setParameterPost($request->getParams()); try { $rawResponse = $this->client->request(HttpClient::POST); $response = unserialize($rawResponse->getBody()); if (false === $response) { // bad response $response = array('error' => 'Bad Response. Got this: ' . $rawResponse->getBody(), 'code' => -99); } } catch (\Exception $e) { if ($e instanceof TimeoutException) { // timeout exception $response = array('error' => 'Could not read response (timed out)', 'code' => -98); } else { // unknown exception $response = array('error' => 'An error occured: ' . $e->getMessage(), 'code' => -99); } } if (is_array($response) && isset($response['error'])) { // return an error response return new Response($response, Response::STATUS_ERROR); } // return a success response return new Response($response); }
/** * Perform the given Request * * @param Request $request * * @return Response */ public function call(Request $request) { $this->errorMessage = null; $this->errorCode = null; $request->setParam('apikey', $this->api_key); $response = $this->connection->execute($request); if ($response->isError()) { $content = $response->getContent(); $this->errorMessage = $content["error"]; $this->errorCode = $content["code"]; } $this->lastRequest = $request; $this->lastResponse = $response; return $response; }