Skip to content

Commit bded08c

Browse files
committed
Add GetEvents and Register Event
1 parent ff90dce commit bded08c

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

licensing/methods.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,88 @@ def get_web_api_log(token, product_id = 0, key = "", machine_code="", friendly_n
409409
return (None, "Could not contact the server.")
410410

411411
return (jobj["logs"], "")
412+
413+
@staticmethod
414+
def get_events(token, limit = 10, starting_after = 0, product_id = 0,\
415+
key = "", metadata = ""):
416+
417+
"""
418+
This method will retrieve events that were registered using Register event method.
419+
420+
More docs: https://app.cryptolens.io/api/ai/GetEvents
421+
"""
422+
423+
response = ""
424+
425+
try:
426+
response = HelperMethods.send_request("ai/GetEvents", {"token":token,\
427+
"ProductId":product_id,\
428+
"Key" : key,\
429+
"Limit": limit,\
430+
"StartingAfter": starting_after})
431+
except HTTPError as e:
432+
response = e.read()
433+
except URLError as e:
434+
return (None, "Could not contact the server. Error message: " + str(e))
435+
except Exception:
436+
return (None, "Could not contact the server.")
437+
438+
jobj = json.loads(response)
439+
440+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
441+
if jobj != None:
442+
return (None, jobj["message"])
443+
else:
444+
return (None, "Could not contact the server.")
445+
446+
return (jobj["events"], "")
447+
448+
@staticmethod
449+
def register_event(token, product_id=0, key="", machine_code="", feature_name ="",\
450+
event_name="", value=0, currency="", metadata=""):
451+
"""
452+
This method will register an event that has occured in either
453+
the client app (eg. start of a certain feature or interaction
454+
within a feature) or in a third party provider (eg. a payment
455+
has occured, etc).
456+
457+
Note: You can either use this method standalone (eg. by only
458+
providing a machine code/device identifier) or together with
459+
Cryptolens Licensing module (which requires productId and
460+
optionally keyid to be set). The more information that is
461+
provided, the better insights can be provided.
462+
463+
More docs: https://app.cryptolens.io/api/ai/RegisterEvent
464+
"""
465+
466+
response = ""
467+
468+
try:
469+
response = HelperMethods.send_request("/ai/RegisterEvent", {"token":token,\
470+
"ProductId":product_id,\
471+
"Key" : key,\
472+
"MachineCode" : machine_code,\
473+
"FeatureName" : feature_name,\
474+
"EventName": event_name,\
475+
"Value" : value,\
476+
"Currency": currency,\
477+
"Metadata" : metadata})
478+
except HTTPError as e:
479+
response = e.read()
480+
except URLError as e:
481+
return (None, "Could not contact the server. Error message: " + str(e))
482+
except Exception:
483+
return (None, "Could not contact the server.")
484+
485+
jobj = json.loads(response)
486+
487+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
488+
if jobj != None:
489+
return (False, jobj["message"])
490+
else:
491+
return (False, "Could not contact the server.")
492+
493+
return (True, jobj["message"])
412494

413495
class Message:
414496

0 commit comments

Comments
 (0)