Skip to content

Commit 1854c83

Browse files
committed
Don't treat event types as an instance of the model that was changed in the event in deserializer - add data attribute to event model so that event data is properly returned along with metadata
1 parent e45e07a commit 1854c83

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

clever/api_client.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,6 @@ def __deserialize(self, data, klass):
258258
return {k: self.__deserialize(v, sub_kls)
259259
for k, v in iteritems(data)}
260260

261-
if klass == 'Event':
262-
klass = eval('models.'+''.join(data['type'].title().split('.')))
263-
return self.__deserialize(data,klass)
264-
265261
# convert str to class
266262
if klass in self.NATIVE_TYPES_MAPPING:
267263
klass = self.NATIVE_TYPES_MAPPING[klass]

clever/models/event.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,28 +33,33 @@ class Event(object):
3333
swagger_types = {
3434
'created': 'str',
3535
'id': 'str',
36-
'type': 'str'
36+
'type': 'str',
37+
'data': 'object'
3738
}
3839

3940
attribute_map = {
4041
'created': 'created',
4142
'id': 'id',
42-
'type': 'type'
43+
'type': 'type',
44+
'data': 'data'
4345
}
4446

45-
def __init__(self, created=None, id=None, type=None):
47+
def __init__(self, created=None, id=None, type=None, data=None):
4648
"""
4749
Event - a model defined in Swagger
4850
"""
4951

5052
self._created = None
5153
self._id = None
5254
self._type = None
55+
self._data = None
5356

5457
if created is not None:
5558
self.created = created
5659
if id is not None:
5760
self.id = id
61+
if data is not None:
62+
self.data = data
5863
self.type = type
5964

6065
@property
@@ -122,6 +127,29 @@ def type(self, type):
122127

123128
self._type = type
124129

130+
@property
131+
def data(self):
132+
"""
133+
Gets the data comprising of this Event.
134+
135+
:return: The data of this Event.
136+
:rtype: object
137+
"""
138+
return self._data
139+
140+
@data.setter
141+
def data(self, data):
142+
"""
143+
Sets the data of this Event.
144+
145+
:param data: The data of this Event.
146+
:type: object
147+
"""
148+
if data is None:
149+
raise ValueError("Invalid value for `type`, must not be `None`")
150+
151+
self._data = data
152+
125153
def to_dict(self):
126154
"""
127155
Returns the model properties as a dict

0 commit comments

Comments
 (0)