/** * @inheritdoc */ protected function _processResponse($value, Request $request, $type = self::MASTER_REQUEST, $catch = true, $params = []) { if ($value instanceof ApiResponseInterface) { $format = new JsonFormat(); $value = Response::create($format->encode($value->toArray(), 200, '', '\\' . get_class($value))); $value->headers->set("Content-Type", "application/json"); } return parent::_processResponse($value, $request, $type, $catch, $params); }
/** * @param \Packaged\Api\Interfaces\ApiRequestInterface $request * * @return \Packaged\Api\Interfaces\ApiResponseInterface */ public function processRequest(ApiRequestInterface $request) { $apiRequest = $this->_createRequest($request); $time = microtime(true); try { $response = $this->_getClient()->send($apiRequest); } catch (ClientException $e) { $response = $e->getResponse(); } $response = $this->_processResponse($response); $totalTime = microtime(true) - $time; $format = new JsonFormat(); return $format->decode($response, number_format($totalTime * 1000, 3)); }
protected function fetchProviderData($url, array $headers = []) { $time = microtime(true); try { $client = $this->getHttpClient(); $client->setBaseUrl($url); if ($headers) { $client->setDefaultOption('headers', $headers); } $request = $client->get()->send(); $response = $request->getBody(); } catch (BadResponseException $e) { // @codeCoverageIgnoreStart $decode = new JsonFormat(); try { $totalTime = microtime(true) - $time; $response = $decode->decode(new Response($e->getResponse()->getStatusCode(), $e->getResponse()->getHeaders()->getAll(), new Stream($e->getResponse()->getBody()->getStream())), $totalTime); throw new \Exception($response->getApiCallData()->getStatusMessage(), $response->getApiCallData()->getStatusCode(), $e); } catch (InvalidApiResponseException $ex) { $raw_response = explode("\n", $e->getResponse()); throw new IDPException(end($raw_response)); } // @codeCoverageIgnoreEnd } return $response; }