-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Start on data object methods * Add more methods * Finish all API methods * Add additional methods in data objects that take in a license key * Fix tests and missing parameters * Update javadoc * Update ProductAndKeyModel.java
- Loading branch information
Showing
15 changed files
with
522 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
package io.cryptolens.methods; | ||
|
||
import com.google.gson.Gson; | ||
import io.cryptolens.internal.*; | ||
import io.cryptolens.models.*; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* <p>The following methods allow you to work with data objects (aka. metadata or custom variables) associated with a | ||
* license key. Data objects can be used to store specific properties that (eg. username, OS version). More importantly | ||
* though, they are used if you plan to implement a <a href="https://help.cryptolens.io/licensing-models/usage-based" target="_blank">usage-based licensing model</a>. | ||
* </p> | ||
* | ||
* <p><b>Access token remarks:</b> When you create an access token for any of the methods below, we recommend to <u>specify the product</u> | ||
* and to set the <u>keylock to <b>-1</b></u>.</p> | ||
*/ | ||
public class Data { | ||
/** | ||
* Adds a new data object to a license key. | ||
* @param token The access token with 'AddDataObject' permission and KeyLock set to '-1'. | ||
* @param license The license key object (it's used to get the product id and key string). | ||
* @param name The name of the data object. Max 10 characters. | ||
* @param intValue An int value (int32) to store. | ||
* @param stringValue A string value (text) to store. Max 10000 characters. | ||
* @return | ||
*/ | ||
public static BasicResult AddDataObject(String token, LicenseKey license, String name, int intValue, String stringValue) { | ||
return AddDataObject(token, new AddDataObjectToKeyModel(license.ProductId, license.Key, name, intValue, stringValue)); | ||
} | ||
|
||
public static BasicResult AddDataObject(String token, AddDataObjectToKeyModel model) { | ||
|
||
Map<String,String> extraParams = new HashMap<>(); | ||
|
||
extraParams.put("token", token); | ||
|
||
return HelperMethods.SendRequestToWebAPI("data/AddDataObjectToKey", model, extraParams, BasicResult.class); | ||
} | ||
|
||
/** | ||
* List data objects of a certain license. | ||
* @param token The access token with 'ListDataObjects' permission and KeyLock set to '-1'. | ||
* @param license The license key object (it's used to get the product id and key string). | ||
* @return | ||
*/ | ||
public static ListOfDataObjectsResult ListDataObjects(String token, LicenseKey license) { | ||
return ListDataObjects(token, new ListDataObjectsToKeyModel(license.ProductId, license.Key, "")); | ||
} | ||
|
||
/** | ||
* List data objects of a certain license. | ||
* @param token The access token with 'ListDataObjects' permission and KeyLock set to '-1'. | ||
* @param license The license key object (it's used to get the product id and key string). | ||
* @param contains Shows only Data Objects where the name contains the following string. | ||
* @return | ||
*/ | ||
public static ListOfDataObjectsResult ListDataObjects(String token, LicenseKey license, String contains) { | ||
return ListDataObjects(token, new ListDataObjectsToKeyModel(license.ProductId, license.Key, contains)); | ||
} | ||
|
||
public static ListOfDataObjectsResult ListDataObjects(String token, ListDataObjectsToKeyModel model) { | ||
|
||
Map<String,String> extraParams = new HashMap<>(); | ||
|
||
extraParams.put("token", token); | ||
|
||
return HelperMethods.SendRequestToWebAPI("data/listdataobjectstokey", model, extraParams, ListOfDataObjectsResult.class); | ||
} | ||
|
||
/** | ||
* This method will assign a new integer value to a Data Object. | ||
* @param token The access token with 'SetIntValue' permission and KeyLock set to '-1'. | ||
* @param license The license key object (it's used to get the product id and key string). | ||
* @param id The unique object id for the data object. | ||
* @param intValue The new int value that should be assigned to the data object. | ||
* @return | ||
*/ | ||
public static BasicResult SetIntValue(String token, LicenseKey license, long id, int intValue) { | ||
return SetIntValue(token, new SetIntValueToKeyModel(license.ProductId, license.Key, id, intValue)); | ||
} | ||
|
||
public static BasicResult SetIntValue(String token, SetIntValueToKeyModel model) { | ||
|
||
Map<String,String> extraParams = new HashMap<>(); | ||
|
||
extraParams.put("token", token); | ||
|
||
return HelperMethods.SendRequestToWebAPI("data/setintvaluetokey", model, extraParams, BasicResult.class); | ||
} | ||
|
||
/** | ||
* This method will increment the integer value in a Data Object by a certain constant (non-negative). | ||
* You can always decrement it. Note, this method does not allow integer overflows, i.e. if you increment | ||
* by a constant that would result in an overflow, an error will be thrown. Note also that you can use the Feature lock | ||
* in the Access Token to specify the upper bound of the increment constant. So, if you only want to allow incrementing | ||
* by 1, please set Feature lock field to 1 also. Please see Remarks for more details (including access token set up). | ||
* @param token The access token with 'IncrementIntValue' permission and KeyLock set to '-1'. | ||
* @param license The license key object (it's used to get the product id and key string). | ||
* @param id The unique object id for the data object. | ||
* @param intValue The constant int (non-negative) value that should be added to the current | ||
* IntValue of the data object. For example, if this value is set to 5 and the | ||
* old IntValue is 1, then the new IntValue will be the old one plus 5, i.e. 6. | ||
* Note, if you would set this value to -5 instead, the same result would be achieved. | ||
* @return | ||
*/ | ||
public static BasicResult IncrementIntValue(String token, LicenseKey license, long id, int intValue) { | ||
return IncrementIntValue(token, new IncrementIntValueToKeyModel(license.ProductId, license.Key, id, intValue, false, 0)); | ||
} | ||
|
||
/** | ||
* This method will increment the integer value in a Data Object by a certain constant (non-negative). | ||
* You can always decrement it. Note, this method does not allow integer overflows, i.e. if you increment | ||
* by a constant that would result in an overflow, an error will be thrown. Note also that you can use the Feature lock | ||
* in the Access Token to specify the upper bound of the increment constant. So, if you only want to allow incrementing | ||
* by 1, please set Feature lock field to 1 also. Please see Remarks for more details (including access token set up). | ||
* @param token The access token with 'IncrementIntValue' permission and KeyLock set to '-1'. | ||
* @param license The license key object (it's used to get the product id and key string). | ||
* @param id The unique object id for the data object. | ||
* @param intValue The constant int (non-negative) value that should be added to the current | ||
* IntValue of the data object. For example, if this value is set to 5 and the | ||
* old IntValue is 1, then the new IntValue will be the old one plus 5, i.e. 6. | ||
* Note, if you would set this value to -5 instead, the same result would be achieved. | ||
* @param enableBound If set to true, it will be possible to specify an upper bound. For example, | ||
* if you set the Bound parameter (below) to 10, you will be able to increment | ||
* the int value until you reach ten (inclusive). Once the upper bound is reached, | ||
* an error will be thrown. | ||
* @param bound This is the upper bound that will be enforced on the increment operation. | ||
* It will only be enforced if EnableBound is set to true. Please read the description about enableBound. | ||
* @return | ||
*/ | ||
public static BasicResult IncrementIntValue(String token, LicenseKey license, long id, int intValue, boolean enableBound, int bound) { | ||
return IncrementIntValue(token, new IncrementIntValueToKeyModel(license.ProductId, license.Key, id, intValue, enableBound, bound)); | ||
} | ||
|
||
public static BasicResult IncrementIntValue(String token, IncrementIntValueToKeyModel model) { | ||
|
||
Map<String,String> extraParams = new HashMap<>(); | ||
|
||
extraParams.put("token", token); | ||
|
||
return HelperMethods.SendRequestToWebAPI("data/incrementintvaluetokey", model, extraParams, BasicResult.class); | ||
} | ||
|
||
/** | ||
* This method will decrement the integer value in a Data Object by a certain constant (non-negative). | ||
* You can always increment it. Note, this method does not allow integer overflows, i.e. if you decrement | ||
* by a constant that would result in an overflow, an error will be thrown. Note also that you can use the | ||
* Feature lock in the Access Token to specify the upper bound of the decrement constant. So, if you only | ||
* want to allow decrementing by 1, please set Feature lock field to 1 also. Please see Remarks for more | ||
* details (including access token setup). | ||
* @param token The access token with 'SetIntValue' permission and KeyLock set to '-1'. | ||
* @param license The license key object (it's used to get the product id and key string). | ||
* @param id The unique object id for the data object. | ||
* @param intValue The constant int value that should be subtracted to the current IntValue of the data object. | ||
* For example, if this value is set to 5 and the old IntValue is 11, then the new IntValue | ||
* will be the old one minus 5, i.e. 6. Note, if you would set this value to -5 instead, the | ||
* same result would be achieved. | ||
* @return | ||
*/ | ||
public static BasicResult DecrementIntValue(String token, LicenseKey license, long id, int intValue) { | ||
return DecrementIntValue(token, new DecrementIntValueToKeyModel(license.ProductId, license.Key, id, intValue, false, 0)); | ||
} | ||
|
||
/** | ||
* This method will decrement the integer value in a Data Object by a certain constant (non-negative). | ||
* You can always increment it. Note, this method does not allow integer overflows, i.e. if you decrement | ||
* by a constant that would result in an overflow, an error will be thrown. Note also that you can use the | ||
* Feature lock in the Access Token to specify the upper bound of the decrement constant. So, if you only | ||
* want to allow decrementing by 1, please set Feature lock field to 1 also. Please see Remarks for more | ||
* details (including access token setup). | ||
* @param token The access token with 'SetIntValue' permission and KeyLock set to '-1'. | ||
* @param license The license key object (it's used to get the product id and key string). | ||
* @param id The unique object id for the data object. | ||
* @param intValue The constant int value that should be subtracted to the current IntValue of the data object. | ||
* For example, if this value is set to 5 and the old IntValue is 11, then the new IntValue | ||
* will be the old one minus 5, i.e. 6. Note, if you would set this value to -5 instead, the | ||
* same result would be achieved. | ||
* @param enableBound If set to true, it will be possible to specify a lower bound. For example, if you set the Bound | ||
* parameter (below) to 0, you will be able to decrement the int value until you reach zero (inclusive). | ||
* Once the lower bound is reached, an error will be thrown. | ||
* @param bound This is the lower bound that will be enforced on the decrement operation. It will only be enforced if | ||
* EnableBound is set to true. Please read the description above. | ||
* @return | ||
*/ | ||
public static BasicResult DecrementIntValue(String token, LicenseKey license, long id, int intValue, boolean enableBound, int bound) { | ||
return DecrementIntValue(token, new DecrementIntValueToKeyModel(license.ProductId, license.Key, id, intValue, enableBound, bound)); | ||
} | ||
|
||
public static BasicResult DecrementIntValue(String token, DecrementIntValueToKeyModel model) { | ||
|
||
Map<String,String> extraParams = new HashMap<>(); | ||
|
||
extraParams.put("token", token); | ||
|
||
return HelperMethods.SendRequestToWebAPI("data/decrementintvaluetokey", model, extraParams, BasicResult.class); | ||
} | ||
|
||
/** | ||
* This method will assign a new string value to a Data Object. | ||
* @param token The access token with 'SetIntValue' permission and KeyLock set to '-1'. | ||
* @param license The license key object (it's used to get the product id and key string). | ||
* @param id The unique object id for the data object. | ||
* @param stringValue A string value (text) to store. Max 10000 characters. | ||
* @return | ||
*/ | ||
public static BasicResult SetStringValue(String token, LicenseKey license, long id, String stringValue) { | ||
return SetStringValue(token, new SetStringValueToKeyModel(license.ProductId, license.Key, id, stringValue)); | ||
} | ||
|
||
public static BasicResult SetStringValue(String token, SetStringValueToKeyModel model) { | ||
|
||
Map<String,String> extraParams = new HashMap<>(); | ||
|
||
extraParams.put("token", token); | ||
|
||
return HelperMethods.SendRequestToWebAPI("data/setstringvaluetokey", model, extraParams, BasicResult.class); | ||
} | ||
|
||
/** | ||
* This method will remove an existing Data Object. | ||
* @param token The access token with 'SetIntValue' permission and KeyLock set to '-1'. | ||
* @param license The license key object (it's used to get the product id and key string). | ||
* @param id A string value (text) to store. Max 10000 characters. | ||
* @return | ||
*/ | ||
public static BasicResult RemoveDataObject(String token, LicenseKey license, long id) { | ||
return RemoveDataObject(token, new RemoveDataObjectToKeyModel(license.ProductId, license.Key, id)); | ||
} | ||
|
||
public static BasicResult RemoveDataObject(String token, RemoveDataObjectToKeyModel model) { | ||
|
||
Map<String,String> extraParams = new HashMap<>(); | ||
|
||
extraParams.put("token", token); | ||
|
||
return HelperMethods.SendRequestToWebAPI("data/removedataobjecttokey", model, extraParams, BasicResult.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/io/cryptolens/models/AddDataObjectToKeyModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.cryptolens.models; | ||
|
||
public class AddDataObjectToKeyModel extends ProductAndKeyModel { | ||
/** | ||
* The name of the data object. Max 10 characters. | ||
*/ | ||
public String Name; | ||
/** | ||
* An int value (int32) to store. | ||
*/ | ||
public int IntValue; | ||
/** | ||
* A string value (text) to store. Max 10000 characters. | ||
*/ | ||
public String StringValue; | ||
|
||
public AddDataObjectToKeyModel(int productId, String key, String name, int intValue, String stringValue) { | ||
Name = name; | ||
StringValue = stringValue; | ||
IntValue = intValue; | ||
this.ProductId = productId; | ||
this.Key = key; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
package io.cryptolens.models; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
|
||
public class DataObject { | ||
@SerializedName(value = "id", alternate = {"Id"}) | ||
public int Id; | ||
@SerializedName(value = "name", alternate = {"Name"}) | ||
public String Name; | ||
@SerializedName(value = "stringValue", alternate = {"StringValue"}) | ||
public String StringValue; | ||
@SerializedName(value = "intValue", alternate = {"IntValue"}) | ||
public int IntValue; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/io/cryptolens/models/DecrementIntValueToKeyModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.cryptolens.models; | ||
|
||
public class DecrementIntValueToKeyModel extends ProductAndKeyModel { | ||
public long Id; | ||
public int IntValue; | ||
public boolean EnableBound; | ||
public int Bound; | ||
|
||
public DecrementIntValueToKeyModel(int productId, String key, long id, int intValue, boolean enableBound, int bound) { | ||
Id = id; | ||
IntValue = intValue; | ||
this.ProductId = productId; | ||
this.Key = key; | ||
this.EnableBound = enableBound; | ||
this.Bound = bound; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/io/cryptolens/models/IncrementIntValueToKeyModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.cryptolens.models; | ||
|
||
public class IncrementIntValueToKeyModel extends ProductAndKeyModel { | ||
public long Id; | ||
public int IntValue; | ||
public boolean EnableBound; | ||
public int Bound; | ||
|
||
public IncrementIntValueToKeyModel(int productId, String key, long id, int intValue, boolean enableBound, int bound) { | ||
Id = id; | ||
this.IntValue = intValue; | ||
this.ProductId = productId; | ||
this.Key = key; | ||
this.EnableBound = enableBound; | ||
this.Bound = bound; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/io/cryptolens/models/ListDataObjectsToKeyModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package io.cryptolens.models; | ||
|
||
public class ListDataObjectsToKeyModel extends ProductAndKeyModel { | ||
public String Contains = ""; | ||
|
||
public ListDataObjectsToKeyModel(int productId, String key, String contains) { | ||
Contains = contains; | ||
this.ProductId = productId; | ||
this.Key = key; | ||
} | ||
} |
Oops, something went wrong.