From ed5ceedb067c811be0b5ffb30004b6265f570b20 Mon Sep 17 00:00:00 2001 From: Skye Pham M <58667176+synominit@users.noreply.github.com> Date: Thu, 28 Oct 2021 11:21:11 -0400 Subject: [PATCH 01/10] Added add data object to machine method --- licensing/methods.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/licensing/methods.py b/licensing/methods.py index b34ed5e..9b03473 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -770,6 +770,44 @@ 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 2) + """ + + 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, "") class PaymentForm: From caa83eb06a31c906e7ea77ddcad5092687e98116 Mon Sep 17 00:00:00 2001 From: Skye Pham M <58667176+synominit@users.noreply.github.com> Date: Thu, 28 Oct 2021 11:43:54 -0400 Subject: [PATCH 02/10] Added method to remove data object from machine --- licensing/methods.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/licensing/methods.py b/licensing/methods.py index 9b03473..5c123b9 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -808,6 +808,40 @@ def add_data_object_to_machine(token, product_id, key, machine_code, name = "", 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 2) + """ + + 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, "") class PaymentForm: From 1b46e6aed01dd1452bdf9ce92c0cd3775dcb6a5c Mon Sep 17 00:00:00 2001 From: Skye Pham M <58667176+synominit@users.noreply.github.com> Date: Thu, 28 Oct 2021 11:45:54 -0400 Subject: [PATCH 03/10] Added method to list machine data objects --- licensing/methods.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/licensing/methods.py b/licensing/methods.py index 5c123b9..6dc003b 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -842,6 +842,41 @@ def remove_data_object_to_machine(token, product_id, key, machine_code, object_i 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 2) + """ + + 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, "") class PaymentForm: From c64ec7b5b24a87e322bfccc9eea38004ae91c39f Mon Sep 17 00:00:00 2001 From: Skye Pham M <58667176+synominit@users.noreply.github.com> Date: Thu, 28 Oct 2021 11:51:51 -0400 Subject: [PATCH 04/10] Added method to list data objects for key --- licensing/methods.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/licensing/methods.py b/licensing/methods.py index 6dc003b..b31f2a8 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -877,6 +877,40 @@ def list_machine_data_objects(token, product_id, key, machine_code, \ 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: From 252f49c5fb9862ee0bf34bad4e1c67359bd1f656 Mon Sep 17 00:00:00 2001 From: Artem Los Date: Mon, 1 Nov 2021 15:49:53 +0100 Subject: [PATCH 05/10] Update the reference to method parameters --- licensing/methods.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/licensing/methods.py b/licensing/methods.py index b31f2a8..fb6b575 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -778,7 +778,7 @@ def add_data_object_to_machine(token, product_id, key, machine_code, name = "", """ This method will add a new Data Object to Machine. - More docs: https://app.cryptolens.io/docs/api/v3/AddDataObject (see parameters under Method 2) + More docs: https://app.cryptolens.io/docs/api/v3/AddDataObject (see parameters under Method 3) """ try: @@ -815,7 +815,7 @@ def remove_data_object_to_machine(token, product_id, key, machine_code, object_i """ This method will remove existing Data Object from Machine Code. - More docs: https://app.cryptolens.io/docs/api/v3/RemoveDataObject (see parameters under Method 2) + More docs: https://app.cryptolens.io/docs/api/v3/RemoveDataObject (see parameters under Method 3) """ try: @@ -850,7 +850,7 @@ def list_machine_data_objects(token, product_id, key, machine_code, \ """ This method will list Data Objects for Machine. - More docs: https://app.cryptolens.io/docs/api/v3/ListDataObjects (see parameters under Method 2) + More docs: https://app.cryptolens.io/docs/api/v3/ListDataObjects (see parameters under Method 3) """ try: From 60104c96d5382027ef45f3be3785ff7b38ff4902 Mon Sep 17 00:00:00 2001 From: Skye Pham M <58667176+synominit@users.noreply.github.com> Date: Thu, 16 Dec 2021 13:53:14 -0500 Subject: [PATCH 06/10] Added Subscription and Analytics Classes Added Subscription Class with method to increment meter for stripe billing. Added Analytics Class with methods to register single events and get events. --- licensing/methods.py | 122 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) diff --git a/licensing/methods.py b/licensing/methods.py index fb6b575..fb667b7 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -1081,4 +1081,124 @@ def HasFeature(license_key, feature_name): if not(found): return False - return True \ No newline at end of file + return True + +class Subscription: + """ + Subscription related methods + """ + + @staticmethod + def record_usage_to_stripe(token, product_id, key, amount=""): + + """ + This method records uses Stripe's metered billing to record usage for a certain subscription. In order to use this mehtod, + you need to have set up recurring billing. A record will be created using Stripe's API with action set to 'increment' + + When creating an access token to this method, remember to include "Subscription" permission and + set the "Lock to key" value to -1. + + More docs: https://app.cryptolens.io/docs/api/v3/RecordUsage (see parameters under Method 3) + """ + + try: + response = HelperMethods.send_request("/subscription/RecordUsage/",\ + {"token":token,\ + "ProductId" : product_id,\ + "Key" : key,\ + "Amount" : amount, + }) + 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 Analytics: + """ + Analytics related methods + """ + + @staticmethod + def register_single_event(token, product_id="", key="", machine_code="", feature_name="", event_name="", value="", currency="", metadata=""): + + """ + This method will register an event that has occured in either the + client app (eg. start of a certain feature or interaction within a feature) + or in a third party provider (eg. a payment has occured, etc). + + More docs: https://app.cryptolens.io/docs/api/v3/RegisterEvent (see parameters under Method 3) + """ + + try: + response = HelperMethods.send_request("/ai/RegisterEvent/",\ + {"token":token,\ + "ProductId" : product_id,\ + "Key" : key,\ + "MachineCode" : machine_code,\ + "FeatureName" : feature_name,\ + "EventName" : event_name,\ + "Value" : value,\ + "Currency": currency,\ + "Metadata" : metadata + }) + 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 get_events(token, product_id="", key="", metadata=""): + + """ + This method will retrieve events that were registered using Register event method. + + More docs: https://app.cryptolens.io/docs/api/v3/GetEvents (see parameters under Method 3) + """ + + try: + response = HelperMethods.send_request("/ai/GetEvents/",\ + {"token":token,\ + "ProductId" : product_id,\ + "Key" : key,\ + "Metadata" : metadata + }) + 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, "") \ No newline at end of file From da8f632318f8df0f441c49de34476d5ca46ac64d Mon Sep 17 00:00:00 2001 From: David Pham <58667176+synominit@users.noreply.github.com> Date: Thu, 16 Dec 2021 14:04:28 -0500 Subject: [PATCH 07/10] Update methods.py --- licensing/methods.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/licensing/methods.py b/licensing/methods.py index fb667b7..677b39c 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -1093,10 +1093,7 @@ def record_usage_to_stripe(token, product_id, key, amount=""): """ This method records uses Stripe's metered billing to record usage for a certain subscription. In order to use this mehtod, - you need to have set up recurring billing. A record will be created using Stripe's API with action set to 'increment' - - When creating an access token to this method, remember to include "Subscription" permission and - set the "Lock to key" value to -1. + you need to have set up recurring billing. A record will be created using Stripe's API with action set to 'increment' More docs: https://app.cryptolens.io/docs/api/v3/RecordUsage (see parameters under Method 3) """ @@ -1201,4 +1198,4 @@ def get_events(token, product_id="", key="", metadata=""): else: return (None, "Could not contact the server.") - return (jobj, "") \ No newline at end of file + return (jobj, "") From 0c3d0781a23bf0b9283506aca0774844d591a9c4 Mon Sep 17 00:00:00 2001 From: David Pham <58667176+synominit@users.noreply.github.com> Date: Thu, 16 Dec 2021 14:09:09 -0500 Subject: [PATCH 08/10] Removed Redundant Analytics class (See AI Class) --- licensing/methods.py | 78 -------------------------------------------- 1 file changed, 78 deletions(-) diff --git a/licensing/methods.py b/licensing/methods.py index 677b39c..77a6620 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -1121,81 +1121,3 @@ def record_usage_to_stripe(token, product_id, key, amount=""): return (None, "Could not contact the server.") return (jobj, "") - -class Analytics: - """ - Analytics related methods - """ - - @staticmethod - def register_single_event(token, product_id="", key="", machine_code="", feature_name="", event_name="", value="", currency="", metadata=""): - - """ - This method will register an event that has occured in either the - client app (eg. start of a certain feature or interaction within a feature) - or in a third party provider (eg. a payment has occured, etc). - - More docs: https://app.cryptolens.io/docs/api/v3/RegisterEvent (see parameters under Method 3) - """ - - try: - response = HelperMethods.send_request("/ai/RegisterEvent/",\ - {"token":token,\ - "ProductId" : product_id,\ - "Key" : key,\ - "MachineCode" : machine_code,\ - "FeatureName" : feature_name,\ - "EventName" : event_name,\ - "Value" : value,\ - "Currency": currency,\ - "Metadata" : metadata - }) - 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 get_events(token, product_id="", key="", metadata=""): - - """ - This method will retrieve events that were registered using Register event method. - - More docs: https://app.cryptolens.io/docs/api/v3/GetEvents (see parameters under Method 3) - """ - - try: - response = HelperMethods.send_request("/ai/GetEvents/",\ - {"token":token,\ - "ProductId" : product_id,\ - "Key" : key,\ - "Metadata" : metadata - }) - 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, "") From cb73486b70eab038f4d2fce9d4a14d93bda12169 Mon Sep 17 00:00:00 2001 From: Artem Los Date: Tue, 28 Dec 2021 16:34:33 +0100 Subject: [PATCH 09/10] Small typo fix --- licensing/methods.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/licensing/methods.py b/licensing/methods.py index 77a6620..003b19d 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -1092,7 +1092,7 @@ class Subscription: def record_usage_to_stripe(token, product_id, key, amount=""): """ - This method records uses Stripe's metered billing to record usage for a certain subscription. In order to use this mehtod, + This method records uses Stripe's metered billing to record usage for a certain subscription. In order to use this method, you need to have set up recurring billing. A record will be created using Stripe's API with action set to 'increment' More docs: https://app.cryptolens.io/docs/api/v3/RecordUsage (see parameters under Method 3) From 8a2d5b6abff3bedd051ceb201b84340eca144a0e Mon Sep 17 00:00:00 2001 From: Artem Los Date: Tue, 28 Dec 2021 16:36:47 +0100 Subject: [PATCH 10/10] Update methods.py --- licensing/methods.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/licensing/methods.py b/licensing/methods.py index 003b19d..4250cba 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -1095,7 +1095,7 @@ def record_usage_to_stripe(token, product_id, key, amount=""): This method records uses Stripe's metered billing to record usage for a certain subscription. In order to use this method, you need to have set up recurring billing. A record will be created using Stripe's API with action set to 'increment' - More docs: https://app.cryptolens.io/docs/api/v3/RecordUsage (see parameters under Method 3) + More docs: https://app.cryptolens.io/docs/api/v3/RecordUsage """ try: