コード例 #1
0
ファイル: AbstractApi.php プロジェクト: packaged/api
 /**
  * @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));
 }
コード例 #2
0
ファイル: FortifiProvider.php プロジェクト: fortifi/sdk
 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;
 }