Class ApiClientBuilder

java.lang.Object
ru.loolzaaa.youkassa.client.ApiClientBuilder

public class ApiClientBuilder extends Object
This class implement builder pattern for ApiClient.

Compared with constructor creation of ApiClient, this option additionally provides some sanity checks.

Usage:

 
 ApiClient client = ApiClientBuilder.newBuilder()
     .configureBasicAuth("shop_id", "secret_key")
     .build();
 
 
See Also:
  • Method Details

    • apiUrl

      public ApiClientBuilder apiUrl(String apiUrl)
      Sets API url endpoint for client.
      Parameters:
      apiUrl - api endpoint url
      Returns:
      builder itself
    • configureBasicAuth

      public ApiClientBuilder configureBasicAuth(String accountId, String secretKey)
      Authentication configuration via Basic auth method.

      Only one method (Basic/OAuth) of authentication can be configured.

      Parameters:
      accountId - id of yookassa shop/account
      secretKey - secret key of yookassa shop/account
      Returns:
      builder itself
      Throws:
      IllegalArgumentException - if OAuth token not null
    • configureOAuth

      public ApiClientBuilder configureOAuth(String authToken)
      Authentication configuration via OAuth method.

      Only one method (Basic/OAuth) of authentication can be configured.

      Parameters:
      authToken - OAuth client token
      Returns:
      builder itself
      Throws:
      IllegalArgumentException - if accountId or secretKey not null
    • build

      public ApiClient build()
      Created ApiClient instance.

      Construct authentication header value supplier based on configured authentication method.

      Returns:
      instance of ApiClient
      Throws:
      IllegalArgumentException - if authentication not configured
    • newBuilder

      public static ApiClientBuilder newBuilder()
      Creates new builder for ApiClient.
      Returns:
      new builder instance