diff options
| author | jantuomi <jans.tuomi@gmail.com> | 2016-07-19 14:50:22 +0300 |
|---|---|---|
| committer | jantuomi <jans.tuomi@gmail.com> | 2016-07-19 14:50:22 +0300 |
| commit | 9d94a01b631676b54f680c2571ae4dbba9ccd037 (patch) | |
| tree | 2cac58eba2cd5d29ae0c2192efc5ca365dde7f74 /project/jsonfactory.py | |
| parent | 080cfd6cfe946e243239af201dea8466abaee020 (diff) | |
Restructure project
Diffstat (limited to 'project/jsonfactory.py')
| -rw-r--r-- | project/jsonfactory.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/project/jsonfactory.py b/project/jsonfactory.py new file mode 100644 index 0000000..c57b430 --- /dev/null +++ b/project/jsonfactory.py @@ -0,0 +1,27 @@ +import json + + +class JSONFactory(object): + """Factory class to create JSON messages to be sent to the shoutbox API""" + running_id = 1 + + @staticmethod + def make_object(text, user, timestamp, ip): + """ + Create a JSON object from the passed parameters and + add a running id + """ + message = json.dumps({ + "id": JSONFactory.running_id, + "text": text, + "user": user, + "timestamp": timestamp, + "ip": ip + }) + JSONFactory.running_id += 1 + return message + + @staticmethod + def make_array(object_list): + """Create a JSON array from a list of JSON objects""" + return "[\n" + ",\n".join(object_list) + "\n]" |
