From 69b1b365d8e3affe45e34864800fcc3a3913b7d7 Mon Sep 17 00:00:00 2001 From: Artem Los Date: Thu, 14 Mar 2019 09:35:42 +0100 Subject: [PATCH 1/3] Start on get_events --- licensing/methods.py | 22 ++++++++++++++++++++++ licensing/models.py | 12 ++++++++++++ test.py | 7 +++++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/licensing/methods.py b/licensing/methods.py index f88e5fa..9a91113 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -10,6 +10,28 @@ import sys from licensing.internal import HelperMethods from licensing.models import * +import json + +class AI: + + def get_events(token, limit=10, starting_after=None): + + response = HelperMethods.send_request("ai/getevents", \ + {"token":token,\ + "limit":limit, \ + "startingafter":starting_after}) + + jobj = json.loads(response) + + arr = [] + + for item in jobj["events"]: + arr.append(Event(**item)) + + + return arr + + class Key: diff --git a/licensing/models.py b/licensing/models.py index 4478f50..37b0de1 100644 --- a/licensing/models.py +++ b/licensing/models.py @@ -127,6 +127,18 @@ def __load_activated_machines(obj): arr.append(ActivatedMachine(**item)) return arr + +class Event: + + def __init__(self, currency, eventName, featureName, id, key, machineCode, productId, time, value): + self.currency = currency + self.event_name = eventName + self.feature_name = featureName + self.id = id + self.machine_code = machineCode + self.product_id = productId + self.time = time + self.value = value class Response: diff --git a/test.py b/test.py index 0523363..104780a 100644 --- a/test.py +++ b/test.py @@ -6,7 +6,7 @@ """ from licensing.models import * -from licensing.methods import Key, Helpers +from licensing.methods import Key, Helpers, AI pubKey = "sGbvxwdlDbqFXOMlVUnAF5ew0t0WpPW7rFpI5jHQOFkht/326dvh7t74RYeMpjy357NljouhpTLA3a6idnn4j6c3jmPWBkjZndGsPL4Bqm+fwE48nKpGPjkj4q/yzT4tHXBTyvaBjA8bVoCTnu+LiC4XEaLZRThGzIn5KQXKCigg6tQRy0GXE13XYFVz/x1mjFbT9/7dS8p85n8BuwlY5JvuBIQkKhuCNFfrUxBWyu87CFnXWjIupCD2VO/GbxaCvzrRjLZjAngLCMtZbYBALksqGPgTUN7ZM24XbPWyLtKPaXF2i4XRR9u6eTj5BfnLbKAU5PIVfjIS+vNYYogteQ==AQAB" @@ -40,4 +40,7 @@ print("Feature 1: " + str(license_key.f1)) print("License expires: " + str(license_key.expires)) -print(Helpers.GetMachineCode()) \ No newline at end of file +print(Helpers.GetMachineCode()) + + +a = AI.get_events("WyIyOTk0Iiwid1ZZUUU4bVEyd2Z1VCtGL05aREpQb0p4VEkxYThRbEw1aGRpUHg3ZiJd") \ No newline at end of file From bfcd2d13e2bb5e5f8159af1b0249e990015a2f87 Mon Sep 17 00:00:00 2001 From: Artem Los Date: Thu, 14 Mar 2019 09:47:38 +0100 Subject: [PATCH 2/3] Update methods.py --- licensing/methods.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/licensing/methods.py b/licensing/methods.py index 9a91113..0d8a559 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -16,6 +16,14 @@ class AI: def get_events(token, limit=10, starting_after=None): + """ + This method will retrieve events that were registered using Register event method. + + :param limit: Specifies how many events should be returned (default 10, max 100). + :param starting_after: Works as a cursor (for pagination). If the last element had the id=125, then setting this to 125 will return all events coming after 125. + """ + + response = HelperMethods.send_request("ai/getevents", \ {"token":token,\ "limit":limit, \ @@ -23,6 +31,9 @@ def get_events(token, limit=10, starting_after=None): jobj = json.loads(response) + if jobj == None or jobj["result"] == "1": + return None + arr = [] for item in jobj["events"]: From a513f5e39ebd869abff76ff7cb8400add3fb8bbf Mon Sep 17 00:00:00 2001 From: Artem Los Date: Thu, 28 Mar 2019 09:28:47 +0100 Subject: [PATCH 3/3] Start on Get keys method (product) --- licensing/methods.py | 20 +++++++++++++++++++- test.py | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/licensing/methods.py b/licensing/methods.py index 0d8a559..c181d52 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -41,8 +41,26 @@ def get_events(token, limit=10, starting_after=None): return arr + + +""" +class Product: + + def get_keys(token, product_id, page = 1, order_by = "ID ascending", search_query = ""): - + response = HelperMethods.send_request("product/getkeys", \ + {"token":token,\ + "productId": product_id, \ + "orderby":order_by, \ + "searchquery": search_query}) + + jobj = json.loads(response) + + if jobj == None or jobj["result"] == "1": + return None + +""" + class Key: diff --git a/test.py b/test.py index 104780a..11d1364 100644 --- a/test.py +++ b/test.py @@ -43,4 +43,4 @@ print(Helpers.GetMachineCode()) -a = AI.get_events("WyIyOTk0Iiwid1ZZUUU4bVEyd2Z1VCtGL05aREpQb0p4VEkxYThRbEw1aGRpUHg3ZiJd") \ No newline at end of file +#a = AI.get_events("WyIyOTk0Iiwid1ZZUUU4bVEyd2Z1VCtGL05aREpQb0p4VEkxYThRbEw1aGRpUHg3ZiJd") \ No newline at end of file