Skip to content

Commit

Permalink
Merge pull request tweepy#156 from kodkultur/master
Browse files Browse the repository at this point in the history
Implemented /friendships/lookup
  • Loading branch information
joshthecoder committed Aug 19, 2012
2 parents 65a26c2 + aa055fe commit ab2be46
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 @@ -279,6 +279,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 @@ -292,6 +292,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 @@ -325,6 +336,7 @@ class ModelFactory(object):
search_result = SearchResult
list = List
relation = Relation
relationship = Relationship

json = JSONModel
ids = IDModel
Expand Down

0 comments on commit ab2be46

Please sign in to comment.