Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions licensing/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,147 @@ def remove_data_object_to_key(token, product_id, key, object_id=0, name = ""):
return (None, "Could not contact the server.")

return (jobj, "")

@staticmethod
def add_data_object_to_machine(token, product_id, key, machine_code, name = "", string_value="",\
int_value=0, check_for_duplicates=False):

"""
This method will add a new Data Object to Machine.

More docs: https://app.cryptolens.io/docs/api/v3/AddDataObject (see parameters under Method 3)
"""

try:
response = HelperMethods.send_request("/data/AddDataObjectToMachineCode/",\
{"token":token,\
"ProductId" : product_id,\
"Key" : key,\
"Name" : name,\
"IntValue": int_value ,\
"StringValue": string_value ,\
"CheckForDuplicates" : str(check_for_duplicates), \
"MachineCode": machine_code
})
except HTTPError as e:
response = e.read()
except URLError as e:
return (None, "Could not contact the server. Error message: " + str(e))
except Exception:
return (None, "Could not contact the server.")

jobj = json.loads(response)

if jobj == None or not("result" in jobj) or jobj["result"] == 1:
if jobj != None:
return (None, jobj["message"])
else:
return (None, "Could not contact the server.")

return (jobj, "")

@staticmethod
def remove_data_object_to_machine(token, product_id, key, machine_code, object_id=0, name = ""):

"""
This method will remove existing Data Object from Machine Code.

More docs: https://app.cryptolens.io/docs/api/v3/RemoveDataObject (see parameters under Method 3)
"""

try:
response = HelperMethods.send_request("/data/RemoveDataObjectToMachineCode/",\
{"token":token,\
"ProductId" : product_id,\
"Key" : key,\
"MachineCode": machine_code,\
"Name" : name,\
"Id": object_id })
except HTTPError as e:
response = e.read()
except URLError as e:
return (None, "Could not contact the server. Error message: " + str(e))
except Exception:
return (None, "Could not contact the server.")

jobj = json.loads(response)

if jobj == None or not("result" in jobj) or jobj["result"] == 1:
if jobj != None:
return (None, jobj["message"])
else:
return (None, "Could not contact the server.")

return (jobj, "")

@staticmethod
def list_machine_data_objects(token, product_id, key, machine_code, \
name_contains=""):

"""
This method will list Data Objects for Machine.

More docs: https://app.cryptolens.io/docs/api/v3/ListDataObjects (see parameters under Method 3)
"""

try:
response = HelperMethods.send_request("/data/ListDataObjectsToMachineCode/",\
{"token":token,\
"ProductId" : product_id,\
"Key" : key,\
"MachineCode": machine_code,\
"Contains": name_contains
})
except HTTPError as e:
response = e.read()
except URLError as e:
return (None, "Could not contact the server. Error message: " + str(e))
except Exception:
return (None, "Could not contact the server.")

jobj = json.loads(response)

if jobj == None or not("result" in jobj) or jobj["result"] == 1:
if jobj != None:
return (None, jobj["message"])
else:
return (None, "Could not contact the server.")

return (jobj, "")

@staticmethod
def list_key_data_objects(token, product_id, key, \
name_contains=""):

"""
This method will list Data Objects for License Key.

More docs: https://app.cryptolens.io/docs/api/v3/ListDataObjects (see parameters under Method 2)
"""

try:
response = HelperMethods.send_request("/data/ListDataObjectsToKey/",\
{"token":token,\
"ProductId" : product_id,\
"Key" : key,\
"Contains": name_contains
})
except HTTPError as e:
response = e.read()
except URLError as e:
return (None, "Could not contact the server. Error message: " + str(e))
except Exception:
return (None, "Could not contact the server.")

jobj = json.loads(response)

if jobj == None or not("result" in jobj) or jobj["result"] == 1:
if jobj != None:
return (None, jobj["message"])
else:
return (None, "Could not contact the server.")

return (jobj, "")


class PaymentForm:
Expand Down