Skip to content

Commit f2f8af0

Browse files
committed
PEP8 formatting.
1 parent c28107e commit f2f8af0

File tree

6 files changed

+137
-82
lines changed

6 files changed

+137
-82
lines changed

intercom/__init__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111

1212
from datetime import datetime
1313

14+
1415
def from_timestamp_property(func_to_decorate):
15-
""" A decorator for properties to convert the property value from a
16+
""" A decorator for properties to convert the property value from a
1617
timestamp to a datetime. """
1718
@functools.wraps(func_to_decorate)
1819
def wrapper(instance):
@@ -22,8 +23,9 @@ def wrapper(instance):
2223
return datetime.fromtimestamp(value)
2324
return wrapper
2425

26+
2527
def to_timestamp_property(func_to_decorate):
26-
""" A decorator for properties to convert the property value from a
28+
""" A decorator for properties to convert the property value from a
2729
datetime to a timestamp. """
2830
@functools.wraps(func_to_decorate)
2931
def wrapper(instance, value):
@@ -42,3 +44,8 @@ def wrapper(instance, value):
4244
from .message_thread import MessageThread
4345
from .note import Note
4446
from .user import User
47+
48+
__all__ = (
49+
AuthenticationError, Intercom, ResourceNotFound, ServerError,
50+
Impression, MessageThread, Note, User
51+
)

intercom/impression.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
# License: http://jkeyes.mit-license.org/
66
#
7-
""" Impression module.
7+
""" Impression module.
88
99
>>> from intercom import Intercom
1010
>>> Intercom.app_id = 'dummy-app-id'
@@ -16,24 +16,26 @@
1616
from . import Intercom
1717
from .user import UserId
1818

19+
1920
class Impression(UserId):
20-
""" An Impression represents an interaction between a User and your
21+
""" An Impression represents an interaction between a User and your
2122
application. """
2223

2324
@classmethod
2425
def create(cls, user_id=None, email=None, user_ip=None, user_agent=None,
25-
location=None):
26+
location=None):
2627
""" Create an Impression.
2728
28-
>>> Impression.create(email="somebody@example.com",
29-
... location="/pricing/upgrade",
30-
... user_ip="1.2.3.4",
29+
>>> Impression.create(email="somebody@example.com",
30+
... location="/pricing/upgrade",
31+
... user_ip="1.2.3.4",
3132
... user_agent="my-service-iphone-app-1.2")
3233
{u'unread_messages': 1}
3334
3435
"""
35-
resp = Intercom.create_impression(user_id=user_id, email=email,
36-
user_ip=user_ip, user_agent=user_agent, location=location)
36+
resp = Intercom.create_impression(
37+
user_id=user_id, email=email, user_ip=user_ip,
38+
user_agent=user_agent, location=location)
3739
return cls(resp)
3840

3941
def save(self):
@@ -64,7 +66,7 @@ def user_ip(self, user_ip):
6466

6567
@property
6668
def location(self):
67-
""" The location where this Impression originated e.g.
69+
""" The location where this Impression originated e.g.
6870
/pricing/upgrade or 'DesktopApp: Pricing' or 'iOS'. """
6971
return dict.get(self, 'location', None)
7072

@@ -86,6 +88,6 @@ def user_agent(self, user_agent):
8688

8789
@property
8890
def unread_messages(self):
89-
""" The number of unread messages for the User who made the
91+
""" The number of unread messages for the User who made the
9092
Impression for the current location. """
9193
return dict.get(self, 'unread_messages', None)

intercom/intercom.py

Lines changed: 68 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import pkg_resources
2020
import requests
2121

22-
DEFAULT_TIMEOUT = 10 # seconds
22+
DEFAULT_TIMEOUT = 10 # seconds
2323
VERSION = pkg_resources.require("python-intercom")[0].version
2424

2525

@@ -29,18 +29,22 @@ def __init__(self, message, result=None):
2929
super(IntercomError, self).__init__(message)
3030
self.result = result
3131

32+
3233
class AuthenticationError(IntercomError):
3334
""" Raised when a request cannot be authenticated by the API. """
3435
pass
3536

37+
3638
class ResourceNotFound(IntercomError):
3739
""" Raised when a resource cannot be found e.g. a non-existant User. """
3840
pass
3941

42+
4043
class ServerError(IntercomError):
4144
""" Raised when the API returns an error other than an auth or not found. """
4245
pass
4346

47+
4448
def api_call(func_to_decorate):
4549
""" Decorator for handling AWS credentials. """
4650
@functools.wraps(func_to_decorate)
@@ -64,6 +68,7 @@ def wrapper(*args, **kwargs):
6468
return result
6569
return wrapper
6670

71+
6772
class Intercom(object):
6873
""" Intercom API Wrapper """
6974

@@ -90,16 +95,16 @@ def _call(cls, method, url, params=None):
9095
req_params['params'] = params
9196
req_params['headers'] = headers
9297

93-
resp = requests.request(method, url, timeout=Intercom.timeout, \
94-
auth=(Intercom.app_id, Intercom.api_key),
95-
**req_params)
98+
resp = requests.request(
99+
method, url, timeout=Intercom.timeout,
100+
auth=(Intercom.app_id, Intercom.api_key), **req_params)
96101
return resp
97102

98103
@classmethod
99104
def _create_or_update_user(cls, method, **kwargs):
100105
""" Used by create_user and update_user. """
101-
user_dict = Intercom._call(method, Intercom.api_endpoint + 'users',
102-
params=kwargs)
106+
user_dict = Intercom._call(
107+
method, Intercom.api_endpoint + 'users', params=kwargs)
103108
return user_dict
104109

105110
@classmethod
@@ -126,12 +131,13 @@ def get_user(cls, email=None, user_id=None):
126131
127132
"""
128133

129-
params = { 'email': email, 'user_id': user_id }
134+
params = {'email': email, 'user_id': user_id}
130135
user_dict = Intercom._call('GET', '%susers' % (Intercom.api_endpoint), params=params)
131136
return user_dict
132137

133138
@classmethod
134-
def create_user(cls, user_id=None, email=None, name=None, created_at=None,
139+
def create_user(
140+
cls, user_id=None, email=None, name=None, created_at=None,
135141
custom_data=None, last_seen_ip=None, last_seen_user_agent=None):
136142
""" Create a user from the available parameters.
137143
@@ -147,12 +153,14 @@ def create_user(cls, user_id=None, email=None, name=None, created_at=None,
147153
u'smuggler'
148154
149155
"""
150-
return Intercom._create_or_update_user('POST', user_id=user_id, email=email,
156+
return Intercom._create_or_update_user(
157+
'POST', user_id=user_id, email=email,
151158
name=name, created_at=created_at, custom_data=custom_data,
152159
last_seen_ip=last_seen_ip, last_seen_user_agent=last_seen_user_agent)
153160

154161
@classmethod
155-
def update_user(cls, user_id=None, email=None, name=None, created_at=None,
162+
def update_user(
163+
cls, user_id=None, email=None, name=None, created_at=None,
156164
custom_data=None, last_seen_ip=None, last_seen_user_agent=None):
157165
""" Update a user with the available parameters.
158166
@@ -164,7 +172,8 @@ def update_user(cls, user_id=None, email=None, name=None, created_at=None,
164172
u'Han'
165173
166174
"""
167-
return Intercom._create_or_update_user('PUT', user_id=user_id, email=email,
175+
return Intercom._create_or_update_user(
176+
'PUT', user_id=user_id, email=email,
168177
name=name, created_at=created_at, custom_data=custom_data,
169178
last_seen_ip=last_seen_ip, last_seen_user_agent=last_seen_user_agent)
170179

@@ -177,13 +186,17 @@ def delete_user(cls, user_id=None, email=None):
177186
u'bob@example.com'
178187
179188
"""
180-
params = { 'email': email, 'user_id': user_id }
189+
params = {
190+
'email': email,
191+
'user_id': user_id
192+
}
181193
user_dict = Intercom._call('DELETE', Intercom.api_endpoint + 'users', params)
182194
return user_dict
183195

184196
@classmethod
185-
def create_impression(cls, user_id=None, email=None, user_ip=None,
186-
user_agent=None, location=None):
197+
def create_impression(
198+
cls, user_id=None, email=None, user_ip=None,
199+
user_agent=None, location=None):
187200
""" Create an impression.
188201
189202
>>> result = Intercom.create_impression(email="somebody@example.com",
@@ -192,10 +205,15 @@ def create_impression(cls, user_id=None, email=None, user_ip=None,
192205
1
193206
194207
"""
195-
params = { 'email': email, 'user_id': user_id, 'user_ip': user_ip,
196-
'user_agent': user_agent, 'location': location }
197-
user_dict = Intercom._call('POST', Intercom.api_endpoint + 'users/impressions',
198-
params=params)
208+
params = {
209+
'email': email,
210+
'user_id': user_id,
211+
'user_ip': user_ip,
212+
'user_agent': user_agent,
213+
'location': location
214+
}
215+
user_dict = Intercom._call(
216+
'POST', Intercom.api_endpoint + 'users/impressions', params=params)
199217
return user_dict
200218

201219
@classmethod
@@ -210,9 +228,13 @@ def create_note(cls, user_id=None, email=None, body=None):
210228
u'somebody@example.com'
211229
212230
"""
213-
params = { 'email': email, 'user_id': user_id, 'body': body }
214-
user_dict = Intercom._call('POST', Intercom.api_endpoint + 'users/notes',
215-
params=params)
231+
params = {
232+
'email': email,
233+
'user_id': user_id,
234+
'body': body
235+
}
236+
user_dict = Intercom._call(
237+
'POST', Intercom.api_endpoint + 'users/notes', params=params)
216238
return user_dict
217239

218240
@classmethod
@@ -230,9 +252,13 @@ def get_message_threads(cls, user_id=None, email=None, thread_id=None):
230252
<type 'dict'>
231253
232254
"""
233-
params = { 'email': email, 'user_id': user_id, 'thread_id': thread_id }
234-
msg_dict = Intercom._call('GET', Intercom.api_endpoint + 'users/message_threads',
235-
params=params)
255+
params = {
256+
'email': email,
257+
'user_id': user_id,
258+
'thread_id': thread_id
259+
}
260+
msg_dict = Intercom._call(
261+
'GET', Intercom.api_endpoint + 'users/message_threads', params=params)
236262
return msg_dict
237263

238264
@classmethod
@@ -249,14 +275,18 @@ def create_message_thread(cls, user_id=None, email=None, body=None):
249275
u"<p>Uh, everything's under control. Situation normal.</p>"
250276
251277
"""
252-
params = { 'email': email, 'user_id': user_id, 'body': body }
253-
user_dict = Intercom._call('POST', Intercom.api_endpoint + 'users/message_threads',
254-
params=params)
278+
params = {
279+
'email': email,
280+
'user_id': user_id,
281+
'body': body
282+
}
283+
user_dict = Intercom._call(
284+
'POST', Intercom.api_endpoint + 'users/message_threads', params=params)
255285
return user_dict
256286

257287
@classmethod
258-
def reply_message_thread(cls, user_id=None, email=None, thread_id=None,
259-
body=None, read=None):
288+
def reply_message_thread(
289+
cls, user_id=None, email=None, thread_id=None, body=None, read=None):
260290
""" Reply to the specific thread.
261291
262292
>>> message_thread = Intercom.reply_message_thread(email="somebody@example.com",
@@ -269,8 +299,13 @@ def reply_message_thread(cls, user_id=None, email=None, thread_id=None,
269299
2
270300
271301
"""
272-
params = { 'email': email, 'user_id': user_id, 'thread_id': thread_id,
273-
'body': body, 'read': read }
274-
user_dict = Intercom._call('PUT', Intercom.api_endpoint + 'users/message_threads',
275-
params=params)
302+
params = {
303+
'email': email,
304+
'user_id': user_id,
305+
'thread_id': thread_id,
306+
'body': body,
307+
'read': read
308+
}
309+
user_dict = Intercom._call(
310+
'PUT', Intercom.api_endpoint + 'users/message_threads', params=params)
276311
return user_dict

0 commit comments

Comments
 (0)