/**
  * {@inheritdoc}
  */
 public function sendRequest($body)
 {
     $stopwatchId = uniqid('speicher210_fastbill.collector.transport.');
     $this->stopwatch->start($stopwatchId);
     $return = $this->service->sendRequest($body);
     $stop = $this->stopwatch->stop($stopwatchId);
     $this->requests[] = array('time' => $stop->getDuration(), 'request' => json_decode($body, true), 'response' => json_decode($return, true));
     return $return;
 }
 /**
  * Send a request to fastbill.
  *
  * @param mixed $request The request to send.
  * @param string $responseClass The class that should be used to unserialize the response.
  * @return ApiResponseInterface
  */
 protected function sendRequest(RequestInterface $request, $responseClass)
 {
     if (!in_array(ApiResponseInterface::class, class_implements($responseClass))) {
         throw new \InvalidArgumentException('The response class must implement "' . ApiResponseInterface::class . '".');
     }
     $body = $this->serializer->serialize($request, 'json');
     $response = $this->transport->sendRequest($body);
     return $this->serializer->deserialize($response, $responseClass, 'json');
 }
예제 #3
0
 /**
  * Send a request to fastbill.
  *
  * @param mixed $request The request to send.
  * @param string $responseClass The class that should be used to unserialize the response.
  * @return ApiResponseInterface
  * @throws ApiResponseException If the API response has errors.
  */
 protected function sendRequest(RequestInterface $request, $responseClass)
 {
     if (!in_array(ApiResponseInterface::class, class_implements($responseClass))) {
         throw new \InvalidArgumentException('The response class must implement "' . ApiResponseInterface::class . '".');
     }
     $body = $this->serializer->serialize($request, 'json');
     $response = $this->transport->sendRequest($body);
     /** @var ApiResponseInterface $apiResponse */
     $apiResponse = $this->serializer->deserialize($response, $responseClass, 'json');
     if ($apiResponse->getResponse() !== null && $apiResponse->getResponse()->hasErrors()) {
         throw new ApiResponseException(sprintf('Error calling "%s"', $request->getService()), $apiResponse->getResponse()->getErrors());
     }
     return $apiResponse;
 }