oauth_verifier required, remove simplejson dependency, update endpoint

* Update `updateProfileBannerImage` to use the v1.1 endpoint

* Added `getProfileBannerSizes` method using the GET
/users/profile_banner.json endpoint

* Fixed a couple of endpoints using variable in the url:
  * destroyDirectMessage, createBlock, destroyBlock no longer use id in
their urls, this shouldn't break anything though.
(t.destroyDirectMessage(id=123) should still work)

* `oauth_verifier` is now **required** when calling
`get_authorized_tokens`

* Updated docs - removed getProfileImageUrl docs since it is
deprecated. Noted since `Twython` 2.7.0 that users should focus on
migrating to v1.1 endpoints since Twitter is deprecating v1 endpoints
in May!,
This commit is contained in:
Mike Helmick 2013-04-08 11:49:12 -04:00
parent 4d7526efc1
commit abaa3e558a
5 changed files with 27 additions and 46 deletions

View file

@ -9,7 +9,7 @@
will be replaced with the keyword that gets passed in to the function at call time.
i.e, in this case, if I pass version = 47 to any function, {{version}} will be replaced
with 47, instead of defaulting to 1 (said defaulting takes place at conversion time).
with 47, instead of defaulting to 1.1 (said defaulting takes place at conversion time).
This map is organized the order functions are documented at:
https://dev.twitter.com/docs/api/1.1
@ -87,7 +87,7 @@ api_table = {
'method': 'GET',
},
'destroyDirectMessage': {
'url': '/direct_messages/destroy/{{id}}.json',
'url': '/direct_messages/destroy.json',
'method': 'POST',
},
'sendDirectMessage': {
@ -183,11 +183,11 @@ api_table = {
'method': 'GET',
},
'createBlock': {
'url': '/blocks/create/{{id}}.json',
'url': '/blocks/create.json',
'method': 'POST',
},
'destroyBlock': {
'url': '/blocks/destroy/{{id}}.json',
'url': '/blocks/destroy.json',
'method': 'POST',
},
'lookupUser': {
@ -215,6 +215,10 @@ api_table = {
'method': 'POST',
},
# See twython.py for update_profile_banner
'getProfileBannerSizes': {
'url': '/users/profile_banner.json',
'method': 'GET',
},
# Suggested Users

View file

@ -26,17 +26,9 @@ except ImportError:
from twitter_endpoints import base_url, api_table, twitter_http_status_codes
try:
import simplejson
import simplejson as json
except ImportError:
try:
# Python 2.6 and up
import json as simplejson
except ImportError:
try:
from django.utils import simplejson
except:
# Seriously wtf is wrong with you if you get this Exception.
raise Exception("Twython requires the simplejson library (or Python 2.6) to work. http://www.undefined.org/python/")
import json
class TwythonError(Exception):
@ -194,7 +186,7 @@ class Twython(object):
# why? twitter will return invalid json with an error code in the headers
json_error = False
try:
content = simplejson.loads(content)
content = content.json()
except ValueError:
json_error = True
content = {}
@ -437,13 +429,13 @@ class Twython(object):
**params - You may pass items that are taken in this doc
(https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media)
"""
subdomain = 'upload' if version == '1' else 'api'
url = 'https://%s.twitter.com/%s/statuses/update_with_media.json' % (subdomain, version)
url = 'https://api.twitter.com/%s/statuses/update_with_media.json' % version
return self._media_update(url,
{'media': (file_, open(file_, 'rb'))},
**params)
def updateProfileBannerImage(self, file_, version=1, **params):
def updateProfileBannerImage(self, file_, version='1.1', **params):
"""Updates the users profile banner
:param file_: (required) A string to the location of the file
@ -453,7 +445,7 @@ class Twython(object):
**params - You may pass items that are taken in this doc
(https://dev.twitter.com/docs/api/1/post/account/update_profile_banner)
"""
url = 'https://api.twitter.com/%d/account/update_profile_banner.json' % version
url = 'https://api.twitter.com/%s/account/update_profile_banner.json' % version
return self._media_update(url,
{'banner': (file_, open(file_, 'rb'))},
**params)
@ -518,7 +510,7 @@ class Twython(object):
for line in stream.iter_lines():
if line:
try:
callback(simplejson.loads(line))
callback(json.loads(line))
except ValueError:
raise TwythonError('Response was not valid JSON, unable to decode.')