From: Josh Roesslein Date: Fri, 14 Aug 2009 14:51:25 +0000 (-0500) Subject: Added API.new() method. Updated tweepyshell. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c64242b46fd79f370b2811115a0fb0f3fda7fc50;p=tweepy.git Added API.new() method. Updated tweepyshell. --- diff --git a/CHANGES b/CHANGES index 7ed169c..b38b357 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,8 @@ during upgrade will be listed here. + API: + __init__() signature change; no longer accepts 'username' parameter which is now autodetected. + + added new() method. shortcut for setting up new API instances + example: API.new(auth='basic', username='testuser', password='testpass') + Fixes + User.following is now set to False instead of None when user is not followed. diff --git a/tweepy/api.py b/tweepy/api.py index 7f39cfc..0592b47 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -5,6 +5,7 @@ from . binder import bind_api from . parsers import * from . error import TweepError +from . auth import BasicAuthHandler, OAuthHandler """Twitter API""" class API(object): @@ -22,6 +23,15 @@ class API(object): # not a good idea to touch these self._username = None + @staticmethod + def new(auth='basic', *args, **kargs): + if auth == 'basic': + return API(BasicAuthHandler(*args, **kargs)) + elif auth == 'oauth': + return API(OAuthHandler(*args, **kargs)) + else: + raise TweepError('Invalid auth type') + """Get public timeline""" public_timeline = bind_api( path = '/statuses/public_timeline.json', diff --git a/tweepy/auth.py b/tweepy/auth.py index 59d502d..86dcdc1 100644 --- a/tweepy/auth.py +++ b/tweepy/auth.py @@ -85,6 +85,4 @@ class OAuthHandler(AuthHandler): return self.access_token except Exception, e: raise TweepError(e) - - diff --git a/tweepyshell.py b/tweepyshell.py index 5f7de00..df4b479 100755 --- a/tweepyshell.py +++ b/tweepyshell.py @@ -17,7 +17,7 @@ if len(sys.argv) != 3: print 'Usage: tweepyshell ' exit(1) -api = tweepy.API(tweepy.BasicAuthHandler(sys.argv[1], sys.argv[2])) +api = tweepy.API.new(auth='basic', username=sys.argv[1], password=sys.argv[2]) if api.verify_credentials() is False: print 'Invalid username and/or password!' exit(1)