Skip to content

Commit 37f3351

Browse files
committed
Add GetProducts, closes #29
1 parent 559288f commit 37f3351

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

licensing/methods.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,39 @@ def get_messages(token, channel="", time=0):
250250
return (None, "Could not contact the server.")
251251

252252
return (jobj["messages"], "")
253+
254+
255+
class Product:
256+
257+
@staticmethod
258+
def get_products(token):
259+
260+
"""
261+
This method will return the list of products. Each product contains fields such as
262+
the name and description, as well feature definitions and data objects. All the fields
263+
of a product are available here: https://app.cryptolens.io/docs/api/v3/model/Product
264+
265+
More docs: https://app.cryptolens.io/docs/api/v3/GetProducts
266+
"""
267+
268+
try:
269+
response = HelperMethods.send_request("/product/getproducts/", {"token":token})
270+
except HTTPError as e:
271+
response = e.read()
272+
except URLError as e:
273+
return (None, "Could not contact the server. Error message: " + str(e))
274+
except Exception:
275+
return (None, "Could not contact the server.")
276+
277+
jobj = json.loads(response)
278+
279+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
280+
if jobj != None:
281+
return (None, jobj["message"])
282+
else:
283+
return (None, "Could not contact the server.")
284+
285+
return (jobj["products"], "")
253286

254287
class Helpers:
255288

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
9+
from licensing.methods import Key, Helpers, Message, Product
1010

1111
import socket
1212

0 commit comments

Comments
 (0)