Skip to content

Commit

Permalink
Added support for /friendships/lookup api call
Browse files Browse the repository at this point in the history
  • Loading branch information
John Gunnarsson authored and John Gunnarsson committed Mar 19, 2012
1 parent 6d7d73c commit aa055fe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tweepy/api.py
Expand Up @@ -278,6 +278,19 @@ def me(self):
'target_id', 'target_screen_name']
)


""" Perform bulk look up of friendships from user ID or screenname """
def lookup_friendships(self, user_ids=None, screen_names=None):
return self._lookup_friendships(list_to_csv(user_ids), list_to_csv(screen_names))

_lookup_friendships = bind_api(
path = '/friendships/lookup.json',
payload_type = 'relationship', payload_list = True,
allowed_param = ['user_id', 'screen_name'],
require_auth = True
)


""" friends/ids """
friends_ids = bind_api(
path = '/friends/ids.json',
Expand Down
12 changes: 12 additions & 0 deletions tweepy/models.py
Expand Up @@ -290,6 +290,17 @@ def parse(cls, api, json):
setattr(result, k, v)
return result

class Relationship(Model):
@classmethod
def parse(cls, api, json):
result = cls(api)
for k,v in json.items():
if k == 'connections':
setattr(result, 'is_following', 'following' in v)
setattr(result, 'is_followed_by', 'followed_by' in v)
else:
setattr(result, k, v)
return result

class JSONModel(Model):

Expand Down Expand Up @@ -323,6 +334,7 @@ class ModelFactory(object):
search_result = SearchResult
list = List
relation = Relation
relationship = Relationship

json = JSONModel
ids = IDModel
Expand Down

0 comments on commit aa055fe

Please sign in to comment.