Merge pull request #127 from michaelhelmick/fix-legacy-urls

Fixing up some urls, cleaning up code
This commit is contained in:
Ryan McGrath 2012-11-10 17:03:14 -08:00
commit e85e8e38ad

View file

@ -203,10 +203,7 @@ class Twython(object):
'error', 'An error occurred processing your request.') 'error', 'An error occurred processing your request.')
self._last_call['api_error'] = error_msg self._last_call['api_error'] = error_msg
if response.status_code == 420: exceptionType = TwythonRateLimitError if response.status_code == 420 else TwythonError
exceptionType = TwythonRateLimitError
else:
exceptionType = TwythonError
raise exceptionType(error_msg, raise exceptionType(error_msg,
error_code=response.status_code, error_code=response.status_code,
@ -420,43 +417,48 @@ class Twython(object):
def _media_update(self, url, file_, **params): def _media_update(self, url, file_, **params):
return self.post(url, params=params, files=file_) return self.post(url, params=params, files=file_)
def updateProfileBackgroundImage(self, file_, tile=True, version=1): def updateProfileBackgroundImage(self, file_, version='1.1', **params):
"""Updates the authenticating user's profile background image. """Updates the authenticating user's profile background image.
:param file_: (required) A string to the location of the file :param file_: (required) A string to the location of the file
(less than 800KB in size, larger than 2048px width will scale down) (less than 800KB in size, larger than 2048px width will scale down)
:param tile: (optional) Default ``True`` If set to true the background image :param version: (optional) A number, default 1.1 because that's the
will be displayed tiled. The image will not be tiled otherwise. current API version for Twitter (Legacy = 1)
:param version: (optional) A number, default 1 because that's the
only API version Twitter has now **params - You may pass items that are stated in this doc
(https://dev.twitter.com/docs/api/1.1/post/account/update_profile_background_image)
""" """
url = 'https://api.twitter.com/%d/account/update_profile_background_image.json' % version url = 'https://api.twitter.com/%s/account/update_profile_background_image.json' % version
return self._media_update(url, return self._media_update(url,
{'image': (file_, open(file_, 'rb'))}, {'image': (file_, open(file_, 'rb'))},
**{'tile': tile}) **params)
def updateProfileImage(self, file_, version=1): def updateProfileImage(self, file_, version='1.1', **params):
"""Updates the authenticating user's profile image (avatar). """Updates the authenticating user's profile image (avatar).
:param file_: (required) A string to the location of the file :param file_: (required) A string to the location of the file
:param version: (optional) A number, default 1 because that's the :param version: (optional) A number, default 1.1 because that's the
only API version Twitter has now current API version for Twitter (Legacy = 1)
**params - You may pass items that are stated in this doc
(https://dev.twitter.com/docs/api/1.1/post/account/update_profile_image)
""" """
url = 'https://api.twitter.com/%d/account/update_profile_image.json' % version url = 'https://api.twitter.com/%s/account/update_profile_image.json' % version
return self._media_update(url, return self._media_update(url,
{'image': (file_, open(file_, 'rb'))}) {'image': (file_, open(file_, 'rb'))},
**params)
def updateStatusWithMedia(self, file_, version='1.1', **params): def updateStatusWithMedia(self, file_, version='1.1', **params):
"""Updates the users status with media """Updates the users status with media
:param file_: (required) A string to the location of the file :param file_: (required) A string to the location of the file
:param version: (optional) A number, default 1 because that's the :param version: (optional) A number, default 1.1 because that's the
only API version Twitter has now current API version for Twitter (Legacy = 1)
**params - You may pass items that are taken in this doc **params - You may pass items that are taken in this doc
(https://dev.twitter.com/docs/api/1/post/statuses/update_with_media) (https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media)
""" """
url = 'https://upload.twitter.com/%d/statuses/update_with_media.json' % version url = 'https://upload.twitter.com/%s/statuses/update_with_media.json' % version
return self._media_update(url, return self._media_update(url,
{'media': (file_, open(file_, 'rb'))}, {'media': (file_, open(file_, 'rb'))},
**params) **params)
@ -466,7 +468,7 @@ class Twython(object):
:param file_: (required) A string to the location of the file :param file_: (required) A string to the location of the file
:param version: (optional) A number, default 1 because that's the :param version: (optional) A number, default 1 because that's the
only API version Twitter has now only API version for Twitter that supports this call
**params - You may pass items that are taken in this doc **params - You may pass items that are taken in this doc
(https://dev.twitter.com/docs/api/1/post/account/update_profile_banner) (https://dev.twitter.com/docs/api/1/post/account/update_profile_banner)
@ -478,7 +480,7 @@ class Twython(object):
########################################################################### ###########################################################################
def getProfileImageUrl(self, username, size='normal', version='1.1'): def getProfileImageUrl(self, username, size='normal', version='1'):
"""Gets the URL for the user's profile image. """Gets the URL for the user's profile image.
:param username: (required) Username, self explanatory. :param username: (required) Username, self explanatory.
@ -487,8 +489,8 @@ class Twython(object):
mini - 24px by 24px mini - 24px by 24px
original - undefined, be careful -- images may be original - undefined, be careful -- images may be
large in bytes and/or size. large in bytes and/or size.
:param version: A number, default 1 because that's the only API :param version: (optional) A number, default 1 because that's the
version Twitter has now only API version for Twitter that supports this call
""" """
endpoint = 'users/profile_image/%s' % username endpoint = 'users/profile_image/%s' % username
url = self.api_url % version + '/' + endpoint url = self.api_url % version + '/' + endpoint