0.0.3 | Combined functions with and without serverId into one
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
group = 'de.winniepat'
|
group = 'de.winniepat'
|
||||||
version = '0.0.2'
|
version = '0.0.3'
|
||||||
|
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class LicenseClient {
|
|||||||
String apiUrl,
|
String apiUrl,
|
||||||
String plugin,
|
String plugin,
|
||||||
String licenseKey,
|
String licenseKey,
|
||||||
String serverId
|
String serverId // can be null
|
||||||
) {
|
) {
|
||||||
|
|
||||||
Http http = new Http();
|
Http http = new Http();
|
||||||
@@ -42,40 +42,12 @@ public class LicenseClient {
|
|||||||
JsonObject payload = new JsonObject();
|
JsonObject payload = new JsonObject();
|
||||||
payload.addProperty("plugin", plugin);
|
payload.addProperty("plugin", plugin);
|
||||||
payload.addProperty("licenseKey", licenseKey);
|
payload.addProperty("licenseKey", licenseKey);
|
||||||
|
|
||||||
|
if (serverId != null) {
|
||||||
payload.addProperty("serverId", serverId);
|
payload.addProperty("serverId", serverId);
|
||||||
|
|
||||||
HttpResponse response = http.post(apiUrl, GSON.toJson(payload));
|
|
||||||
|
|
||||||
JsonObject json = GSON.fromJson(response.body(), JsonObject.class);
|
|
||||||
|
|
||||||
return new LicenseResult(
|
|
||||||
json.get("valid").getAsBoolean(),
|
|
||||||
json.get("status").getAsString(),
|
|
||||||
json.get("message").getAsString()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if license is valid (without serverId)
|
|
||||||
* @param apiUrl Server API url
|
|
||||||
* @param plugin Plugin id matching the one on the backend api
|
|
||||||
* @param licenseKey License key issued by the api
|
|
||||||
* @return LicenseResult with the data from the backend
|
|
||||||
*/
|
|
||||||
public static LicenseResult check(
|
|
||||||
String apiUrl,
|
|
||||||
String plugin,
|
|
||||||
String licenseKey
|
|
||||||
) {
|
|
||||||
|
|
||||||
Http http = new Http();
|
|
||||||
|
|
||||||
JsonObject payload = new JsonObject();
|
|
||||||
payload.addProperty("plugin", plugin);
|
|
||||||
payload.addProperty("licenseKey", licenseKey);
|
|
||||||
|
|
||||||
HttpResponse response = http.post(apiUrl, GSON.toJson(payload));
|
HttpResponse response = http.post(apiUrl, GSON.toJson(payload));
|
||||||
|
|
||||||
JsonObject json = GSON.fromJson(response.body(), JsonObject.class);
|
JsonObject json = GSON.fromJson(response.body(), JsonObject.class);
|
||||||
|
|
||||||
return new LicenseResult(
|
return new LicenseResult(
|
||||||
|
|||||||
Reference in New Issue
Block a user