You are here

public function SDKConnector::buildClient in Apigee Edge 8

Same name in this branch
  1. 8 src/SDKConnector.php \Drupal\apigee_edge\SDKConnector::buildClient()
  2. 8 tests/modules/apigee_edge_test/src/SDKConnector.php \Drupal\apigee_edge_test\SDKConnector::buildClient()

Returns a pre-configured API client with the provided credentials.

Parameters

\Http\Message\Authentication $authentication: Authentication.

null|string $endpoint: API endpoint, default is https://api.enterprise.apigee.com/v1.

array $options: Client configuration option.

Return value

\Apigee\Edge\ClientInterface Configured API client.

Overrides SDKConnector::buildClient

File

tests/modules/apigee_edge_test/src/SDKConnector.php, line 87

Class

SDKConnector
Service decorator for SDKConnector.

Namespace

Drupal\apigee_edge_test

Code

public function buildClient(Authentication $authentication, ?string $endpoint = NULL, array $options = []) : ClientInterface {
  $decider = function (RequestInterface $request, Exception $e) {

    // Only retry API calls that failed with this specific error.
    if ($e instanceof ApiResponseException && $e
      ->getEdgeErrorCode() === 'messaging.adaptors.http.flow.ApplicationNotFound') {
      $this->logger
        ->warning('Restarting request because it failed. {error_code}: {exception}.', [
        'error_code' => $e
          ->getEdgeErrorCode(),
        'exception' => $e
          ->getMessage(),
      ]);
      return TRUE;
    }
    return FALSE;
  };

  // Use the retry plugin in tests.
  return $this->innerService
    ->buildClient($authentication, $endpoint, [
    Client::CONFIG_RETRY_PLUGIN_CONFIG => [
      'retries' => 5,
      'exception_decider' => $decider,
      'exception_delay' => function (RequestInterface $request, Exception $e, $retries) : int {
        return $retries * 15000000;
      },
    ],
  ]);
}