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:
  • Constructor Details

    • CfDnsClientBuilder

      public CfDnsClientBuilder()
      Constructs a new instance of `CfDnsClientBuilder`.

      This class serves as a builder for creating and configuring instances of a CfDnsClient. It provides a fluent API to set various optional configurations, such as API authentication methods and base URL, before constructing the client.

      By using this constructor, you can initiate the building process with default settings, which can later be overridden using the provided builder methods.

  • 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(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.
      Parameters:
      baseUrl - the base URL to be used for API requests
      Returns:
      the current instance of CfDnsClientBuilder, enabling method chaining
    • 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.