Skip to content

Commit 2691075

Browse files
synominitartemlos
andauthored
More api methods for working with data objects (#48)
* Added add data object to machine method * Added method to remove data object from machine * Added method to list machine data objects * Added method to list data objects for key * Update the reference to method parameters Co-authored-by: Artem Los <[email protected]>
1 parent f4747b5 commit 2691075

File tree

1 file changed

+141
-0
lines changed

1 file changed

+141
-0
lines changed

licensing/methods.py

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,147 @@ def remove_data_object_to_key(token, product_id, key, object_id=0, name = ""):
770770
return (None, "Could not contact the server.")
771771

772772
return (jobj, "")
773+
774+
@staticmethod
775+
def add_data_object_to_machine(token, product_id, key, machine_code, name = "", string_value="",\
776+
int_value=0, check_for_duplicates=False):
777+
778+
"""
779+
This method will add a new Data Object to Machine.
780+
781+
More docs: https://app.cryptolens.io/docs/api/v3/AddDataObject (see parameters under Method 3)
782+
"""
783+
784+
try:
785+
response = HelperMethods.send_request("/data/AddDataObjectToMachineCode/",\
786+
{"token":token,\
787+
"ProductId" : product_id,\
788+
"Key" : key,\
789+
"Name" : name,\
790+
"IntValue": int_value ,\
791+
"StringValue": string_value ,\
792+
"CheckForDuplicates" : str(check_for_duplicates), \
793+
"MachineCode": machine_code
794+
})
795+
except HTTPError as e:
796+
response = e.read()
797+
except URLError as e:
798+
return (None, "Could not contact the server. Error message: " + str(e))
799+
except Exception:
800+
return (None, "Could not contact the server.")
801+
802+
jobj = json.loads(response)
803+
804+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
805+
if jobj != None:
806+
return (None, jobj["message"])
807+
else:
808+
return (None, "Could not contact the server.")
809+
810+
return (jobj, "")
811+
812+
@staticmethod
813+
def remove_data_object_to_machine(token, product_id, key, machine_code, object_id=0, name = ""):
814+
815+
"""
816+
This method will remove existing Data Object from Machine Code.
817+
818+
More docs: https://app.cryptolens.io/docs/api/v3/RemoveDataObject (see parameters under Method 3)
819+
"""
820+
821+
try:
822+
response = HelperMethods.send_request("/data/RemoveDataObjectToMachineCode/",\
823+
{"token":token,\
824+
"ProductId" : product_id,\
825+
"Key" : key,\
826+
"MachineCode": machine_code,\
827+
"Name" : name,\
828+
"Id": object_id })
829+
except HTTPError as e:
830+
response = e.read()
831+
except URLError as e:
832+
return (None, "Could not contact the server. Error message: " + str(e))
833+
except Exception:
834+
return (None, "Could not contact the server.")
835+
836+
jobj = json.loads(response)
837+
838+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
839+
if jobj != None:
840+
return (None, jobj["message"])
841+
else:
842+
return (None, "Could not contact the server.")
843+
844+
return (jobj, "")
845+
846+
@staticmethod
847+
def list_machine_data_objects(token, product_id, key, machine_code, \
848+
name_contains=""):
849+
850+
"""
851+
This method will list Data Objects for Machine.
852+
853+
More docs: https://app.cryptolens.io/docs/api/v3/ListDataObjects (see parameters under Method 3)
854+
"""
855+
856+
try:
857+
response = HelperMethods.send_request("/data/ListDataObjectsToMachineCode/",\
858+
{"token":token,\
859+
"ProductId" : product_id,\
860+
"Key" : key,\
861+
"MachineCode": machine_code,\
862+
"Contains": name_contains
863+
})
864+
except HTTPError as e:
865+
response = e.read()
866+
except URLError as e:
867+
return (None, "Could not contact the server. Error message: " + str(e))
868+
except Exception:
869+
return (None, "Could not contact the server.")
870+
871+
jobj = json.loads(response)
872+
873+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
874+
if jobj != None:
875+
return (None, jobj["message"])
876+
else:
877+
return (None, "Could not contact the server.")
878+
879+
return (jobj, "")
880+
881+
@staticmethod
882+
def list_key_data_objects(token, product_id, key, \
883+
name_contains=""):
884+
885+
"""
886+
This method will list Data Objects for License Key.
887+
888+
More docs: https://app.cryptolens.io/docs/api/v3/ListDataObjects (see parameters under Method 2)
889+
"""
890+
891+
try:
892+
response = HelperMethods.send_request("/data/ListDataObjectsToKey/",\
893+
{"token":token,\
894+
"ProductId" : product_id,\
895+
"Key" : key,\
896+
"Contains": name_contains
897+
})
898+
except HTTPError as e:
899+
response = e.read()
900+
except URLError as e:
901+
return (None, "Could not contact the server. Error message: " + str(e))
902+
except Exception:
903+
return (None, "Could not contact the server.")
904+
905+
jobj = json.loads(response)
906+
907+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
908+
if jobj != None:
909+
return (None, jobj["message"])
910+
else:
911+
return (None, "Could not contact the server.")
912+
913+
return (jobj, "")
773914

774915

775916
class PaymentForm:

0 commit comments

Comments
 (0)