|
1 | 1 | import json
|
2 | 2 |
|
3 | 3 |
|
4 |
| -class EntryCreatedRS(object): |
5 |
| - def __init__(self, id=None, raw=None): |
6 |
| - super(EntryCreatedRS, self).__init__() |
7 |
| - self.id = id |
| 4 | +class RS(object): |
| 5 | + def __init__(self, raw): |
| 6 | + super(RS, self).__init__() |
8 | 7 | self.raw = raw
|
9 |
| - if raw is not None: |
10 |
| - self.id = json.loads(raw)["id"] |
| 8 | + |
| 9 | + |
| 10 | +class EntryCreatedRS(RS): |
| 11 | + def __init__(self, raw): |
| 12 | + super(EntryCreatedRS, self).__init__(raw) |
| 13 | + |
| 14 | + @property |
| 15 | + def id(self): |
| 16 | + try: |
| 17 | + return json.loads(self.raw)["id"] |
| 18 | + except KeyError: |
| 19 | + print("{0} object has no attribute 'id'".format(self.raw)) |
| 20 | + return None |
11 | 21 |
|
12 | 22 | def as_dict(self):
|
13 |
| - return {"id": self.id} |
| 23 | + try: |
| 24 | + return {"id": self.id} |
| 25 | + except KeyError: |
| 26 | + return json.loads(self.raw) |
| 27 | + |
14 | 28 |
|
| 29 | +class OperationCompletionRS(RS): |
| 30 | + def __init__(self, raw): |
| 31 | + super(OperationCompletionRS, self).__init__(raw) |
15 | 32 |
|
16 |
| -class OperationCompletionRS(object): |
17 |
| - def __init__(self, msg=None, raw=None): |
18 |
| - super(OperationCompletionRS, self).__init__() |
19 |
| - self.msg = msg |
20 |
| - if raw is not None: |
21 |
| - self.msg = json.loads(raw)["msg"] |
| 33 | + @property |
| 34 | + def msg(self): |
| 35 | + try: |
| 36 | + return json.loads(self.raw)["msg"] |
| 37 | + except KeyError: |
| 38 | + print("{0} object has no attribute 'msg'".format(self.raw)) |
| 39 | + return None |
22 | 40 |
|
23 | 41 | def as_dict(self):
|
24 |
| - return {"msg": self.msg} |
| 42 | + try: |
| 43 | + return {"msg": json.loads(self.raw)["msg"]} |
| 44 | + except KeyError: |
| 45 | + return json.loads(self.raw) |
0 commit comments