Skip to content

Commit bd19546

Browse files
authored
Add Get Customer Licenses (#70)
* Update methods.py * Update setup.py * Update methods.py
1 parent 0595156 commit bd19546

File tree

2 files changed

+69
-2
lines changed

2 files changed

+69
-2
lines changed

licensing/methods.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,73 @@ def add_customer(token, name = "", email = "", company_name="",\
940940
return (None, "Could not contact the server.")
941941

942942
return (jobj, "")
943+
944+
@staticmethod
945+
def get_customer_licenses(token, customer_id, detailed=False, metadata=False):
946+
947+
"""
948+
This method will return a list of license keys that belong to a certain customer.
949+
950+
More docs: https://app.cryptolens.io/docs/api/v3/GetCustomerLicenses
951+
"""
952+
953+
try:
954+
response = HelperMethods.send_request("/customer/GetCustomerLicenses/",\
955+
{"token":token,\
956+
"customerId" : customer_id,\
957+
"detailed" : detailed,\
958+
"metadata" : metadata
959+
})
960+
except HTTPError as e:
961+
response = e.read()
962+
except URLError as e:
963+
return (None, "Could not contact the server. Error message: " + str(e))
964+
except Exception:
965+
return (None, "Could not contact the server.")
966+
967+
jobj = json.loads(response)
968+
969+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
970+
if jobj != None:
971+
return (None, jobj["message"])
972+
else:
973+
return (None, "Could not contact the server.")
974+
975+
return (jobj, "")
976+
977+
@staticmethod
978+
def get_customer_licenses_by_secret(token, secret, detailed=False, metadata=False):
979+
980+
"""
981+
This method will return a list of license keys that belong to a certain customer.
982+
983+
More docs: https://app.cryptolens.io/docs/api/v3/GetCustomerLicenses
984+
"""
985+
986+
try:
987+
response = HelperMethods.send_request("/customer/GetCustomerLicensesBySecret/",\
988+
{"token":token,\
989+
"secret" : secret,\
990+
"detailed" : detailed,\
991+
"metadata" : metadata
992+
})
993+
except HTTPError as e:
994+
response = e.read()
995+
except URLError as e:
996+
return (None, "Could not contact the server. Error message: " + str(e))
997+
except Exception:
998+
return (None, "Could not contact the server.")
999+
1000+
jobj = json.loads(response)
1001+
1002+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
1003+
if jobj != None:
1004+
return (None, jobj["message"])
1005+
else:
1006+
return (None, "Could not contact the server.")
1007+
1008+
return (jobj, "")
1009+
9431010

9441011
class Data:
9451012

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
setup(
33
name = 'licensing', # How you named your package folder (MyLib)
44
packages = ['licensing'], # Chose the same as "name"
5-
version = '0.44', # Start with a small number and increase it with every change you make
5+
version = '0.45', # 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
99
author_email = 'support@cryptolens.io', # Type in your E-Mail
1010
url = 'https://cryptolens.io', # Provide either the link to your github or to your website
11-
download_url = 'https://github.com/Cryptolens/cryptolens-python/archive/v_44.tar.gz', # I explain this later on
11+
download_url = 'https://github.com/Cryptolens/cryptolens-python/archive/v_45.tar.gz', # I explain this later on
1212
keywords = ['software licensing', 'licensing library', 'cryptolens'], # Keywords that define your package best
1313
classifiers=[
1414
#'Development Status :: 5 - Stable', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package

0 commit comments

Comments
 (0)