2008-10-03 17:44:31 +05:30
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
__author__ = "Abhinav Sarkar <abhinav@abhinavsarkar.net>"
|
|
|
|
__version__ = "0.2"
|
|
|
|
__license__ = "GNU Lesser General Public License"
|
2009-03-17 20:51:40 +05:30
|
|
|
__package__ = "lastfm.mixins"
|
2008-10-03 17:44:31 +05:30
|
|
|
|
2009-03-31 09:09:23 +05:30
|
|
|
def sharable(cls):
|
2008-10-03 17:44:31 +05:30
|
|
|
def share(self, recipient, message = None):
|
2008-12-31 11:00:23 +05:30
|
|
|
from lastfm.user import User
|
2008-12-30 15:57:13 +05:30
|
|
|
params = self._default_params({'method': '%s.share' % self.__class__.__name__.lower()})
|
2008-10-03 17:44:31 +05:30
|
|
|
if message is not None:
|
|
|
|
params['message'] = message
|
|
|
|
|
|
|
|
if not isinstance(recipient, list):
|
|
|
|
recipient = [recipient]
|
|
|
|
|
|
|
|
for i in xrange(len(recipient)):
|
|
|
|
if isinstance(recipient[i], User):
|
|
|
|
recipient[i] = recipient[i].name
|
|
|
|
params['recipient'] = ",".join(recipient)
|
2008-12-30 19:21:04 +05:30
|
|
|
self._api._post_data(params)
|
|
|
|
|
2009-03-18 08:49:57 +05:30
|
|
|
def _default_params(self, extra_params = None):
|
|
|
|
if extra_params is not None:
|
|
|
|
return extra_params
|
|
|
|
else:
|
2009-03-31 09:09:23 +05:30
|
|
|
return {}
|
|
|
|
|
|
|
|
cls.share = share
|
|
|
|
if not hasattr(cls, '_default_params'):
|
|
|
|
cls._default_params = _default_params
|
|
|
|
|
2009-03-31 21:14:18 +05:30
|
|
|
if not hasattr(cls, '_mixins'):
|
|
|
|
cls._mixins = []
|
|
|
|
cls._mixins.append('share')
|
|
|
|
|
2009-03-31 09:09:23 +05:30
|
|
|
return cls
|