diff --git a/build.gradle b/build.gradle index bcf9792..3d7d47f 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'de.winniepat' -version = '0.0.7' +version = '0.0.8' java { diff --git a/src/main/java/de/winniepat/licenselib/LicenseClient.java b/src/main/java/de/winniepat/licenselib/LicenseClient.java index 0c4871f..964f63e 100644 --- a/src/main/java/de/winniepat/licenselib/LicenseClient.java +++ b/src/main/java/de/winniepat/licenselib/LicenseClient.java @@ -65,24 +65,9 @@ public class LicenseClient { } /** - * Record representing the result of a license check, containing the validity, status, message, plugin, customer, expiration date, and check date. - * @param valid indicates whether the license is valid or not - * @param status the status of the license check, e.g. "valid", "invalid", "expired", etc. - * @param message a message providing additional information about the license check result, e.g. error messages or instructions for resolving issues - * @param plugin the plugin for which the license check was performed - * @param customer the customer associated with the license, if available - * @param expiresAt the expiration date of the license, if available - * @param checkedAt the date and time when the license check was performed + * Represents the result of a license check, which can be either a success with license details or an error with a message. */ - public record LicenseResult( - boolean valid, - String status, - String message, - String plugin, - String customer, - String expiresAt, - String checkedAt - ) { } + public sealed interface LicenseResult permits LicenseSuccess, LicenseError {} private static HttpRequest createRequest( String apiUrl, @@ -107,15 +92,7 @@ public class LicenseClient { } private static LicenseResult errorResult(Throwable throwable) { - return new LicenseResult( - false, - "error", - throwable.getMessage(), - null, - null, - null, - null - ); + return new LicenseError(throwable.getMessage()); } private static String getString(JsonObject json, String key, String def) { @@ -134,7 +111,7 @@ public class LicenseClient { JsonObject json = JsonParser.parseString(response.body()).getAsJsonObject(); boolean valid = json.has("valid") && json.get("valid").getAsBoolean(); - return new LicenseResult( + return new LicenseSuccess( valid, getString(json, "status", "unknown"), getString(json, "message", ""), diff --git a/src/main/java/de/winniepat/licenselib/LicenseError.java b/src/main/java/de/winniepat/licenselib/LicenseError.java new file mode 100644 index 0000000..bce3c79 --- /dev/null +++ b/src/main/java/de/winniepat/licenselib/LicenseError.java @@ -0,0 +1,10 @@ +package de.winniepat.licenselib; + +/** + * Represents an error that occurred during the license check process, such as network issues or invalid responses from the server. + * @param message A descriptive error message providing details about the failure. + */ +public record LicenseError( + String message +) implements LicenseClient.LicenseResult { +} \ No newline at end of file diff --git a/src/main/java/de/winniepat/licenselib/LicenseSuccess.java b/src/main/java/de/winniepat/licenselib/LicenseSuccess.java new file mode 100644 index 0000000..3f0180a --- /dev/null +++ b/src/main/java/de/winniepat/licenselib/LicenseSuccess.java @@ -0,0 +1,22 @@ +package de.winniepat.licenselib; + +/** + * Represents a successful license check result, containing all relevant information about the license status, plugin, customer, and expiration details. + * @param valid Indicates whether the license is valid or not. + * @param status A string representing the status of the license, such as "valid", "invalid", "expired", etc. + * @param message A message providing additional information about the license status, which can be used for logging or debugging purposes. + * @param plugin The name of the plugin associated with the license, which can be used to identify which plugin the license check was performed for. + * @param customer The name of the customer or organization that owns the license, which can be useful for tracking and support purposes. + * @param expiresAt The expiration date of the license in ISO 8601 format (e.g., "2024-12-31T23:59:59Z"), which indicates when the license will no longer be valid. + * @param checkedAt The date and time when the license check was performed, also in ISO 8601 format, which can be used to determine how recent the license information is. + */ +public record LicenseSuccess( + boolean valid, + String status, + String message, + String plugin, + String customer, + String expiresAt, + String checkedAt +) implements LicenseClient.LicenseResult { +} \ No newline at end of file