Skip to content

Commit 15a05ba

Browse files
authored
Add GetMessages (#26)
* Add Martin's code * Minor updates * Minor fixes
1 parent f77cad0 commit 15a05ba

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

licensing/methods.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,12 +214,42 @@ def get_web_api_log(token, product_id = 0, key = "", machine_code="", friendly_n
214214

215215
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
216216
if jobj != None:
217-
return (False, jobj["message"])
217+
return (None, jobj["message"])
218218
else:
219-
return (False, "Could not contact the server.")
219+
return (None, "Could not contact the server.")
220220

221221
return (jobj["logs"], "")
222222

223+
class Message:
224+
225+
@staticmethod
226+
def get_messages(token, channel="", time=0):
227+
228+
"""
229+
This method will return a list of messages that were broadcasted.
230+
You can create new messages here. Messages can be filtered based on the time and the channel.
231+
232+
More docs: https://app.cryptolens.io/docs/api/v3/GetMessages
233+
"""
234+
235+
try:
236+
response = HelperMethods.send_request("/message/getmessages/", {"token":token, "Channel": channel, "Time": time})
237+
except HTTPError as e:
238+
response = e.read()
239+
except URLError as e:
240+
return (None, "Could not contact the server. Error message: " + str(e))
241+
except Exception:
242+
return (None, "Could not contact the server.")
243+
244+
jobj = json.loads(response)
245+
246+
if jobj == None or not("result" in jobj) or jobj["result"] == 1:
247+
if jobj != None:
248+
return (None, jobj["message"])
249+
else:
250+
return (None, "Could not contact the server.")
251+
252+
return (jobj["messages"], "")
223253

224254
class Helpers:
225255

@@ -264,5 +294,4 @@ def IsOnRightMachine(license_key, is_floating_license = False, allow_overdraft=F
264294
if current_mid == act_machine.Mid:
265295
return True
266296

267-
return False
268-
297+
return False

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.21', # Start with a small number and increase it with every change you make
5+
version = '0.22', # 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_21.tar.gz', # I explain this later on
11+
download_url = 'https://github.com/Cryptolens/cryptolens-python/archive/v_22.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

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

1111
import socket
1212

0 commit comments

Comments
 (0)