Browse Source

is_setup (and the new user) are now property, which makes more sense,

actually.

(Also, it seems I'm in a @property mood lately.)
master
Julio Biason 14 years ago
parent
commit
511babf5f2
  1. 2
      mitterlib/network/__init__.py
  2. 38
      mitterlib/network/networkbase.py
  3. 13
      mitterlib/network/twitter.py

2
mitterlib/network/__init__.py

@ -113,7 +113,7 @@ class Networks(object):
setup = False
for target in targets:
if self.networks[target].is_setup():
if self.networks[target].is_setup:
setup = True
yield target

38
mitterlib/network/networkbase.py

@ -106,22 +106,19 @@ class MessageTooLongWarning(NetworkWarning):
#--------------------------------------------------------------------
class NetworkUser(object):
"""Provides an uniform way to access information about users. The
following fields should appear:
**name**
The name to be displayed as author of the message. *Required*
**username**
The message author username in the network. *Required*
**avatar**
URL to the author avatar. *Optional*
"""
"""Provides an uniform way to access information about users."""
def __init__(self):
self.name = ''
"""The name to be displayed as author of the message. *Required*"""
self.username = ''
self.avatar = ''
"""The message author username in the network. *Required*"""
self.avatar = None
"""URL to the author avatar. *Optional*"""
def __repr__(self):
return "%s (%s)" % (self.name, self.username)
class NetworkData(object):
@ -228,12 +225,15 @@ class NetworkBase(object):
if possible.
"""
def is_setup(self):
"""Should return a boolean indicating if the network have all
necessary options set up so it can retrieve information.
:class:`Networks` won't send requests to networks that return False to
this function."""
return False
def __init__(self):
self.is_setup = False
"""Boolean indication if the network have all necessary options set up
so it can retrieve the messages. :class:`Networks` will not send
requests to networks that return False to this function."""
self.user = NetworkUser()
"""A :class:`NetworkUser` with the information about the currently
logged user."""
def messages(self):
"""Return a list of :class:`NetworkData` objects for the main

13
mitterlib/network/twitter.py

@ -174,6 +174,7 @@ class Connection(NetworkBase):
NAMESPACE = 'Twitter'
SHORTCUT = 'tw' # TODO: find a way to move this to the config file
@property
def is_setup(self):
"""Return True or False if the network is setup/enabled."""
if (self._options[self.NAMESPACE]['username'] and
@ -184,8 +185,20 @@ class Connection(NetworkBase):
else:
return False
@property
def user(self):
"""Information about this user."""
if self._user:
return self._user
user = self._request('/account/verify_credentials.json')
self._user = TwitterNetworkUser(user)
_log.debug("User: %s" % (self._user))
return self._user
def __init__(self, options):
self._options = options
self._user = None
@property
def server(self):

Loading…
Cancel
Save