wallaroo.notify

 1class Notification:
 2    def to_json(self):
 3        raise NotImplemented()
 4
 5
 6class Email(Notification):
 7    def __init__(self, to):
 8        self.args = {"to": to}
 9
10    def to_json(self):
11        return self.args
12
13    @classmethod
14    def from_json(cls, json):
15        return Email(json["to"])
16
17
18def to_json(notifications):
19    emails = [n for n in notifications if isinstance(n, Email)]
20    return {"email": [n.to_json() for n in emails]}
21
22
23def from_json(json):
24    return [Email.from_json(e) for e in json["email"]]
25
26
27class AlertConfiguration:
28    def __init__(self, name, expression, notifications):
29        self.name = name
30        self.expression = expression
31        self.notifications = notifications
32
33    @classmethod
34    def from_json(Cls, json):
35        return Cls(
36            json["name"],
37            json["expression"],
38            from_json(json["notifications"]),
39        )
40
41    def to_json(self):
42        return {
43            "name": self.name,
44            "expression": self.expression,
45            "notifications": to_json(self.notifications),
46        }
class Notification:
2class Notification:
3    def to_json(self):
4        raise NotImplemented()
Notification()
def to_json(self):
3    def to_json(self):
4        raise NotImplemented()
class Email(Notification):
 7class Email(Notification):
 8    def __init__(self, to):
 9        self.args = {"to": to}
10
11    def to_json(self):
12        return self.args
13
14    @classmethod
15    def from_json(cls, json):
16        return Email(json["to"])
Email(to)
8    def __init__(self, to):
9        self.args = {"to": to}
def to_json(self):
11    def to_json(self):
12        return self.args
@classmethod
def from_json(cls, json):
14    @classmethod
15    def from_json(cls, json):
16        return Email(json["to"])
def to_json(notifications):
19def to_json(notifications):
20    emails = [n for n in notifications if isinstance(n, Email)]
21    return {"email": [n.to_json() for n in emails]}
def from_json(json):
24def from_json(json):
25    return [Email.from_json(e) for e in json["email"]]
class AlertConfiguration:
28class AlertConfiguration:
29    def __init__(self, name, expression, notifications):
30        self.name = name
31        self.expression = expression
32        self.notifications = notifications
33
34    @classmethod
35    def from_json(Cls, json):
36        return Cls(
37            json["name"],
38            json["expression"],
39            from_json(json["notifications"]),
40        )
41
42    def to_json(self):
43        return {
44            "name": self.name,
45            "expression": self.expression,
46            "notifications": to_json(self.notifications),
47        }
AlertConfiguration(name, expression, notifications)
29    def __init__(self, name, expression, notifications):
30        self.name = name
31        self.expression = expression
32        self.notifications = notifications
@classmethod
def from_json(Cls, json):
34    @classmethod
35    def from_json(Cls, json):
36        return Cls(
37            json["name"],
38            json["expression"],
39            from_json(json["notifications"]),
40        )
def to_json(self):
42    def to_json(self):
43        return {
44            "name": self.name,
45            "expression": self.expression,
46            "notifications": to_json(self.notifications),
47        }