Skip to content

Commit 58cc26d

Browse files
committed
Added Impression Location support
Added Location support to the Impression create methods. Also added docstrings and doctests for the Impression module.
1 parent 19afd14 commit 58cc26d

File tree

3 files changed

+52
-5
lines changed

3 files changed

+52
-5
lines changed

intercom/impression.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,88 @@
33
#
44
# License: http://jkeyes.mit-license.org/
55
#
6+
""" Impression module.
7+
8+
>>> from intercom import Intercom
9+
>>> Intercom.app_id = 'dummy-app-id'
10+
>>> Intercom.api_key = 'dummy-api-key'
11+
>>> from intercom import Impression
12+
13+
"""
614

715
from . import Intercom
816
from .user import UserId
917

1018
class Impression(UserId):
19+
""" An Impression represents an interaction between a User and your
20+
application. """
1121

1222
@classmethod
13-
def create(cls, user_id=None, email=None, user_ip=None, user_agent=None):
23+
def create(cls, user_id=None, email=None, user_ip=None, user_agent=None,
24+
location=None):
25+
""" Create an Impression.
26+
27+
>>> Impression.create(email="somebody@example.com",
28+
... location="/pricing/upgrade",
29+
... user_ip="1.2.3.4",
30+
... user_agent="my-service-iphone-app-1.2")
31+
{u'unread_messages': 1}
32+
33+
"""
1434
resp = Intercom.create_impression(user_id=user_id, email=email,
15-
user_ip=user_ip, user_agent=user_agent)
35+
user_ip=user_ip, user_agent=user_agent, location=location)
1636
return cls(resp)
1737

1838
def save(self):
39+
""" Create an Impression from this objects properties:
40+
41+
>>> impression = Impression()
42+
>>> impression.email = "somebody@example.com"
43+
>>> impression.location = "/pricing/upgrade"
44+
>>> impression.user_ip = "1.2.3.4"
45+
>>> impression.user_agent = "my-service-iphone-app-1.2"
46+
>>> impression.save()
47+
>>> impression.unread_messages
48+
1
49+
50+
"""
1951
resp = Intercom.create_impression(**self)
2052
self.update(resp)
2153

2254
@property
2355
def user_ip(self):
56+
""" The IP address where this Impression originated. """
2457
return dict.get(self, 'user_ip', None)
2558

2659
@user_ip.setter
2760
def user_ip(self, user_ip):
61+
""" Set the user IP address. """
2862
self['user_ip'] = user_ip
2963

3064
@property
3165
def location(self):
66+
""" The location where this Impression originated e.g.
67+
/pricing/upgrade or 'DesktopApp: Pricing' or 'iOS'. """
3268
return dict.get(self, 'location', None)
3369

3470
@location.setter
3571
def location(self, location):
72+
""" Set the location. """
3673
self['location'] = location
3774

3875
@property
3976
def user_agent(self):
77+
""" The User Agent that created this Impression e.g. the browser
78+
User Agent, or the name and version of an application. """
4079
return dict.get(self, 'user_agent', None)
4180

4281
@user_agent.setter
4382
def user_agent(self, user_agent):
83+
""" Set the User Agent. """
4484
self['user_agent'] = user_agent
4585

4686
@property
4787
def unread_messages(self):
88+
""" The number of unread messages for the User who made the
89+
Impression for the current location. """
4890
return dict.get(self, 'unread_messages', None)

intercom/intercom.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ def update_user(cls, user_id=None, email=None, name=None, created_at=None,
112112

113113
@classmethod
114114
def create_impression(cls, user_id=None, email=None, user_ip=None,
115-
user_agent=None):
115+
user_agent=None, location=None):
116116
""" Create an impression. """
117117
params = { 'email': email, 'user_id': user_id, 'user_ip': user_ip,
118-
'user_agent': user_agent }
118+
'user_agent': user_agent, 'location': location }
119119
user_dict = Intercom._call('POST', Intercom.api_endpoint + 'users/impressions',
120-
params=params)
120+
params=params)
121121
return user_dict
122122

123123
@classmethod

tests/unit/test_impression.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ def test_create_impression_valid(self):
2929
impression = Impression.create(email='xxx@example.com')
3030
self.assertEqual(0, impression.unread_messages)
3131

32+
# check params
33+
impression = Impression.create(email='xxx@example.com', location="home",
34+
user_ip='1.2.3.4', user_agent='Mozilla/5.0')
35+
self.assertEqual(0, impression.unread_messages)
36+
3237
def test_properties(self):
3338
impression = Impression()
3439
impression.user_ip = '192.168.1.100'

0 commit comments

Comments
 (0)