From bd19546188047a6da91fed36672be52bff68ffb9 Mon Sep 17 00:00:00 2001 From: Artem Los Date: Wed, 24 Apr 2024 09:05:33 +0200 Subject: [PATCH] Add Get Customer Licenses (#70) * Update methods.py * Update setup.py * Update methods.py --- licensing/methods.py | 67 ++++++++++++++++++++++++++++++++++++++++++++ setup.py | 4 +-- 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/licensing/methods.py b/licensing/methods.py index f5f35f4..e752948 100644 --- a/licensing/methods.py +++ b/licensing/methods.py @@ -940,6 +940,73 @@ def add_customer(token, name = "", email = "", company_name="",\ return (None, "Could not contact the server.") return (jobj, "") + + @staticmethod + def get_customer_licenses(token, customer_id, detailed=False, metadata=False): + + """ + This method will return a list of license keys that belong to a certain customer. + + More docs: https://app.cryptolens.io/docs/api/v3/GetCustomerLicenses + """ + + try: + response = HelperMethods.send_request("/customer/GetCustomerLicenses/",\ + {"token":token,\ + "customerId" : customer_id,\ + "detailed" : detailed,\ + "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_customer_licenses_by_secret(token, secret, detailed=False, metadata=False): + + """ + This method will return a list of license keys that belong to a certain customer. + + More docs: https://app.cryptolens.io/docs/api/v3/GetCustomerLicenses + """ + + try: + response = HelperMethods.send_request("/customer/GetCustomerLicensesBySecret/",\ + {"token":token,\ + "secret" : secret,\ + "detailed" : detailed,\ + "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, "") + class Data: diff --git a/setup.py b/setup.py index 3f91393..514e1fe 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.44', # Start with a small number and increase it with every change you make + version = '0.45', # 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_44.tar.gz', # I explain this later on + download_url = 'https://github.com/Cryptolens/cryptolens-python/archive/v_45.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