Skip to content

Commit

Permalink
intercom: add support for Events endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
javimb committed Jan 9, 2015
1 parent b2510c7 commit a9ffe1a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
46 changes: 46 additions & 0 deletions libsaas/services/intercom/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,49 @@ def update(self, *args, **kwargs):

def delete(self, *args, **kwargs):
raise base.MethodNotSupported()


class Events(IntercomResource):

path = 'events'

@base.apimethod
def create(self, event_name, created_at, user_id=None, email=None,
metadata=None):
"""
Create a new Event object.
:var event_name: The name of the event that occurred.
:vartype event_name: str
:var created_at: The time the event occurred as a UTC Unix timestamp.
:vartype created_at: int
:var user_id: The user_id of the user which messages should be
returned. Required if no email.
:vartype user_id: int
:var email: The email of the user which messages that should be
returned. Required if no user_id.
:vartype email: str
:var metadata: Optional metadata about the event.
:vartype metadata: dict
"""
if not user_id and not email:
raise TypeError(
'create() must be passed at least one of user_id, email')

params = base.get_params(None, locals())
request = http.Request('POST', self.get_url(), params)

return request, parsers.parse_json

def get(self, *args, **kwargs):
raise base.MethodNotSupported()

def update(self, *args, **kwargs):
raise base.MethodNotSupported()

def delete(self, *args, **kwargs):
raise base.MethodNotSupported()
7 changes: 7 additions & 0 deletions libsaas/services/intercom/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,10 @@ def counts(self):
Return the resource corresponding to all counts.
"""
return resource.Counts(self)

@base.resource(resource.Events)
def events(self):
"""
Return the resource corresponding to all events.
"""
return resource.Events(self)
19 changes: 19 additions & 0 deletions test/test_intercom.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,22 @@ def test_counts(self):
self.service.counts().get(type='company', count='user')
self.expect('GET', '/counts', {'type': 'company', 'count': 'user'})
self.service.counts().get()

def test_events(self):
with port.assertRaises(MethodNotSupported):
self.service.counts().get()
self.service.counts().update()
self.service.counts().delete()

kwargs = {
'event_name': 'test',
'created_at': 9999999999,
'email': 'name@domain.com',
'metadata': {
'service_kind': 'custom',
'data_source_kind': 'custom_float'
}
}

self.service.events().create(**kwargs)
self.expect('POST', '/events', json.dumps(kwargs))

0 comments on commit a9ffe1a

Please sign in to comment.