Browse Source

Favourite functions

master
Julio Biason 15 years ago
parent
commit
38e3447f7a
  1. 8
      issues/issue-9afa1b63c3df1833387f8ddfcf8a28a2f01105a5.yaml
  2. 10
      mitterlib/network/__init__.py
  3. 16
      mitterlib/network/networkbase.py
  4. 16
      mitterlib/network/twitter.py

8
issues/issue-9afa1b63c3df1833387f8ddfcf8a28a2f01105a5.yaml

@ -5,8 +5,8 @@ type: :feature
component: network
release: 1.0.0
reporter: Julio Biason <julio.biason@gmail.com>
status: :unstarted
disposition:
status: :closed
disposition: :fixed
creation_time: 2009-12-16 11:17:47.876106 Z
references: []
@ -16,3 +16,7 @@ log_events:
- Julio Biason <julio.biason@gmail.com>
- created
- ""
- - 2009-12-20 21:30:24.326334 Z
- Julio Biason <julio.biason@gmail.com>
- closed with disposition fixed
- ""

10
mitterlib/network/__init__.py

@ -176,6 +176,11 @@ class Networks(object):
self.networks[message.network].repost(message)
return
def favourite(self, message):
"""Change the favourite status of the message."""
self.networks[message.network].favourite(message)
return
def delete_message(self, message, network=None):
"""Delete an update. Message can be a NetworkData object, in which
case network is not necessary; otherwise a network must be
@ -231,6 +236,11 @@ class Networks(object):
"""Return True if the message can be resposted; False otherwise."""
return self.networks[message.network].can_repost(message)
def can_favourite(self, message):
"""Return True if the message can be favourited/unfavourited; False
otherwise."""
return self.networks[message.network].can_favourite(message)
# TODO: Function to return a regexp for usernames
# TODO: Function to return a pre-message for replies (how to handle
# dynamic content, like usernames?)

16
mitterlib/network/networkbase.py

@ -127,6 +127,9 @@ class NetworkData(object):
**message_time**
Message timestamp (as a datetime object). Defaults to None.
**favourite**
Boolean indicating if the message was marked as "favourite" or not.
**parent**
The parent of this message, in case of a reply.
@ -151,6 +154,7 @@ class NetworkData(object):
self.avatar = ''
self.message = ''
self.message_time = None
self.favourite = False
self.parent = ''
self.reposted_by = ''
self.network = ''
@ -220,6 +224,13 @@ class NetworkBase(object):
# anyway?
return None
def favourite(self, message):
"""Toggle the favourite status of a message. *message* must be a valid
:class:`NetworkData` object. Returns True if the request was
successful or False otherwise."""
# TODO: Again, if errors appear as exceptions, why return something?
return False
def delete_message(self, message):
"""Delete an update. Must return True if the message was deleted or
False if not. *message* can be either an id or a :class:`NetworkData`
@ -253,3 +264,8 @@ class NetworkBase(object):
def can_repost(self, message):
"""Return True if the message can be resposted; False otherwise."""
return False
def can_favourite(self, message):
"""Return True if the message can be favourited/unfavourited; False
otherwise."""
return False

16
mitterlib/network/twitter.py

@ -116,6 +116,7 @@ class TwitterNetworkData(NetworkData):
self.username = data['user']['screen_name']
self.avatar = data['user']['profile_image_url']
self.message_time = _to_datetime(data['created_at'])
self.favourited = data['favorited']
if 'in_reply_to_status_id' in data and data['in_reply_to_status_id']:
self.parent = int(data['in_reply_to_status_id'])
@ -410,6 +411,16 @@ class Connection(NetworkBase):
data = self._request(resource, body=body)
return TwitterNetworkData(data)
def favourite(self, message):
"""Mark a message as favourite."""
body = urllib.urlencode({'id': message.id})
if not message.favourite:
resource = '/favorites/create/%d.json' % (message.id)
else:
resource = '/favorites/destroy/%d.json' % (message.id)
data = self._request(resource, body=body)
return TwitterNetworkData(data)
def delete_message(self, message):
"""Delete a message."""
if isinstance(message, NetworkData):
@ -436,3 +447,8 @@ class Connection(NetworkBase):
"""Twitter ignores retweets from the user."""
return not (message.username ==
self._options[self.NAMESPACE]['username'])
def can_favourite(self, message):
"""Always return True; Twitter allows favouriting/unfavouriting any
messages."""
return True

Loading…
Cancel
Save