diff --git a/licensing/methods.py b/licensing/methods.py index 6844577..f5f35f4 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -546,6 +546,74 @@ def create_key_from_template(token, license_template_id): return (False, "Could not contact the server.") return (jobj["key"], jobj["rawResponse"], jobj["message"]) + + def add_feature(token, product_id, key, feature): + """ + This method will set a certain feature (F1..F8) to true. + If the key algorithm in the product is SKGL, the key string will be + changed if necessary. Otherwise, if SKM15 is used, the key will stay + the same. To do the reverse, please see RemoveFeature. + + More docs: https://app.cryptolens.io/docs/api/v3/AddFeature + """ + + response = "" + + try: + response = HelperMethods.send_request("/key/AddFeature", {"token":token,\ + "ProductId":product_id,\ + "Key" : key,\ + "Feature" : feature}) + 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 (False, jobj["message"]) + else: + return (False, "Could not contact the server.") + + return (True, jobj["message"]) + + def remove_feature(token, product_id, key, feature): + """ + This method will set a certain feature (F1..F8) to false. If the key + algorithm in the product is SKGL, the key string will be changed if + necessary. Otherwise, if SKM15 is used, the key will stay the same. + To do the reverse, please see AddFeature. + + More docs: https://app.cryptolens.io/docs/api/v3/RemoveFeature + """ + + response = "" + + try: + response = HelperMethods.send_request("/key/RemoveFeature", {"token":token,\ + "ProductId":product_id,\ + "Key" : key,\ + "Feature" : feature}) + 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 (False, jobj["message"]) + else: + return (False, "Could not contact the server.") + + return (True, jobj["message"]) class AI: diff --git a/setup.py b/setup.py index c314fc7..3f91393 100644 --- a/setup.py +++ b/setup.py @@ -2,13 +2,13 @@ setup( name = 'licensing', # How you named your package folder (MyLib) packages = ['licensing'], # Chose the same as "name" - version = '0.43', # Start with a small number and increase it with every change you make + version = '0.44', # Start with a small number and increase it with every change you make license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository description = 'Client library for Cryptolens licensing Web API.', # Give a short description about your library author = 'Cryptolens AB', # Type in your name author_email = 'support@cryptolens.io', # Type in your E-Mail url = 'https://cryptolens.io', # Provide either the link to your github or to your website - download_url = 'https://github.com/Cryptolens/cryptolens-python/archive/v_42.tar.gz', # I explain this later on + download_url = 'https://github.com/Cryptolens/cryptolens-python/archive/v_44.tar.gz', # I explain this later on keywords = ['software licensing', 'licensing library', 'cryptolens'], # Keywords that define your package best classifiers=[ #'Development Status :: 5 - Stable', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package