Commit 19433225 authored by Josh Roesslein's avatar Josh Roesslein
Browse files

Fix some bugs with new model validation code.

parent 971cf1fa
......@@ -11,7 +11,8 @@ from error import TweepError
class API(object):
def __init__(self, auth_handler=None, username=None, host='', cache=None,
secure=False, api_root='', classes={'user': User, 'status': Status,
secure=False, api_root='', validate=True,
classes={'user': User, 'status': Status,
'direct_message': DirectMessage, 'friendship': Friendship,
'saved_search': SavedSearch, 'search_result': SearchResult}):
self.auth_handler = auth_handler
......@@ -20,6 +21,7 @@ class API(object):
self.api_root = api_root
self.cache = cache = secure
self.validate = validate
self.classes = classes
"""Get public timeline"""
......@@ -79,13 +79,24 @@ def bind_api(path, parser, allowed_param=None, method='GET', require_auth=False,
# Pass returned body into parser and return parser output
out = parser(, api)
# validate result
if api.validate:
# list of results
if isinstance(out, list) and len(out) > 0:
if hasattr(out[0], 'validate'):
for result in out:
# single result
if hasattr(out, 'validate'):
# store result in cache
if api.cache and method == 'GET':, out)
# close connection and return data
return out
return _call
......@@ -27,7 +27,7 @@ class Status(Model):
def _validate(status):
Model.validate(status, [
Model._validate(status, [
'created_at', 'id', 'text', 'source', 'truncated', 'in_reply_to_status_id',
'in_reply_to_user_id', 'favorited', 'in_reply_to_screen_name'
......@@ -43,7 +43,7 @@ class User(Model):
def _validate(user):
Model.validate(user, [
Model._validate(user, [
'id', 'name', 'screen_name', 'location', 'description', 'profile_image_url',
'url', 'protected', 'followers_count', 'profile_background_color',
'profile_text_color', 'profile_sidebar_fill_color', 'profile_sidebar_border_color',
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