Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding waiting_since as a timestamp field. #174

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions intercom/traits/api_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def type_field(attribute):


def timestamp_field(attribute):
return attribute.endswith('_at')
# update_last_request_at is a boolean field, we must ignore that
if attribute == 'update_last_request_at':
return False
return attribute.endswith('_at') or attribute == 'waiting_since'


def custom_attribute_field(attribute):
Expand Down Expand Up @@ -97,10 +100,16 @@ def submittable_attribute(self, name, value):

def __getattribute__(self, attribute):
value = super(Resource, self).__getattribute__(attribute)
# ignore attributes we know about
if '_' == attribute[0] or attribute in self.__class__.__dict__:
return value

# check for timestamp fields
if timestamp_field(attribute):
return to_datetime_value(value)
else:
return value

# just return the value
return value

def __setattr__(self, attribute, value):
if typed_value(value) and not custom_attribute_field(attribute):
Expand Down
1 change: 1 addition & 0 deletions tests/unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ def page_of_companies(include_next_link=False):
"id": "123456789",
"created_at": "1410335293",
"updated_at": "1410335293",
"waiting_since": "1512020127",
"user": {
"type": "user",
"id": "540f1de7112d3d1d51001637",
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_notification.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def it_returns_inner_conversation_parts_for_conversation(self):
eq_(1, len(conversation_parts))
eq_('conversation_part', conversation_parts[0].resource_type)

@istest
def it_returns_datetimes_for_conversations(self):
payload = Notification(**test_conversation_notification)
eq_(2014, payload.data.item.created_at.year)
eq_(2017, payload.data.item.waiting_since.year)

@istest
def it_returns_inner_user_object_with_nil_tags(self):
user_notification = {
Expand Down