Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function sendRequest(RequestInterface $request)
 {
     // If we don't have an http client, use the async call
     if (!$this->client instanceof HttpClient) {
         return $this->sendAsyncRequest($request)->wait();
     }
     // Else we want to use the synchronous call of the underlying client, and not the async one in the case
     // we have both an async and sync call
     $pluginChain = $this->createPluginChain($this->plugins, function (RequestInterface $request) {
         try {
             return new FulfilledPromise($this->client->sendRequest($request));
         } catch (Exception $exception) {
             return new RejectedPromise($exception);
         }
     });
     return $pluginChain($request)->wait();
 }
Exemplo n.º 2
0
 /**
  * Make a synchronous call to the API
  *
  * @param string $operationId The name of your operation as described in the API Schema
  * @param array $params An array of request parameters
  *
  * @return mixed
  */
 public function call($operationId, array $params = [])
 {
     $requestDefinition = $this->schema->getRequestDefinition($operationId);
     $request = $this->createRequestFromDefinition($requestDefinition, $params);
     $this->validateRequest($request, $requestDefinition);
     $response = $this->client->sendRequest($request);
     $this->validateResponse($response, $requestDefinition);
     $data = $this->getDataFromResponse($response, $requestDefinition->getResponseDefinition($response->getStatusCode()), $request);
     return $data;
 }