Skip to content

Commit 39d4db8

Browse files
committed
Add GetKey overload without error parameter
1 parent d72bbe7 commit 39d4db8

File tree

1 file changed

+67
-39
lines changed
  • src/main/java/io/cryptolens/methods

1 file changed

+67
-39
lines changed

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

Lines changed: 67 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,44 +29,45 @@
2929
*
3030
* <application ....
3131
* </pre>
32-
*
3332
*/
3433
public class Key {
3534

3635
/**
3736
* Calls the Activate method (https://app.cryptolens.io/docs/api/v3/Activate).
38-
* @param token The access token with 'Activate' permission.
37+
*
38+
* @param token The access token with 'Activate' permission.
3939
* @param RSAPubKey Your RSA Public Key, which can be found at https://app.cryptolens.io/docs/api/v3/QuickStart.
40-
* @param model Method parameters.
40+
* @param model Method parameters.
4141
* @return A LicenseKey object if success and null otherwise.
4242
*/
43-
public static LicenseKey Activate (String token, String RSAPubKey, ActivateModel model) {
44-
return Activate(token, RSAPubKey, model,null);
43+
public static LicenseKey Activate(String token, String RSAPubKey, ActivateModel model) {
44+
return Activate(token, RSAPubKey, model, null);
4545
}
4646

4747
/**
4848
* 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>
51-
* To retrieve the error message, you need to initialize an APIError object and pass it in into the
52-
* "error" parameter. For example,
51+
* To retrieve the error message, you need to initialize an APIError object and pass it in into the
52+
* "error" parameter. For example,
5353
* </p>
5454
* <code>
55-
* APIError error = new APIError();<br>
56-
* LicenseKey license = Key.Activate(auth, RSAPubKey, new ActivateModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", Helpers.GetMachineCode()), error);<br>
57-
* System.out.println(error.message);
55+
* APIError error = new APIError();<br>
56+
* LicenseKey license = Key.Activate(auth, RSAPubKey, new ActivateModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", Helpers.GetMachineCode()), error);<br>
57+
* System.out.println(error.message);
5858
* </code>
59-
* @param token The access token with 'Activate' permission.
59+
*
60+
* @param token The access token with 'Activate' permission.
6061
* @param RSAPubKey Your RSA Public Key, which can be found at https://app.cryptolens.io/docs/api/v3/QuickStart.
61-
* @param model Method parameters.
62-
* @param error The error object whose Message field will be populated if an error has occurred. Please initialize
63-
* this parameter, i.e. define <code>APIError error = new APIError();</code> and then pass
64-
* <code>error</code> into this parameter.
62+
* @param model Method parameters.
63+
* @param error The error object whose Message field will be populated if an error has occurred. Please initialize
64+
* this parameter, i.e. define <code>APIError error = new APIError();</code> and then pass
65+
* <code>error</code> into this parameter.
6566
* @return A LicenseKey object if success and null otherwise.
6667
*/
67-
public static LicenseKey Activate (String token, String RSAPubKey, ActivateModel model, APIError error) {
68+
public static LicenseKey Activate(String token, String RSAPubKey, ActivateModel model, APIError error) {
6869

69-
Map<String,String> extraParams = new HashMap<>();
70+
Map<String, String> extraParams = new HashMap<>();
7071

7172
// force sign and the new protocol (only in activate)
7273
// modelVersion=3 docs: https://app.cryptolens.io/docs/api/v3/Activate?modelVersion=3
@@ -77,8 +78,8 @@ public static LicenseKey Activate (String token, String RSAPubKey, ActivateModel
7778

7879
ActivateResult result = HelperMethods.SendRequestToWebAPI("key/activate", model, extraParams, ActivateResult.class, error);
7980

80-
if(result == null || result.result == 1) {
81-
if(result != null) {
81+
if (result == null || result.result == 1) {
82+
if (result != null) {
8283
if (error != null) {
8384
error.message = result.message;
8485
error.errorType = ErrorType.WebAPIError;
@@ -98,25 +99,48 @@ public static LicenseKey Activate (String token, String RSAPubKey, ActivateModel
9899
* Calls the GetKey method (https://app.cryptolens.io/docs/api/v3/GetKey?modelVersion=3).
99100
* <p>This method allows you to retrieve the error message from the Web API.</p>
100101
* <p>
101-
* To retrieve the error message, you need to initialize an APIError object and pass it in into the
102-
* "error" parameter. For example,
102+
* To retrieve the error message, you need to initialize an APIError object and pass it in into the
103+
* "error" parameter. For example,
103104
* </p>
104105
* <code>
105-
* APIError error = new APIError();<br>
106-
* LicenseKey license = Key.GetKey(auth, RSAPubKey, new GetKeyModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL"), error);<br>
107-
* System.out.println(error.message);
106+
* APIError error = new APIError();<br>
107+
* LicenseKey license = Key.GetKey(auth, RSAPubKey, new GetKeyModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL"), error);<br>
108+
* System.out.println(error.message);
108109
* </code>
109-
* @param token The access token with 'GetKey' permission.
110+
*
111+
* @param token The access token with 'GetKey' permission.
110112
* @param RSAPubKey Your RSA Public Key, which can be found at https://app.cryptolens.io/docs/api/v3/QuickStart.
111-
* @param model Method parameters.
112-
* @param error The error object whose Message field will be populated if an error has occurred. Please initialize
113-
* this parameter, i.e. define <code>APIError error = new APIError();</code> and then pass
114-
* <code>error</code> into this parameter.
113+
* @param model Method parameters.
114+
* @return A LicenseKey object if success and null otherwise.
115+
*/
116+
public static LicenseKey GetKey(String token, String RSAPubKey, GetKeyModel model) {
117+
return GetKey(token, RSAPubKey, model, null);
118+
}
119+
120+
/**
121+
* Calls the GetKey method (https://app.cryptolens.io/docs/api/v3/GetKey?modelVersion=3).
122+
* <p>This method allows you to retrieve the error message from the Web API.</p>
123+
* <p>
124+
* To retrieve the error message, you need to initialize an APIError object and pass it in into the
125+
* "error" parameter. For example,
126+
* </p>
127+
* <code>
128+
* APIError error = new APIError();<br>
129+
* LicenseKey license = Key.GetKey(auth, RSAPubKey, new GetKeyModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL"), error);<br>
130+
* System.out.println(error.message);
131+
* </code>
132+
*
133+
* @param token The access token with 'GetKey' permission.
134+
* @param RSAPubKey Your RSA Public Key, which can be found at https://app.cryptolens.io/docs/api/v3/QuickStart.
135+
* @param model Method parameters.
136+
* @param error The error object whose Message field will be populated if an error has occurred. Please initialize
137+
* this parameter, i.e. define <code>APIError error = new APIError();</code> and then pass
138+
* <code>error</code> into this parameter.
115139
* @return A LicenseKey object if success and null otherwise.
116140
*/
117-
public static LicenseKey GetKey (String token, String RSAPubKey, GetKeyModel model, APIError error) {
141+
public static LicenseKey GetKey(String token, String RSAPubKey, GetKeyModel model, APIError error) {
118142

119-
Map<String,String> extraParams = new HashMap<>();
143+
Map<String, String> extraParams = new HashMap<>();
120144

121145
// force sign and the new protocol (only in activate)
122146
// modelVersion=3 docs: https://app.cryptolens.io/docs/api/v3/Activate?modelVersion=3
@@ -127,8 +151,8 @@ public static LicenseKey GetKey (String token, String RSAPubKey, GetKeyModel mod
127151

128152
ActivateResult result = HelperMethods.SendRequestToWebAPI("key/getkey", model, extraParams, ActivateResult.class, error);
129153

130-
if(result == null || result.result == 1) {
131-
if(result != null) {
154+
if (result == null || result.result == 1) {
155+
if (result != null) {
132156
if (error != null) {
133157
error.message = result.message;
134158
error.errorType = ErrorType.WebAPIError;
@@ -148,34 +172,36 @@ public static LicenseKey GetKey (String token, String RSAPubKey, GetKeyModel mod
148172
* This method will 'undo' a key activation with a certain machine code.
149173
* The key should not be blocked, since otherwise this method will throw an error.
150174
* More info: https://app.cryptolens.io/docs/api/v3/Deactivate
175+
*
151176
* @param token The access token with 'Deactivate' permission.
152177
* @param model Method parameters.
153178
* @return True if deactivation succeeded and false otherwise.
154179
*/
155-
public static boolean Deactivate (String token, DeactivateModel model) {
180+
public static boolean Deactivate(String token, DeactivateModel model) {
156181
return Deactivate(token, model, null);
157182
}
158183

159184
/**
160185
* This method will 'undo' a key activation with a certain machine code.
161186
* The key should not be blocked, since otherwise this method will throw an error.
162187
* More info: https://app.cryptolens.io/docs/api/v3/Deactivate
188+
*
163189
* @param token The access token with 'Deactivate' permission.
164190
* @param model Method parameters.
165191
* @param error The error object whose Message field will be populated if an error has occurred. Please initialize
166192
* this parameter, i.e. define <code>APIError error = new APIError();</code> and then pass
167193
* <code>error</code> into this parameter.
168194
* @return True if deactivation succeeded and false otherwise.
169195
*/
170-
public static boolean Deactivate (String token, DeactivateModel model, APIError error) {
196+
public static boolean Deactivate(String token, DeactivateModel model, APIError error) {
171197

172-
Map<String,String> extraParams = new HashMap<>();
198+
Map<String, String> extraParams = new HashMap<>();
173199
extraParams.put("token", token);
174200

175201
BasicResult result = HelperMethods.SendRequestToWebAPI("key/deactivate", model, extraParams, BasicResult.class, error);
176202

177-
if(result == null || result.result == 1) {
178-
if(result != null) {
203+
if (result == null || result.result == 1) {
204+
if (result != null) {
179205
if (error != null) {
180206
error.message = result.message;
181207
error.errorType = ErrorType.WebAPIError;
@@ -201,6 +227,7 @@ public static boolean Deactivate (String token, DeactivateModel model, APIError
201227
* <p>If a trial key was already created for a certain machine code, this method will try to find the license
202228
* key and return it instead. However, this will only occur if the license key is still a trial key (based
203229
* on feature definitions) and is not blocked.</p>
230+
*
204231
* @param token The access token with 'CreateTrialKey' permission.
205232
* @param model Method parameters.
206233
* @return A new license key or error message.
@@ -219,6 +246,7 @@ public static CreateKeyResult CreateTrialKey(String token, CreateTrialKeyModel m
219246
* <p>If a trial key was already created for a certain machine code, this method will try to find the license
220247
* key and return it instead. However, this will only occur if the license key is still a trial key (based
221248
* on feature definitions) and is not blocked.</p>
249+
*
222250
* @param token The access token with 'CreateTrialKey' permission.
223251
* @param model Method parameters.
224252
* @param error The error object whose Message field will be populated if an error has occurred. Please initialize
@@ -227,7 +255,7 @@ public static CreateKeyResult CreateTrialKey(String token, CreateTrialKeyModel m
227255
* @return A new license key or error message.
228256
*/
229257
public static CreateKeyResult CreateTrialKey(String token, CreateTrialKeyModel model, APIError error) {
230-
Map<String,String> extraParams = new HashMap<>();
258+
Map<String, String> extraParams = new HashMap<>();
231259
extraParams.put("token", token);
232260

233261
return HelperMethods.SendRequestToWebAPI("key/createtrialkey", model, extraParams, CreateKeyResult.class, error);

0 commit comments

Comments
 (0)