Class CfDnsClientBuilder

java.lang.Object
codes.thischwa.cf.CfDnsClientBuilder

public class CfDnsClientBuilder extends Object
Builder class for configuring and creating instances of CfDnsClient. This class provides a fluent API for customizing the client settings, such as the base URL and authentication mechanism.
  • Field Details

    • DEFAULT_BASEURL

      public static final String DEFAULT_BASEURL
      The default base URL for the Cloudflare v4 API requests made by the CfDnsClient.
      See Also:
    • DEFAULT_CONNECT_TIMEOUT

      public static final Duration DEFAULT_CONNECT_TIMEOUT
      The default timeout for establishing a connection.
    • DEFAULT_RESPONSE_TIMEOUT

      public static final Duration DEFAULT_RESPONSE_TIMEOUT
      The default timeout for waiting for the response data.
  • Constructor Details

    • CfDnsClientBuilder

      public CfDnsClientBuilder()
  • Method Details

    • withEmptyResultThrowsException

      public CfDnsClientBuilder withEmptyResultThrowsException(boolean emptyResultThrowsException)
      Configures whether an exception should be thrown when an empty result is encountered during operations performed by the `CfDnsClient`.
      Parameters:
      emptyResultThrowsException - a boolean flag indicating if an exception should be thrown when an empty result is returned. If set to `true`, operations that result in an empty response will throw an exception; otherwise, they will not.
      Returns:
      the current instance of CfDnsClientBuilder, allowing for method chaining to further configure the builder.
    • withBaseUrl

      public CfDnsClientBuilder withBaseUrl(@Nullable @Nullable String baseUrl)
      Sets the base URL to be used by the CfDnsClient. This method allows configuring the base URL for API requests, overriding any default value.

      To protect the credentials, the URL must use HTTPS. Plain HTTP is only allowed for loopback hosts (e.g. localhost) for testing purposes.

      Parameters:
      baseUrl - the base URL to be used for API requests, null resets it to DEFAULT_BASEURL
      Returns:
      the current instance of CfDnsClientBuilder, enabling method chaining
      Throws:
      IllegalArgumentException - if the URL is invalid or doesn't use HTTPS
    • withConnectTimeout

      public CfDnsClientBuilder withConnectTimeout(Duration connectTimeout)
      Sets the timeout for establishing a connection. Default is DEFAULT_CONNECT_TIMEOUT.
      Parameters:
      connectTimeout - the connect timeout, must be positive
      Returns:
      the current instance of CfDnsClientBuilder, enabling method chaining
      Throws:
      IllegalArgumentException - if the timeout is null, zero or negative
    • withResponseTimeout

      public CfDnsClientBuilder withResponseTimeout(Duration responseTimeout)
      Sets the timeout for waiting for the response data. Default is DEFAULT_RESPONSE_TIMEOUT.
      Parameters:
      responseTimeout - the response timeout, must be positive
      Returns:
      the current instance of CfDnsClientBuilder, enabling method chaining
      Throws:
      IllegalArgumentException - if the timeout is null, zero or negative
    • withApiTokenAuth

      public CfDnsClientBuilder withApiTokenAuth(String apiToken)
      Configures the authentication method for the CfDnsClient to use an API token. This is the recommended way to authenticate with the Cloudflare API, as it provides enhanced security and ease of use compared to other authentication mechanisms.
      Parameters:
      apiToken - the Cloudflare API token. This token is required for authenticating API requests and must not be null or blank.
      Returns:
      the current instance of CfDnsClientBuilder, allowing for method chaining to further configure the builder.
      Throws:
      IllegalArgumentException - if the apiToken is null or blank.
    • withEmailKeyAuth

      public CfDnsClientBuilder withEmailKeyAuth(String authEmail, String authKey)
      Configures the authentication method for the CfDnsClient to use an email and API key. This approach uses the legacy authentication mechanism provided by Cloudflare, where requests are authenticated with a combination of an account's email address and API key.
      Parameters:
      authEmail - the email address associated with the Cloudflare account. This must not be null or blank.
      authKey - the API key of the Cloudflare account. This must not be null or blank.
      Returns:
      the current instance of CfDnsClientBuilder, allowing for method chaining to further configure the builder.
      Throws:
      IllegalArgumentException - if authEmail or authKey is null or blank.
    • build

      public CfDnsClient build()
      Builds and returns a configured instance of CfDnsClient.

      The method constructs a new CfDnsClient object based on the options set in the CfDnsClientBuilder. If no base URL has been explicitly configured, a default base URL will be used.

      Returns:
      a new instance of CfDnsClient configured with the specified options such as base URL, authentication details, and the exception-handling policy for empty results.
      Throws:
      IllegalStateException - if no authentication was configured