diff --git a/src/main/java/codes/thischwa/cf/CfBasicHttpClient.java b/src/main/java/codes/thischwa/cf/CfBasicHttpClient.java index 9fc7c14..21f8c6e 100644 --- a/src/main/java/codes/thischwa/cf/CfBasicHttpClient.java +++ b/src/main/java/codes/thischwa/cf/CfBasicHttpClient.java @@ -34,7 +34,7 @@ abstract class CfBasicHttpClient { private final ObjectMapper objectMapper; CfBasicHttpClient(String baseUrl, String authEmail, String authKey) - throws IllegalArgumentException { + throws IllegalArgumentException { if (authEmail == null || authEmail.isBlank()) { throw new IllegalArgumentException("Authentication email must not be null or blank!"); } @@ -60,12 +60,12 @@ abstract class CfBasicHttpClient { private T executeRequest(ClassicHttpRequest request, Class responseType) - throws CloudflareApiException { + throws CloudflareApiException { String logUri = null; try (CloseableHttpClient client = createHttpClient()) { ResultWrapper result = client.execute(request, - (ClassicHttpResponse response) -> new ResultWrapper(response.getCode(), - EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8))); + (ClassicHttpResponse response) -> new ResultWrapper(response.getCode(), + EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8))); T respObj = objectMapper.readValue(result.responseBody, responseType); @@ -79,9 +79,9 @@ abstract class CfBasicHttpClient { return respObj; } else { log.error("{} request failed for URL {}: Status {}", request.getMethod(), request.getUri(), - result.statusCode); + result.statusCode); throw new CloudflareApiException( - request.getMethod() + " request failed with status code: " + result.statusCode); + request.getMethod() + " request failed with status code: " + result.statusCode); } } catch (JsonProcessingException e) { log.error("JSON parsing error for request to {}", logUri, e); @@ -95,7 +95,7 @@ abstract class CfBasicHttpClient { * Sends a GET request to the given endpoint and maps the response. */ T getRequest(String endpoint, Class responseType) - throws CloudflareApiException { + throws CloudflareApiException { HttpGet request = new HttpGet(buildUrl(endpoint)); return executeRequest(request, responseType); } @@ -115,7 +115,7 @@ abstract class CfBasicHttpClient { T postRequest(String endpoint, Object requestPayload, Class responseType) - throws CloudflareApiException { + throws CloudflareApiException { HttpPost request = new HttpPost(buildUrl(endpoint)); setRequestPayload(request, requestPayload); return executeRequest(request, responseType); @@ -127,7 +127,7 @@ abstract class CfBasicHttpClient { T putRequest(String endpoint, Object requestPayload, Class responseType) - throws CloudflareApiException { + throws CloudflareApiException { HttpPut request = new HttpPut(buildUrl(endpoint)); setRequestPayload(request, requestPayload); return executeRequest(request, responseType); @@ -138,7 +138,7 @@ abstract class CfBasicHttpClient { */ T patchRequest(String endpoint, Object requestPayload) - throws CloudflareApiException { + throws CloudflareApiException { HttpPatch request = new HttpPatch(buildUrl(endpoint)); setRequestPayload(request, requestPayload); return executeRequest(request, (Class) codes.thischwa.cf.model.RecordSingleResponse.class); @@ -149,12 +149,12 @@ abstract class CfBasicHttpClient { */ private void setRequestPayload(BasicClassicHttpRequest request, Object requestPayload) - throws CloudflareApiException { + throws CloudflareApiException { try { String jsonPayload = objectMapper.writeValueAsString(requestPayload); log.debug("Request payload: {}", jsonPayload); request.setEntity(new StringEntity(jsonPayload, - ContentType.APPLICATION_JSON)); + ContentType.APPLICATION_JSON)); } catch (JsonProcessingException e) { throw new CloudflareApiException("Error serializing JSON payload", e); } diff --git a/src/main/java/codes/thischwa/cf/CfDnsClient.java b/src/main/java/codes/thischwa/cf/CfDnsClient.java index 5e5c966..5ec2a21 100644 --- a/src/main/java/codes/thischwa/cf/CfDnsClient.java +++ b/src/main/java/codes/thischwa/cf/CfDnsClient.java @@ -106,6 +106,10 @@ public class CfDnsClient extends CfBasicHttpClient { this.responseValidator = new ResponseValidator(emptyResultThrowsException); } + private static String buildFqdn(ZoneEntity zone, String sld) { + return sld + "." + zone.getName(); + } + /** * Retrieves a list of all zones from the Cloudflare API. * @@ -376,10 +380,6 @@ public class CfDnsClient extends CfBasicHttpClient { checkResponse(resp); } - private static String buildFqdn(ZoneEntity zone, String sld) { - return sld + "." + zone.getName(); - } - private void checkResponse(AbstractResponse resp) throws CloudflareApiException { checkResponse(resp, false); } diff --git a/src/main/java/codes/thischwa/cf/CfRequest.java b/src/main/java/codes/thischwa/cf/CfRequest.java index 8a2a626..89cc689 100644 --- a/src/main/java/codes/thischwa/cf/CfRequest.java +++ b/src/main/java/codes/thischwa/cf/CfRequest.java @@ -9,7 +9,9 @@ import lombok.Getter; @Getter public enum CfRequest { - /** Represents the API endpoint path for retrieving the list of DNS zones. */ + /** + * Represents the API endpoint path for retrieving the list of DNS zones. + */ ZONE_LIST("/zones"), /** * Represents the API endpoint path for retrieving information about a specific DNS zone by its @@ -69,7 +71,7 @@ public enum CfRequest { * arguments. * * @param vars the arguments to format the path string with; these are typically specific - * identifiers or parameters required by the API endpoint. + * identifiers or parameters required by the API endpoint. * @return the fully constructed API endpoint path as a string. */ String buildPath(Object... vars) { diff --git a/src/main/java/codes/thischwa/cf/CloudflareApiException.java b/src/main/java/codes/thischwa/cf/CloudflareApiException.java index 136d68c..30e83ef 100644 --- a/src/main/java/codes/thischwa/cf/CloudflareApiException.java +++ b/src/main/java/codes/thischwa/cf/CloudflareApiException.java @@ -7,7 +7,8 @@ import java.io.Serial; */ public class CloudflareApiException extends Exception { - @Serial private static final long serialVersionUID = 1L; + @Serial + private static final long serialVersionUID = 1L; /** * Constructs a new CloudflareApiException with the specified detail message. @@ -22,9 +23,9 @@ public class CloudflareApiException extends Exception { * Constructs a new CloudflareApiException with the specified detail message and cause. * * @param message the detail message, which provides additional context or information about the - * exception. - * @param cause the cause of this exception, which is the underlying throwable that triggered this - * exception. + * exception. + * @param cause the cause of this exception, which is the underlying throwable that triggered this + * exception. */ public CloudflareApiException(String message, Throwable cause) { super(message, cause); diff --git a/src/main/java/codes/thischwa/cf/CloudflareNotFoundException.java b/src/main/java/codes/thischwa/cf/CloudflareNotFoundException.java index b57c0c1..ce744bc 100644 --- a/src/main/java/codes/thischwa/cf/CloudflareNotFoundException.java +++ b/src/main/java/codes/thischwa/cf/CloudflareNotFoundException.java @@ -13,7 +13,7 @@ public class CloudflareNotFoundException extends CloudflareApiException { * Constructs a new CloudflareNotFoundException with the specified detail message. * * @param message the detail message, which provides additional context about the "not found" - * error encountered during interaction with the Cloudflare API. + * error encountered during interaction with the Cloudflare API. */ public CloudflareNotFoundException(String message) { super(message); @@ -23,9 +23,9 @@ public class CloudflareNotFoundException extends CloudflareApiException { * Constructs a new CloudflareNotFoundException with the specified detail message and cause. * * @param message the detail message, which provides additional context about the "not found" - * error encountered during interaction with the Cloudflare API. - * @param cause the cause of this exception, which is the underlying throwable that triggered this - * exception. + * error encountered during interaction with the Cloudflare API. + * @param cause the cause of this exception, which is the underlying throwable that triggered this + * exception. */ public CloudflareNotFoundException(String message, Throwable cause) { super(message, cause); diff --git a/src/main/java/codes/thischwa/cf/model/AbstractMultipleResponse.java b/src/main/java/codes/thischwa/cf/model/AbstractMultipleResponse.java index 2235e69..bc6e310 100644 --- a/src/main/java/codes/thischwa/cf/model/AbstractMultipleResponse.java +++ b/src/main/java/codes/thischwa/cf/model/AbstractMultipleResponse.java @@ -24,7 +24,7 @@ import lombok.EqualsAndHashCode; *

Subclasses can be created by specifying the entity type that the response should handle. * * @param Represents the type of entities contained within the response. For this class, it is - * expected to be {@code ResponseEntity}. + * expected to be {@code ResponseEntity}. */ @EqualsAndHashCode(callSuper = true) @Data diff --git a/src/main/java/codes/thischwa/cf/model/BatchResponse.java b/src/main/java/codes/thischwa/cf/model/BatchResponse.java index 07fc02c..d66b892 100644 --- a/src/main/java/codes/thischwa/cf/model/BatchResponse.java +++ b/src/main/java/codes/thischwa/cf/model/BatchResponse.java @@ -1,5 +1,15 @@ package codes.thischwa.cf.model; +/** + * Represents a response that contains a single {@link BatchEntry} as the result. + * + *

This class is used for API responses where the primary result is a batch entry, + * which includes collections of operations such as patches, posts, puts, and deletes + * performed on DNS record entities. + * + *

Extends {@code AbstractSingleResponse} with {@code BatchEntry} as the generic type, + * ensuring that the response result is a batch of operations. + */ public class BatchResponse extends AbstractSingleResponse { BatchResponse() { diff --git a/src/main/java/codes/thischwa/cf/model/PagingRequest.java b/src/main/java/codes/thischwa/cf/model/PagingRequest.java index fcdab6c..de6277c 100644 --- a/src/main/java/codes/thischwa/cf/model/PagingRequest.java +++ b/src/main/java/codes/thischwa/cf/model/PagingRequest.java @@ -32,7 +32,7 @@ public class PagingRequest { /** * Creates a new {@code PagingRequest} instance with the specified page number and items per page. * - * @param page the page number to be requested + * @param page the page number to be requested * @param perPage the number of items to be included per page * @return a new {@code PagingRequest} instance with the provided parameters */ diff --git a/src/main/java/codes/thischwa/cf/model/RecordEntity.java b/src/main/java/codes/thischwa/cf/model/RecordEntity.java index cc07725..3787f7d 100644 --- a/src/main/java/codes/thischwa/cf/model/RecordEntity.java +++ b/src/main/java/codes/thischwa/cf/model/RecordEntity.java @@ -34,10 +34,14 @@ public class RecordEntity extends AbstractEntity { private Boolean proxied; private Integer ttl; private Boolean locked; - @Nullable private String zoneId; - @Nullable private String zoneName; - @Nullable private LocalDateTime modifiedOn; - @Nullable private LocalDateTime createdOn; + @Nullable + private String zoneId; + @Nullable + private String zoneName; + @Nullable + private LocalDateTime modifiedOn; + @Nullable + private LocalDateTime createdOn; /** * Initializes a new instance of the RecordEntity class and invokes the parent constructor from @@ -52,9 +56,9 @@ public class RecordEntity extends AbstractEntity { /** * Builds and returns a {@link RecordEntity} instance with the specified attributes. * - * @param name the name of the DNS record - * @param type the {@link RecordType} of the DNS record - * @param ttl the time-to-live (TTL) value for the DNS record + * @param name the name of the DNS record + * @param type the {@link RecordType} of the DNS record + * @param ttl the time-to-live (TTL) value for the DNS record * @param content the content of the DNS record, typically an IP address * @return a {@link RecordEntity} populated with the provided attributes */ @@ -81,6 +85,16 @@ public class RecordEntity extends AbstractEntity { return rec; } + /** + * Builds and returns a {@link RecordEntity} instance with the specified attributes. + * + * @param id the unique identifier for the DNS record + * @param name the name of the DNS record + * @param type the type of the DNS record, represented as a string (e.g., "A", "CNAME") + * @param ttl the time-to-live (TTL) value for the DNS record + * @param content the content of the DNS record, typically an IP address or other record data + * @return a {@link RecordEntity} populated with the provided attributes + */ public static RecordEntity build(String id, String name, String type, Integer ttl, String content) { RecordEntity rec = build(name, RecordType.valueOf(type), ttl, content); rec.setId(id); diff --git a/src/main/java/codes/thischwa/cf/model/ResponseResultInfo.java b/src/main/java/codes/thischwa/cf/model/ResponseResultInfo.java index 585a9c2..7589fbc 100644 --- a/src/main/java/codes/thischwa/cf/model/ResponseResultInfo.java +++ b/src/main/java/codes/thischwa/cf/model/ResponseResultInfo.java @@ -21,14 +21,34 @@ public class ResponseResultInfo { private List errors; private List messages; + /** + * Represents an error with a specific code and message. + * + *

This class is used to encapsulate error information, including a numerical error code + * and a corresponding descriptive message. It is often used as part of a collection of errors + * to provide detailed diagnostics for failed operations or processes. + */ @Data public static class Error { private int code; private String message; + /** + * Constructs a new instance of the {@code Error} class with default values for its properties. + * + *

This no-argument constructor initializes an {@code Error} object without setting + * specific values for the error code or message. It is primarily used when an error needs to + * be created and set up later, or when default values are acceptable. + */ public Error() { } + /** + * Constructs an instance of the {@code Error} class with a specified error code and message. + * + * @param code the numerical code representing the error + * @param message the descriptive message providing details about the error + */ public Error(int code, String message) { this.code = code; this.message = message; diff --git a/src/main/java/codes/thischwa/cf/model/ZoneMultipleResponse.java b/src/main/java/codes/thischwa/cf/model/ZoneMultipleResponse.java index 5c8234f..fb860cd 100644 --- a/src/main/java/codes/thischwa/cf/model/ZoneMultipleResponse.java +++ b/src/main/java/codes/thischwa/cf/model/ZoneMultipleResponse.java @@ -1,6 +1,8 @@ package codes.thischwa.cf.model; -/** Represents a response model that contains multiple {@link ZoneEntity} instances. */ +/** + * Represents a response model that contains multiple {@link ZoneEntity} instances. + */ public class ZoneMultipleResponse extends AbstractMultipleResponse { /** diff --git a/src/main/java/codes/thischwa/cf/model/package-info.java b/src/main/java/codes/thischwa/cf/model/package-info.java index c9a9fe9..ff627be 100644 --- a/src/main/java/codes/thischwa/cf/model/package-info.java +++ b/src/main/java/codes/thischwa/cf/model/package-info.java @@ -1,2 +1,5 @@ -/** The model of CloudflareDNS-java. */ +/** + * The model of CloudflareDNS-java. + */ + package codes.thischwa.cf.model; diff --git a/src/main/java/codes/thischwa/cf/package-info.java b/src/main/java/codes/thischwa/cf/package-info.java index b0adb4c..d08f7cd 100644 --- a/src/main/java/codes/thischwa/cf/package-info.java +++ b/src/main/java/codes/thischwa/cf/package-info.java @@ -1,2 +1,5 @@ -/** The base package of CloudflareDNS-java. */ +/** + * The base package of CloudflareDNS-java. + */ + package codes.thischwa.cf; \ No newline at end of file