Skip to content

Commit 568dac4

Browse files
authored
Add new methods related to a License Key (#68)
* Update methods.py * Update methods.py * Update methods.py * Update setup.py
1 parent 3df4ae2 commit 568dac4

File tree

2 files changed

+133
-1
lines changed

2 files changed

+133
-1
lines changed

licensing/methods.py

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,138 @@ def block_key(token, product_id, key):
414414
return (False, "Could not contact the server.")
415415

416416
return (True, jobj["message"])
417+
418+
def machine_lock_limit(token, product_id, key, number_of_machines):
419+
"""
420+
This method will change the maximum number of machine codes that
421+
a license key can have.
422+
423+
More docs: https://app.cryptolens.io/docs/api/v3/MachineLockLimit
424+
"""
425+
426+
response = ""
427+
428+
try:
429+
response = HelperMethods.send_request("/key/MachineLockLimit", {"token":token,\
430+
"ProductId":product_id,\
431+
"Key" : key,\
432+
"NumberOfMachines": number_of_machines})
433+
except HTTPError as e:
434+
response = e.read()
435+
except URLError as e:
436+
return (None, "Could not contact the server. Error message: " + str(e))
437+
except Exception:
438+
return (None, "Could not contact the server.")
439+
440+
jobj = json.loads(response)
441+
442+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
443+
if jobj != None:
444+
return (False, jobj["message"])
445+
else:
446+
return (False, "Could not contact the server.")
447+
448+
return (True, jobj["message"])
449+
450+
def change_notes(token, product_id, key, notes):
451+
"""
452+
This method will change the content of the notes field of
453+
a given license key.
454+
455+
More docs: https://app.cryptolens.io/docs/api/v3/ChangeNotes
456+
"""
457+
458+
response = ""
459+
460+
try:
461+
response = HelperMethods.send_request("/key/ChangeNotes", {"token":token,\
462+
"ProductId":product_id,\
463+
"Key" : key,\
464+
"Notes": notes})
465+
except HTTPError as e:
466+
response = e.read()
467+
except URLError as e:
468+
return (None, "Could not contact the server. Error message: " + str(e))
469+
except Exception:
470+
return (None, "Could not contact the server.")
471+
472+
jobj = json.loads(response)
473+
474+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
475+
if jobj != None:
476+
return (False, jobj["message"])
477+
else:
478+
return (False, "Could not contact the server.")
479+
480+
return (True, jobj["message"])
481+
482+
def change_reseller(token, product_id, key, reseller_id):
483+
"""
484+
This method will change the reseller of a license. If the reseller is
485+
not specified (for example, if ResellerId=0) or the reseller with the
486+
provided ID does not exist, any reseller that was previously associated
487+
with the license will be dissociated.
488+
489+
More docs: https://app.cryptolens.io/docs/api/v3/ChangeReseller
490+
"""
491+
492+
response = ""
493+
494+
try:
495+
response = HelperMethods.send_request("/key/ChangeReseller", {"token":token,\
496+
"ProductId":product_id,\
497+
"Key" : key,\
498+
"ResellerId": reseller_id})
499+
except HTTPError as e:
500+
response = e.read()
501+
except URLError as e:
502+
return (None, "Could not contact the server. Error message: " + str(e))
503+
except Exception:
504+
return (None, "Could not contact the server.")
505+
506+
jobj = json.loads(response)
507+
508+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
509+
if jobj != None:
510+
return (False, jobj["message"])
511+
else:
512+
return (False, "Could not contact the server.")
513+
514+
return (True, jobj["message"])
515+
516+
def create_key_from_template(token, license_template_id):
517+
"""
518+
This method will create a license key based on a License Template.
519+
If you want to see all the defined license templates through the API,
520+
this can be accomplished with Get License Templates. An alternative is
521+
to call the Create Key method, which allows you to specify all the
522+
parameters yourself. Note: the "feature lock" field in the access token
523+
can be used to restrict which license tempalte id can be used.
524+
525+
More docs: https://app.cryptolens.io/docs/api/v3/CreateKeyFromTemplate
526+
"""
527+
528+
response = ""
529+
530+
try:
531+
response = HelperMethods.send_request("/key/CreateKeyFromTemplate", {"token":token,\
532+
"LicenseTemplateId": license_template_id})
533+
except HTTPError as e:
534+
response = e.read()
535+
except URLError as e:
536+
return (None, "Could not contact the server. Error message: " + str(e))
537+
except Exception:
538+
return (None, "Could not contact the server.")
539+
540+
jobj = json.loads(response)
541+
542+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
543+
if jobj != None:
544+
return (False, jobj["message"])
545+
else:
546+
return (False, "Could not contact the server.")
547+
548+
return (jobj["key"], jobj["rawResponse"], jobj["message"])
417549

418550
class AI:
419551

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
setup(
33
name = 'licensing', # How you named your package folder (MyLib)
44
packages = ['licensing'], # Chose the same as "name"
5-
version = '0.42', # Start with a small number and increase it with every change you make
5+
version = '0.43', # Start with a small number and increase it with every change you make
66
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
77
description = 'Client library for Cryptolens licensing Web API.', # Give a short description about your library
88
author = 'Cryptolens AB', # Type in your name

0 commit comments

Comments
 (0)