1919import functools
2020import json
2121import requests
22+ import time
2223
2324DEFAULT_TIMEOUT = 10 # seconds
2425
@@ -63,6 +64,8 @@ def wrapper(*args, **kwargs):
6364 """ Decorator closure. """
6465 response = func_to_decorate (* args , ** kwargs )
6566 raise_errors_on_failure (response )
67+ if not response .content .strip ():
68+ return ''
6669 result = json .loads (response .content )
6770 return result
6871 return wrapper
@@ -121,19 +124,24 @@ def _create_or_update_user(cls, method, **kwargs):
121124
122125 @classmethod
123126 def get_users (cls , ** kwargs ):
124- """ Returns a paginated list of all users in your application on Intercom.
127+ """ Returns a paginated list of all users in your application on
128+ Intercom.
125129
126130 **Arguments**
127131
128132 * ``page``: optional (defaults to 1)
129133 * ``per_page``: optional (defaults to 500, max value of 500)
130- * ``tag_id``: optional — query for users that are tagged with a specific tag.
131- * ``tag_name``: optional — query for users that are tagged with a specific tag.
134+ * ``tag_id``: optional — query for users that are tagged with a
135+ specific tag.
136+ * ``tag_name``: optional — query for users that are tagged with a
137+ specific tag.
132138
133139 **Response**
134140
135- * ``users``: an array of User objects (same as returned by getting a single User)
136- * ``total_count``: the total number of Users tracked in your Intercom application
141+ * ``users``: an array of User objects (same as returned by getting a
142+ single User)
143+ * ``total_count``: the total number of Users tracked in your Intercom
144+ application
137145 * ``page``: the current requested page
138146 * ``next_page``: the next page number, if any
139147 * ``previous_page``: the previous page number, if any
@@ -146,7 +154,8 @@ def get_users(cls, **kwargs):
146154 3
147155
148156 """
149- return Intercom ._call ('GET' , Intercom .api_endpoint + 'users' , params = kwargs )
157+ return Intercom ._call (
158+ 'GET' , Intercom .api_endpoint + 'users' , params = kwargs )
150159
151160 @classmethod
152161 def get_user (cls , email = None , user_id = None ):
@@ -194,7 +203,8 @@ def create_user(cls, **kwargs):
194203 unsubscribed status.
195204
196205
197- >>> user = Intercom.create_user(user_id='7902', email='ben@intercom.io',
206+ >>> user = Intercom.create_user(user_id='7902',
207+ ... email='ben@intercom.io',
198208 ... name='Somebody', created_at=1270000000, last_seen_ip='1.2.3.4',
199209 ... custom_data={ 'app_name': 'Genesis'}, last_request_at=1300000000)
200210 >>> user['name']
@@ -433,3 +443,22 @@ def get_tag(cls, name=None):
433443 tag_dict = Intercom ._call (
434444 'GET' , Intercom .api_endpoint + 'tags' , params = params )
435445 return tag_dict
446+
447+ @classmethod
448+ def create_event (cls , event_name = None , user_id = None , email = None , metadata = None ):
449+ """
450+ Create an event
451+ """
452+ params = {
453+ 'event_name' : event_name ,
454+ 'user_id' : user_id ,
455+ 'email' : email ,
456+ 'created' : int (time .time ())
457+ }
458+
459+ if isinstance (metadata , dict ):
460+ params ['metadata' ] = metadata
461+
462+ call = Intercom ._call (
463+ 'POST' , Intercom .api_endpoint + 'events' , params = params )
464+ return call
0 commit comments