Skip to content

Commit

Permalink
Add Deactivate method (#13)
Browse files Browse the repository at this point in the history
* Start on deactivate method

* Finish deactivate

* Test deactivate

* Update README.md
  • Loading branch information
artemlos authored Feb 4, 2019
1 parent 958874b commit b9e9c71
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 156 deletions.
1 change: 1 addition & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .idea/cryptolens-java.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

232 changes: 81 additions & 151 deletions .idea/workspace.xml

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,40 @@ public static void main(String args[]) {
}
}
```

### Deactivation
In order to deactivate a license, we can call the `Key.Deactivate` method, as shown below:

```java
import io.cryptolens.methods.*;
import io.cryptolens.models.*;

public static void main(String args[]) {
String auth = "";

boolean result = Key.Deactivate(auth, new DeactivateModel(3349, "MTMPW-VZERP-JZVNZ-SCPZM", Helpers.GetMachineCode()));
if (result == true) {
System.out.println("Deactivation successful.");
} else {
System.out.println("Deactivation failed.");
}
}
```

The call above is useful when [node-locking](https://help.cryptolens.io/licensing-models/node-locked) is used. If it's a floating license, deactivation is not necessary since licenses will be deactivated automatically after a certain period of time. However, to force a deactivation earlier, you can use similar code as above with addition of a boolean flag.

```java
import io.cryptolens.methods.*;
import io.cryptolens.models.*;

public static void main(String args[]) {
String auth = "";

boolean result = Key.Deactivate(auth, new DeactivateModel(3349, "MTMPW-VZERP-JZVNZ-SCPZM", Helpers.GetMachineCode(), true));
if (result == true) {
System.out.println("Deactivation successful.");
} else {
System.out.println("Deactivation failed.");
}
}
```
33 changes: 29 additions & 4 deletions src/main/java/io/cryptolens/methods/Key.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package io.cryptolens.methods;

import io.cryptolens.internal.BasicResult;
import io.cryptolens.internal.HelperMethods;
import io.cryptolens.models.ActivateModel;
import io.cryptolens.internal.ActivateResult;
import io.cryptolens.models.DeactivateModel;
import io.cryptolens.models.LicenseKey;

import java.util.HashMap;
Expand All @@ -16,10 +18,10 @@ public class Key {

/**
* Calls the Activate method (https://app.cryptolens.io/docs/api/v3/Activate).
* @param token
* @param RSAPubKey
* @param model
* @return
* @param token The access token with 'Activate' permission.
* @param RSAPubKey Your RSA Public Key, which can be found at https://app.cryptolens.io/docs/api/v3/QuickStart.
* @param model Method parameters.
* @return A LicenseKey object if success and null otherwise.
*/
public static LicenseKey Activate (String token, String RSAPubKey, ActivateModel model) {

Expand All @@ -40,4 +42,27 @@ public static LicenseKey Activate (String token, String RSAPubKey, ActivateModel
return LicenseKey.LoadFromString(RSAPubKey, result.RawResponse);
}

/**
* This method will 'undo' a key activation with a certain machine code.
* The key should not be blocked, since otherwise this method will throw an error.
* More info: https://app.cryptolens.io/docs/api/v3/Deactivate
* @param token The access token with 'Deactivate' permission.
* @param model Method parameters.
* @return True if deactivation succeeded and false otherwise.
*/
public static boolean Deactivate (String token, DeactivateModel model) {

Map<String,String> extraParams = new HashMap<>();
extraParams.put("token", token);

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

if(result.result == 1) {
System.err.println("The server returned an error: " + result.message);
return false;
}

return true;
}

}
26 changes: 26 additions & 0 deletions src/main/java/io/cryptolens/models/DeactivateModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.cryptolens.models;

public class DeactivateModel {

public int ProductId;
public String Key;
public String MachineCode;
public boolean Floating;

public DeactivateModel() {

}

public DeactivateModel(int productId, String key, String machineCode) {
ProductId = productId;
Key = key;
MachineCode = machineCode;
}

public DeactivateModel(int productId, String key, String machineCode, boolean floating) {
ProductId = productId;
Key = key;
MachineCode = machineCode;
Floating = floating;
}
}
3 changes: 2 additions & 1 deletion src/test/java/io/cryptolens/KeyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.cryptolens.methods.Helpers;
import io.cryptolens.methods.Key;
import io.cryptolens.models.ActivateModel;
import io.cryptolens.models.DeactivateModel;
import io.cryptolens.models.LicenseKey;
import junit.framework.Test;
import junit.framework.TestCase;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void testApp() throws Exception {
System.out.println(newLicense.Expires);
}


//Key.Deactivate("", new DeactivateModel(3349, "ICVLD-VVSZR-ZTICT-YKGXL", Helpers.GetMachineCode()));

assertTrue( true );

Expand Down

0 comments on commit b9e9c71

Please sign in to comment.