Skip to content

Commit e1374fa

Browse files
committed
Adding waiting_since as a timestamp field.
Also returning False for update_last_request_at field as it is a boolean.
1 parent 164fd6c commit e1374fa

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

intercom/traits/api_resource.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ def type_field(attribute):
1414

1515

1616
def timestamp_field(attribute):
17-
return attribute.endswith('_at')
17+
# update_last_request_at is a boolean field, we must ignore that
18+
if attribute == 'update_last_request_at':
19+
return False
20+
return attribute.endswith('_at') or attribute == 'waiting_since'
1821

1922

2023
def custom_attribute_field(attribute):
@@ -97,10 +100,16 @@ def submittable_attribute(self, name, value):
97100

98101
def __getattribute__(self, attribute):
99102
value = super(Resource, self).__getattribute__(attribute)
103+
# ignore attributes we know about
104+
if '_' == attribute[0] or attribute in self.__class__.__dict__:
105+
return value
106+
107+
# check for timestamp fields
100108
if timestamp_field(attribute):
101109
return to_datetime_value(value)
102-
else:
103-
return value
110+
111+
# just return the value
112+
return value
104113

105114
def __setattr__(self, attribute, value):
106115
if typed_value(value) and not custom_attribute_field(attribute):

tests/unit/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ def page_of_companies(include_next_link=False):
348348
"id": "123456789",
349349
"created_at": "1410335293",
350350
"updated_at": "1410335293",
351+
"waiting_since": "1512020127",
351352
"user": {
352353
"type": "user",
353354
"id": "540f1de7112d3d1d51001637",

tests/unit/test_notification.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ def it_returns_inner_conversation_parts_for_conversation(self):
6666
eq_(1, len(conversation_parts))
6767
eq_('conversation_part', conversation_parts[0].resource_type)
6868

69+
@istest
70+
def it_returns_datetimes_for_conversations(self):
71+
payload = Notification(**test_conversation_notification)
72+
eq_(2014, payload.data.item.created_at.year)
73+
eq_(2017, payload.data.item.waiting_since.year)
74+
6975
@istest
7076
def it_returns_inner_user_object_with_nil_tags(self):
7177
user_notification = {

0 commit comments

Comments
 (0)