Example #1
0
 /** @test */
 public function itThrowAnExceptionWhenNoRequestDefinitionIsFound()
 {
     $this->expectException(\InvalidArgumentException::class);
     $this->expectExceptionMessage('Unable to get the request definition for getPet');
     $requests = $this->prophesize(RequestDefinitions::class);
     $requests->getIterator()->willReturn(new \ArrayIterator());
     $schema = new Schema($requests->reveal(), '/api');
     $schema->getRequestDefinition('getPet');
 }
Example #2
0
 /**
  * Make an asynchronous 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 Promise
  */
 public function callAsync($operationId, array $params = [])
 {
     if (!$this->client instanceof HttpAsyncClient) {
         throw new \RuntimeException(sprintf('"%s" does not support async request', get_class($this->client)));
     }
     $requestDefinition = $this->schema->getRequestDefinition($operationId);
     $request = $this->createRequestFromDefinition($requestDefinition, $params);
     $promise = $this->client->sendAsyncRequest($request);
     return $promise->then(function (ResponseInterface $response) use($request, $requestDefinition) {
         return $this->getDataFromResponse($response, $requestDefinition->getResponseDefinition($response->getStatusCode()), $request);
     });
 }