Commit 6466483e authored by Josh Roesslein's avatar Josh Roesslein
Browse files

Autodetect username inside the API.me() method.

parent 82df16e4
......@@ -7,6 +7,9 @@ during upgrade will be listed here.
+ User:
+ follow()
+ unfollow()
+ API:
+ __init__() signature change; no longer accepts 'username' parameter
which is now autodetected.
+ Fixes
+ User.following is now set to False instead of None
when user is not followed.
......@@ -9,5 +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
+ autodetect authenticated user's ID [DONE]
......@@ -9,16 +9,19 @@ from . error import TweepError
"""Twitter API"""
class API(object):
def __init__(self, auth_handler=None, username=None, host='twitter.com', cache=None,
def __init__(self, auth_handler=None, host='twitter.com', cache=None,
secure=False, api_root='', validate=True):
# you may access these freely
self.auth_handler = auth_handler
self.username = username
self.host = host
self.api_root = api_root
self.cache = cache
self.secure = secure
self.validate = validate
# not a good idea to touch these
self._username = None
"""Get public timeline"""
public_timeline = bind_api(
path = '/statuses/public_timeline.json',
......@@ -84,10 +87,18 @@ class API(object):
"""Get authenticated user"""
def me(self):
if self.username:
return self.get_user(screen_name=self.username)
else:
return None
# if username not fetched, go get it...
if self._username is None:
if self.auth_handler is None:
raise TweepError('Authentication required')
try:
user = bind_api(path='/account/verify_credentials.json', parser=parse_user)(self)
except TweepError, e:
raise TweepError('Failed to fetch username: %s' % e)
self._username = user.screen_name
return self.get_user(screen_name=self._username)
"""Show friends"""
friends = bind_api(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment