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
Fields -
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(@Nullable String baseUrl) Sets the base URL to be used by theCfDnsClient.withConnectTimeout(Duration connectTimeout) Sets the timeout for establishing a connection.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`.withResponseTimeout(Duration responseTimeout) Sets the timeout for waiting for the response data.
-
Field Details
-
DEFAULT_BASEURL
The default base URL for the Cloudflare v4 API requests made by theCfDnsClient.- See Also:
-
DEFAULT_CONNECT_TIMEOUT
The default timeout for establishing a connection. -
DEFAULT_RESPONSE_TIMEOUT
The default timeout for waiting for the response data.
-
-
Constructor Details
-
CfDnsClientBuilder
public CfDnsClientBuilder()
-
-
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.Only HTTPS URLs with a host are accepted. User information, query parameters and fragments are not permitted. Credentials are sent to the configured host, so only use trusted URLs.
- Parameters:
baseUrl- the base URL to be used for API requests,nullresets it toDEFAULT_BASEURL- Returns:
- the current instance of
CfDnsClientBuilder, enabling method chaining - Throws:
IllegalArgumentException- if the URL is invalid, doesn't use HTTPS, has no host or contains user information, a query or a fragment
-
withConnectTimeout
Sets the timeout for establishing a connection. Default isDEFAULT_CONNECT_TIMEOUT.- Parameters:
connectTimeout- the connect timeout, must be positive- Returns:
- the current instance of
CfDnsClientBuilder, enabling method chaining - Throws:
IllegalArgumentException- if the timeout isnull, zero or negative
-
withResponseTimeout
Sets the timeout for waiting for the response data. Default isDEFAULT_RESPONSE_TIMEOUT.- Parameters:
responseTimeout- the response timeout, must be positive- Returns:
- the current instance of
CfDnsClientBuilder, enabling method chaining - Throws:
IllegalArgumentException- if the timeout isnull, zero or negative
-
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. - Throws:
IllegalStateException- if no authentication was configured
-