# Copyright 2009 Joshua Roesslein
# See LICENSE
+from error import TweepError
+
class Model(object):
def __getstate__(self):
pickle[k] = v
return pickle
+ @staticmethod
+ def _validate(model, attributes):
+ missing = []
+ for attr in attributes:
+ if not hasattr(model, attr):
+ missing.append(attr)
+ if len(missing) > 0:
+ raise TweepError('Missing required attribute(s) %s' % str(missing).strip('[]'))
+
class Status(Model):
+ @staticmethod
+ def _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'
+ ])
+ if hasattr(status, 'user'):
+ User._validate(status.user)
+ def validate(self):
+ Status._validate(self)
+
def destroy(self):
return self._api.destroy_status(id=self.id)
class User(Model):
+ @staticmethod
+ def _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',
+ 'friends_count', 'created_at', 'favourites_count', 'utc_offset', 'time_zone',
+ 'profile_background_image_url', 'statuses_count', 'notifications', 'following',
+ 'verified'
+ ])
+ if hasattr(user, 'status'):
+ Status._validate(user.status)
+ def validate(self):
+ User._validate(self)
+
def timeline(self, **kargs):
return self._api.user_timeline(**kargs)
def mentions(self, **kargs):