|
3 | 3 | #
|
4 | 4 | # License: http://jkeyes.mit-license.org/
|
5 | 5 | #
|
| 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 | +""" |
6 | 14 |
|
7 | 15 | from . import Intercom
|
8 | 16 | from .user import UserId
|
9 | 17 |
|
10 | 18 | class Impression(UserId):
|
| 19 | + """ An Impression represents an interaction between a User and your |
| 20 | + application. """ |
11 | 21 |
|
12 | 22 | @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 | + """ |
14 | 34 | 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) |
16 | 36 | return cls(resp)
|
17 | 37 |
|
18 | 38 | 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 | + """ |
19 | 51 | resp = Intercom.create_impression(**self)
|
20 | 52 | self.update(resp)
|
21 | 53 |
|
22 | 54 | @property
|
23 | 55 | def user_ip(self):
|
| 56 | + """ The IP address where this Impression originated. """ |
24 | 57 | return dict.get(self, 'user_ip', None)
|
25 | 58 |
|
26 | 59 | @user_ip.setter
|
27 | 60 | def user_ip(self, user_ip):
|
| 61 | + """ Set the user IP address. """ |
28 | 62 | self['user_ip'] = user_ip
|
29 | 63 |
|
30 | 64 | @property
|
31 | 65 | def location(self):
|
| 66 | + """ The location where this Impression originated e.g. |
| 67 | + /pricing/upgrade or 'DesktopApp: Pricing' or 'iOS'. """ |
32 | 68 | return dict.get(self, 'location', None)
|
33 | 69 |
|
34 | 70 | @location.setter
|
35 | 71 | def location(self, location):
|
| 72 | + """ Set the location. """ |
36 | 73 | self['location'] = location
|
37 | 74 |
|
38 | 75 | @property
|
39 | 76 | 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. """ |
40 | 79 | return dict.get(self, 'user_agent', None)
|
41 | 80 |
|
42 | 81 | @user_agent.setter
|
43 | 82 | def user_agent(self, user_agent):
|
| 83 | + """ Set the User Agent. """ |
44 | 84 | self['user_agent'] = user_agent
|
45 | 85 |
|
46 | 86 | @property
|
47 | 87 | def unread_messages(self):
|
| 88 | + """ The number of unread messages for the User who made the |
| 89 | + Impression for the current location. """ |
48 | 90 | return dict.get(self, 'unread_messages', None)
|
0 commit comments