Skip to content

Commit

Permalink
Flattr integration: Show error messages to user
Browse files Browse the repository at this point in the history
  • Loading branch information
thp committed Jul 13, 2012
1 parent f069abc commit c469f43
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
27 changes: 19 additions & 8 deletions src/gpodder/flattr.py
Expand Up @@ -24,6 +24,7 @@
#

import urllib
import urllib2
import json

import logging
Expand Down Expand Up @@ -72,7 +73,11 @@ def request(self, url, data=None):
if data is not None:
data = json.dumps(data)

response = util.urlopen(url, headers, data)
try:
response = util.urlopen(url, headers, data)
except urllib2.HTTPError, error:
return {'_gpodder_statuscode': error.getcode()}

if response.getcode() == 200:
return json.loads(response.read())

Expand Down Expand Up @@ -112,6 +117,13 @@ def get_auth_username(self):
return data.get('username', '')

def flattr_url(self, url):
"""Flattr an object given its Flattr URL
Returns a tuple (success, message):
success ... True if the item was Flattr'd
message ... The success or error message
"""
params = {
'url': url
}
Expand All @@ -121,14 +133,13 @@ def flattr_url(self, url):
if '_gpodder_statuscode' in content:
status_code = content['_gpodder_statuscode']
if status_code == 401:
return _('Not enough means to flattr')
return (False, _('Not enough means to flattr'))
elif status_code == 404:
return _('Item does not exist on Flattr')
return (False, _('Item does not exist on Flattr'))
elif status_code == 403:
# The current user have already flattred the thing or the user
# is the owner of the thing we just silently ignore this case
None
return (True, _('Already flattred or own item'))
else:
return _('Invalid request')
return (False, _('Invalid request'))

return (True, content.get('description', _('No description')))

return content.get('description', _('No description'))
4 changes: 2 additions & 2 deletions src/gpodder/gtkui/desktop/channel.py
Expand Up @@ -192,6 +192,6 @@ def set_flattr_information(self):

def on_flattr_button_clicked(self, widget):
if self.flattr_possible:
status = self._flattr.flattr_url(self.channel.payment_url)
self.show_message(status, title=_('Flattr status'))
success, message = self._flattr.flattr_url(self.channel.payment_url)
self.show_message(message, title=_('Flattr status'), important=not success)
self.set_flattr_information()
4 changes: 2 additions & 2 deletions src/gpodder/gtkui/interface/shownotes.py
Expand Up @@ -99,8 +99,8 @@ def set_flattr_information(self):

def on_flattr_button_clicked(self, widget):
if self.flattr_possible:
status = self._flattr.flattr_url(self.episode.payment_url)
self.show_message(status, title=_('Flattr status'))
success, message = self._flattr.flattr_url(self.episode.payment_url)
self.show_message(message, title=_('Flattr status'), important=not success)
self.set_flattr_information()

#############################################################
Expand Down
8 changes: 4 additions & 4 deletions src/gpodder/gtkui/main.py
Expand Up @@ -1909,8 +1909,8 @@ def error_handler(filename, err):

# flattr episode if auto-flattr is enabled
if self.config.flattr.token and self.config.flattr.flattr_on_play:
status = self.flattr.flattr_url(episode.payment_url)
self.show_message(status, title=_('Flattr status'))
success, message = self.flattr.flattr_url(episode.payment_url)
self.show_message(message, title=_('Flattr status'), important=not success)

groups[player].append(filename)

Expand Down Expand Up @@ -3182,8 +3182,8 @@ def set_flattr_information(self, widget):

def on_flattr_button_clicked(self, widget, event):
if self.flattr_possible:
status = self.flattr.flattr_url(self.channel.payment_url)
self.show_message(status, title=_('Flattr status'))
success, message = self.flattr.flattr_url(self.channel.payment_url)
self.show_message(message, title=_('Flattr status'), important=not success)
self.set_flattr_information(widget.get_children()[0])

def on_itemAbout_activate(self, widget, *args):
Expand Down

0 comments on commit c469f43

Please sign in to comment.