Skip to content

Commit 3cb6102

Browse files
committed
Add ExtendLicense
1 parent 1ae0baa commit 3cb6102

File tree

4 files changed

+77
-1
lines changed

4 files changed

+77
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<artifactId>cryptolens</artifactId>
88
<packaging>jar</packaging>
99

10-
<version>1.12.0</version>
10+
<version>1.27.0</version>
1111

1212
<name>cryptolens</name>
1313
<description>A client API to access Cryptolens Licensing API.</description>

src/main/java/io/cryptolens/methods/Key.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,4 +260,38 @@ public static CreateKeyResult CreateTrialKey(String token, CreateTrialKeyModel m
260260

261261
return HelperMethods.SendRequestToWebAPI("key/createtrialkey", model, extraParams, CreateKeyResult.class, error);
262262
}
263+
264+
/**
265+
* This method will extend a license by a certain amount of days. If the key algorithm in the product is SKGL,
266+
* the key string will be changed if necessary. Otherwise, if SKM15 is used, the key will stay the same.
267+
* More about the way this method works in Remarks.
268+
* @param token The access token with 'CreateTrialKey' permission.
269+
* @param model Method parameters.
270+
* @param error The error object whose Message field will be populated if an error has occurred. Please initialize
271+
* this parameter, i.e. define <code>APIError error = new APIError();</code> and then pass
272+
* <code>error</code> into this parameter.
273+
* @return True if successful and false otherwise.
274+
*/
275+
public static boolean ExtendLicense(String token, ExtendLicenseModel model, APIError error) {
276+
Map<String, String> extraParams = new HashMap<>();
277+
extraParams.put("token", token);
278+
279+
BasicResult result = HelperMethods.SendRequestToWebAPI("key/extendlicense", model, extraParams, BasicResult.class, error);
280+
281+
if (result == null || result.result == 1) {
282+
if (result != null) {
283+
if (error != null) {
284+
error.message = result.message;
285+
error.errorType = ErrorType.WebAPIError;
286+
}
287+
} else {
288+
if (error != null) {
289+
error.errorType = ErrorType.WebAPIError;
290+
}
291+
}
292+
return false;
293+
}
294+
295+
return true;
296+
}
263297
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.cryptolens.models;
2+
3+
public class ExtendLicenseModel extends RequestModel {
4+
5+
/**
6+
* The product id.
7+
*/
8+
int ProductId;
9+
10+
/**
11+
* The license key string.
12+
*/
13+
String Key;
14+
15+
/**
16+
* The number of days the license should be extended.
17+
*/
18+
int NoOfDays;
19+
20+
public ExtendLicenseModel(int productId, String key, int noOfDays) {
21+
ProductId = productId;
22+
Key = key;
23+
NoOfDays = noOfDays;
24+
}
25+
}

src/test/java/io/cryptolens/KeyTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.Gson;
44
import com.google.gson.reflect.TypeToken;
5+
import io.cryptolens.internal.BasicResult;
56
import io.cryptolens.methods.Helpers;
67
import io.cryptolens.methods.Key;
78
import io.cryptolens.models.*;
@@ -148,6 +149,22 @@ public void testGetKeyLicenseServer() throws Exception {
148149

149150
}
150151

152+
public void testExtendLicense() throws Exception {
153+
154+
init();
155+
156+
String auth = APIKey.get("extendlicense");
157+
158+
APIError error = new APIError();
159+
160+
ExtendLicenseModel model = new ExtendLicenseModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL",1);
161+
model.LicenseServerUrl = "https://api.cryptolens.io";
162+
boolean result = Key.ExtendLicense(auth, model , error);
163+
164+
assertTrue(result);
165+
166+
}
167+
151168

152169

153170
}

0 commit comments

Comments
 (0)