Commit 7281dd61 authored by Josh Roesslein's avatar Josh Roesslein
Browse files

Added some api endpoints to user model.

parent 8951f603
......@@ -17,6 +17,9 @@ class API(object): = secure
self.classes = classes
if username: = self.get_user(screen_name=username)
"""Get public timeline"""
public_timeline = bind_api(
path = '/statuses/public_timeline.json',
......@@ -45,7 +45,7 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False)
raise TweepError(parse_error(
# Pass returned body into parser and return parser output
out = parser(, api.classes)
out = parser(, api)
# close connection and return data
......@@ -4,4 +4,11 @@ class Status(object):
class User(object):
def timeline(self, **kargs):
return self._api.user_timeline(**kargs)
def mentions(self, **kargs):
return self._api.mentions(**kargs)
def friends(self, **kargs):
return self._api.friends(, **kargs)
def followers(self, **kargs):
return self._api.followers(, **kargs)
......@@ -13,48 +13,50 @@ def _parse_datetime(str):
return datetime.strptime(str, '%a %b %d %H:%M:%S +0000 %Y')
def _parse_user(obj, classes):
def _parse_user(obj, api):
user = classes['user']()
user = api.classes['user']()
user._api = api
for k,v in obj.items():
if k == 'created_at':
setattr(user, k, _parse_datetime(v))
elif k == 'status':
setattr(user, k, _parse_status(v, classes))
setattr(user, k, _parse_status(v, api))
setattr(user, k, v)
return user
def parse_user(data, classes):
def parse_user(data, api):
return _parse_user(json.loads(data), classes)
return _parse_user(json.loads(data), api)
def parse_users(data, classes):
def parse_users(data, api):
users = []
for obj in json.loads(data):
users.append(_parse_user(obj, classes))
users.append(_parse_user(obj, api))
return users
def _parse_status(obj, classes):
def _parse_status(obj, api):
status = classes['status']()
status = api.classes['status']()
status._api = api
for k,v in obj.items():
if k == 'user':
setattr(status, k, _parse_user(v, classes))
setattr(status, k, _parse_user(v, api))
elif k == 'created_at':
setattr(status, k, _parse_datetime(v))
setattr(status, k, v)
return status
def parse_status(data, classes):
def parse_status(data, api):
return _parse_status(json.loads(data), classes)
return _parse_status(json.loads(data), api)
def parse_statuses(data, classes):
def parse_statuses(data, api):
statuses = []
for obj in json.loads(data):
statuses.append(_parse_status(obj, classes))
statuses.append(_parse_status(obj, api))
return statuses
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