Skip to content

Commit 2db884d

Browse files
committed
Add "AddCustomer" method, closes #28
1 parent 37f3351 commit 2db884d

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

licensing/methods.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,46 @@ def get_products(token):
283283
return (None, "Could not contact the server.")
284284

285285
return (jobj["products"], "")
286+
287+
288+
class Customer:
289+
290+
@staticmethod
291+
def add_customer(token, name = "", email = "", company_name="",\
292+
enable_customer_association = False,\
293+
allow_activation_management = False ):
294+
295+
"""
296+
This method will add new customer.
297+
298+
More docs: https://app.cryptolens.io/docs/api/v3/AddCustomer
299+
"""
300+
301+
try:
302+
response = HelperMethods.send_request("/customer/addcustomer/",\
303+
{"token":token,\
304+
"Name": name,\
305+
"Email": email,\
306+
"CompanyName": company_name,\
307+
"EnableCustomerAssociation": enable_customer_association,\
308+
"AllowActivationManagement": allow_activation_management
309+
})
310+
except HTTPError as e:
311+
response = e.read()
312+
except URLError as e:
313+
return (None, "Could not contact the server. Error message: " + str(e))
314+
except Exception:
315+
return (None, "Could not contact the server.")
316+
317+
jobj = json.loads(response)
318+
319+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
320+
if jobj != None:
321+
return (None, jobj["message"])
322+
else:
323+
return (None, "Could not contact the server.")
324+
325+
return (jobj, "")
286326

287327
class Helpers:
288328

test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"""
77

88
from licensing.models import *
9-
from licensing.methods import Key, Helpers, Message, Product
9+
from licensing.methods import Key, Helpers, Message, Product, Customer
1010

1111
import socket
1212

0 commit comments

Comments
 (0)