Skip to content

Commit 169218b

Browse files
committed
update for twitter.UserStatus object to include connections
1 parent 0e44e76 commit 169218b

2 files changed

Lines changed: 23 additions & 7 deletions

File tree

tests/test_api_30.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,7 @@ def testLookupFriendshipMute(self):
14241424
match_querystring=True,
14251425
status=200)
14261426
resp = self.api.LookupFriendship(screen_name='dickc')
1427+
self.assertEqual(resp[0].blocking, False)
14271428
self.assertEqual(resp[0].muting, True)
14281429

14291430
@responses.activate

twitter/models.py

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ def __str__(self):
1212
return self.AsJsonString()
1313

1414
def __eq__(self, other):
15-
return other and \
16-
self.AsDict() == other.AsDict()
15+
return other and self.AsDict() == other.AsDict()
1716

1817
def __ne__(self, other):
1918
return not self.__eq__(other)
@@ -220,24 +219,40 @@ class UserStatus(TwitterModel):
220219
""" A class representing the UserStatus structure. This is an abbreviated
221220
form of the twitter.User object. """
222221

222+
connections = {'following': False,
223+
'followed_by': False,
224+
'following_received': False,
225+
'following_requested': False,
226+
'blocking': False,
227+
'muting': False}
228+
223229
def __init__(self, **kwargs):
224230
self.param_defaults = {
225231
'name': None,
226232
'id': None,
227233
'id_str': None,
228234
'screen_name': None,
229-
'following': None,
230-
'followed_by': None}
235+
'following': False,
236+
'followed_by': False,
237+
'following_received': False,
238+
'following_requested': False,
239+
'blocking': False,
240+
'muting': False}
231241

232242
for (param, default) in self.param_defaults.items():
233243
setattr(self, param, kwargs.get(param, default))
234244

245+
if 'connections' in kwargs:
246+
for param in self.connections:
247+
if param in kwargs['connections']:
248+
setattr(self, param, True)
249+
235250
def __repr__(self):
236-
return "UserStatus(ID={uid}, Name={sn}, Following={fng}, Followed={fed})".format(
251+
conns = [param for param in self.connections if getattr(self, param)]
252+
return "UserStatus(ID={uid}, Name={sn}, Connections=[{conn}])".format(
237253
uid=self.id,
238254
sn=self.screen_name,
239-
fng=self.following,
240-
fed=self.followed_by)
255+
conn=", ".join(conns))
241256

242257

243258
class User(TwitterModel):

0 commit comments

Comments
 (0)