Skip to content

Commit f37b626

Browse files
committed
Add support for GetKey
1 parent 794606e commit f37b626

File tree

4 files changed

+92
-10
lines changed

4 files changed

+92
-10
lines changed
Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>io.cryptolens</groupId>
55
<artifactId>cryptolens</artifactId>
66
<packaging>jar</packaging>
7-
<version>1.5</version>
7+
<version>1.7-STABLE</version>
88
<name>cryptolens</name>
99
<description>A client api to access Cryptolens Licensing API.</description>
1010
<url>https://github.com/cryptolens/cryptolens-java</url>
@@ -27,7 +27,7 @@
2727
<dependency>
2828
<groupId>com.github.oshi</groupId>
2929
<artifactId>oshi-core</artifactId>
30-
<version>LATEST</version>
30+
<version>5.3.1</version>
3131
</dependency>
3232
<dependency>
3333
<groupId>commons-codec</groupId>

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

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static LicenseKey Activate (String token, String RSAPubKey, ActivateModel
4545
}
4646

4747
/**
48-
* Calls the Activate method (https://app.cryptolens.io/docs/api/v3/Activate).
48+
* Calls the Activate method (https://app.cryptolens.io/docs/api/v3/Activate?modelVersion=3).
4949
* <p>This method allows you to retrieve the error message from the Web API.</p>
5050
* <p>
5151
* To retrieve the error message, you need to initialize an APIError object and pass it in into the
@@ -94,6 +94,36 @@ public static LicenseKey Activate (String token, String RSAPubKey, ActivateModel
9494
return LicenseKey.LoadFromString(RSAPubKey, result.RawResponse);
9595
}
9696

97+
public static LicenseKey GetKey (String token, String RSAPubKey, GetKeyModel model, APIError error) {
98+
99+
Map<String,String> extraParams = new HashMap<>();
100+
101+
// force sign and the new protocol (only in activate)
102+
// modelVersion=3 docs: https://app.cryptolens.io/docs/api/v3/Activate?modelVersion=3
103+
extraParams.put("Sign", "true");
104+
extraParams.put("SignMethod", "1");
105+
extraParams.put("token", token);
106+
extraParams.put("ModelVersion", "3");
107+
108+
ActivateResult result = HelperMethods.SendRequestToWebAPI("key/getkey", model, extraParams, ActivateResult.class, error);
109+
110+
if(result == null || result.result == 1) {
111+
if(result != null) {
112+
if (error != null) {
113+
error.message = result.message;
114+
error.errorType = ErrorType.WebAPIError;
115+
}
116+
} else {
117+
if (error != null) {
118+
error.errorType = ErrorType.WebAPIError;
119+
}
120+
}
121+
return null;
122+
}
123+
124+
return LicenseKey.LoadFromString(RSAPubKey, result.RawResponse);
125+
}
126+
97127
/**
98128
* This method will 'undo' a key activation with a certain machine code.
99129
* The key should not be blocked, since otherwise this method will throw an error.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package io.cryptolens.models;
2+
3+
/**
4+
* The parameters that are used when calling the Key.GetKey method.
5+
*/
6+
7+
public class GetKeyModel {
8+
/**
9+
* The product id, which can be found on the product page.
10+
*/
11+
public int ProductId;
12+
13+
/**
14+
* The Key string, eg. AAAA-BBBB-CCCC-DDDD.
15+
*/
16+
public String Key;
17+
18+
/**
19+
* An integer that allows you to restrict the information returned in the license key data object.
20+
* Please read https://app.cryptolens.io/docs/api/v3/Activate#remarks for more details.
21+
*/
22+
public int FieldsToReturn;
23+
24+
/**
25+
* Includes additional information about the license key, such as number of activated devices, etc.
26+
*/
27+
public boolean Metadata;
28+
29+
/**
30+
* Allows you specify the floatingTimeInterval. The current version of the SDK uses a modelVersion=3,
31+
* which means that all activated devices (node-locked and floating) will be returned in ActivatedMachines,
32+
* independent of the floatingTimeInterval value. This value is only taken into account in the additional
33+
* metadata that is returned (if Metadata=true). In most use cases, this parameter does not need to be used.
34+
*/
35+
public int FloatingTimeInterval;
36+
37+
public GetKeyModel() {
38+
39+
}
40+
41+
public GetKeyModel(int productId, String key) {
42+
ProductId = productId;
43+
Key = key;
44+
}
45+
46+
public GetKeyModel(int productId, String key, int floatingTimeInterval, boolean metadata) {
47+
ProductId = productId;
48+
Key = key;
49+
FloatingTimeInterval = floatingTimeInterval;
50+
Metadata = metadata;
51+
}
52+
}

0 commit comments

Comments
 (0)