Total Complexity | 8 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 2 |
1 | #!/usr/bin/python |
||
10 | class SearchResponse(AbstractEntity): |
||
11 | """General Search Response from the APIs""" |
||
12 | |||
13 | def __init__(self, success: bool, checked_time: int, items: List[Item] = None): |
||
14 | """Initializing function |
||
15 | |||
16 | :param success: |
||
17 | :param checked_time: |
||
18 | :param items: |
||
19 | """ |
||
20 | self._success = success |
||
21 | self._time = checked_time |
||
22 | |||
23 | if items: |
||
24 | self._items = items |
||
25 | else: |
||
26 | self._items = [] |
||
27 | |||
28 | @property |
||
29 | def value(self): |
||
30 | """Return all important information regarding the search API call like success, time and items |
||
31 | |||
32 | :return: |
||
33 | """ |
||
34 | return { |
||
35 | 'data': { |
||
36 | 'status': self._success, |
||
37 | 'time': self._time, |
||
38 | 'items': self.items |
||
39 | } |
||
40 | } |
||
41 | |||
42 | @property |
||
43 | def items(self): |
||
44 | """Property for items which returns __dict__ of the item objects |
||
45 | to allow JSON dump the search response without custom JSONEncoder objects |
||
46 | |||
47 | :return: |
||
48 | """ |
||
49 | return [i.__dict__ for i in self._items] |
||
50 | |||
51 | @items.setter |
||
52 | def items(self, items: List[Item]): |
||
53 | """Setter for items |
||
54 | |||
55 | :param items: |
||
56 | :return: |
||
57 | """ |
||
58 | self._items = items |
||
59 | |||
60 | def add_item(self, item: Item): |
||
61 | """Adder for items |
||
62 | |||
63 | :param item: |
||
64 | :return: |
||
65 | """ |
||
66 | if item not in self._items: |
||
67 | self._items.append(item) |
||
68 |