aboutsummaryrefslogtreecommitdiffstats
path: root/jsonfactory.py
blob: 6703ef27240327dbf3da0f298ae4f6213644e456 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import json


class JSONFactory(object):
    running_id = 1

    @staticmethod
    def make_object(text, user, timestamp, ip):
        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):
        return "[\n" + ",\n".join(object_list) + "\n]"