From d8f598cbcd7d0d47a58b2f2f066a75e8b08b0605 Mon Sep 17 00:00:00 2001 From: Josh Roesslein Date: Thu, 13 Aug 2009 13:34:32 -0500 Subject: [PATCH] Added follow/unfollow shortcuts to User model. Fixed issue with User.following being set to None when user not followed. --- CHANGES | 10 ++++++++-- ROADMAP | 1 + tweepy/models.py | 7 +++++++ tweepy/parsers.py | 6 ++++++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index d826004..f3fe1c7 100644 --- a/CHANGES +++ b/CHANGES @@ -2,5 +2,11 @@ All changes made to the library that might affect applications during upgrade will be listed here. 1.0 -> 1.0.1 ------------- -Status.user --> Status.author +============ ++ Status.user --> Status.author ++ User: + + follow() + + unfollow() ++ Fixes + + User.following is now set to False instead of None + when user is not followed. diff --git a/ROADMAP b/ROADMAP index 79e6f41..e2b61d0 100644 --- a/ROADMAP +++ b/ROADMAP @@ -9,4 +9,5 @@ The plan of attack for the next version of Tweepy. + rate limit governor + prepare for social graph changes mentioned on mailinglist + finish search api ++ autodetect authenticated user's ID diff --git a/tweepy/models.py b/tweepy/models.py index eb5ec14..329a236 100644 --- a/tweepy/models.py +++ b/tweepy/models.py @@ -68,6 +68,13 @@ class User(Model): def followers(self, **kargs): return self._api.followers(id=self.id, **kargs) + def follow(self): + self._api.create_friendship(user_id=self.id) + self.following = True + def unfollow(self): + self._api.destroy_friendship(user_id=self.id) + self.following = False + class DirectMessage(Model): def destroy(self): diff --git a/tweepy/parsers.py b/tweepy/parsers.py index 0f3f2f9..bbde005 100644 --- a/tweepy/parsers.py +++ b/tweepy/parsers.py @@ -52,6 +52,12 @@ def _parse_user(obj, api): setattr(user, k, _parse_datetime(v)) elif k == 'status': setattr(user, k, _parse_status(v, api)) + elif k == 'following': + # twitter sets this to null if it is false + if v is True: + setattr(user, k, True) + else: + setattr(user, k, False) else: setattr(user, k, v) return user -- 2.25.1