/**
  * Execute an API call using a certain method
  *
  * @param ApiCallInterface $call The API call
  *
  * @return string The parsed response of the API call
  */
 public function call(ApiCallInterface $call)
 {
     if ($call instanceof CurlCall) {
         if ($this->freshConnect || $this->engine == null || !$this->engine instanceof Curl) {
             $this->engine = new Curl();
         }
     } else {
         if ($this->freshConnect || $this->engine == null || !$this->engine instanceof \SoapClient) {
             $this->engine = new \SoapClient($call->getUrl());
         }
     }
     if ($this->logger) {
         $this->logger->startCall($call);
     }
     $this->lastCall = $call;
     $result = $call->execute($this->options, $this->engine, $this->freshConnect);
     if ($this->logger) {
         $this->logger->stopCall($call);
     }
     if ($call instanceof CurlCall) {
         if ($this->freshConnect) {
             $this->engine->close();
         }
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function stopCall(ApiCallInterface $call)
 {
     $status = $call->getStatus();
     $responseData = $call->getResponseData();
     $responseObject = $call->getResponseObjectRepresentation();
     $executionMS = microtime(true) - $this->start;
     $this->calls[$this->currentCall] += compact('status', 'responseData', 'responseObject', 'executionMS');
     if (null !== $this->logger) {
         $type = $this->calls[$this->currentCall]['type'];
         $url = $this->calls[$this->currentCall]['url'];
         $requestData = $this->calls[$this->currentCall]['requestData'];
         $responseDataLength = strlen($responseData);
         $executionMS = sprintf('%0.2f', $executionMS * 1000);
         $this->logger->debug("API call \"{$type}\" requested \"{$url}?{$requestData}\" that returned \"{$status}\" in {$executionMS} ms sending {$responseDataLength} bytes");
     }
 }