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 15 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 setup = False
for target in targets: for target in targets:
if self.networks[target].is_setup(): if self.networks[target].is_setup:
setup = True setup = True
yield target yield target

38
mitterlib/network/networkbase.py

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

13
mitterlib/network/twitter.py

@ -174,6 +174,7 @@ class Connection(NetworkBase):
NAMESPACE = 'Twitter' NAMESPACE = 'Twitter'
SHORTCUT = 'tw' # TODO: find a way to move this to the config file SHORTCUT = 'tw' # TODO: find a way to move this to the config file
@property
def is_setup(self): def is_setup(self):
"""Return True or False if the network is setup/enabled.""" """Return True or False if the network is setup/enabled."""
if (self._options[self.NAMESPACE]['username'] and if (self._options[self.NAMESPACE]['username'] and
@ -184,8 +185,20 @@ class Connection(NetworkBase):
else: else:
return False 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): def __init__(self, options):
self._options = options self._options = options
self._user = None
@property @property
def server(self): def server(self):

Loading…
Cancel
Save