Package codes.thischwa.cf
Class CfDnsClientBuilder
java.lang.Object
codes.thischwa.cf.CfDnsClientBuilder
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default base URL for the Cloudflare v4 API requests made by theCfDnsClient. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds and returns a configured instance ofCfDnsClient.withApiTokenAuth(String apiToken) Configures the authentication method for theCfDnsClientto use an API token.withBaseUrl(String baseUrl) Sets the base URL to be used by theCfDnsClient.withEmailKeyAuth(String authEmail, String authKey) Configures the authentication method for theCfDnsClientto use an email and API key.withEmptyResultThrowsException(boolean emptyResultThrowsException) Configures whether an exception should be thrown when an empty result is encountered during operations performed by the `CfDnsClient`.
-
Field Details
-
DEFAULT_BASEURL
The default base URL for the Cloudflare v4 API requests made by theCfDnsClient.- 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
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
Sets the base URL to be used by theCfDnsClient. 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
Configures the authentication method for theCfDnsClientto 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 theapiTokenis null or blank.
-
withEmailKeyAuth
Configures the authentication method for theCfDnsClientto 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- ifauthEmailorauthKeyis null or blank.
-
build
Builds and returns a configured instance ofCfDnsClient.The method constructs a new
CfDnsClientobject based on the options set in theCfDnsClientBuilder. If no base URL has been explicitly configured, a default base URL will be used.- Returns:
- a new instance of
CfDnsClientconfigured with the specified options such as base URL, authentication details, and the exception-handling policy for empty results.
-