Cleaning up endpoints per Twitter Spring 2012 deprecations
https://dev.twitter.com/docs/deprecations/spring-2012
This commit is contained in:
parent
ac18837ed6
commit
0ee5e5877e
2 changed files with 32 additions and 44 deletions
|
|
@ -32,10 +32,6 @@ api_table = {
|
||||||
},
|
},
|
||||||
|
|
||||||
# Timeline methods
|
# Timeline methods
|
||||||
'getPublicTimeline': {
|
|
||||||
'url': '/statuses/public_timeline.json',
|
|
||||||
'method': 'GET',
|
|
||||||
},
|
|
||||||
'getHomeTimeline': {
|
'getHomeTimeline': {
|
||||||
'url': '/statuses/home_timeline.json',
|
'url': '/statuses/home_timeline.json',
|
||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
|
|
@ -44,24 +40,12 @@ api_table = {
|
||||||
'url': '/statuses/user_timeline.json',
|
'url': '/statuses/user_timeline.json',
|
||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
},
|
},
|
||||||
'getFriendsTimeline': {
|
|
||||||
'url': '/statuses/friends_timeline.json',
|
|
||||||
'method': 'GET',
|
|
||||||
},
|
|
||||||
|
|
||||||
# Interfacing with friends/followers
|
# Interfacing with friends/followers
|
||||||
'getUserMentions': {
|
'getUserMentions': {
|
||||||
'url': '/statuses/mentions.json',
|
'url': '/statuses/mentions.json',
|
||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
},
|
},
|
||||||
'getFriendsStatus': {
|
|
||||||
'url': '/statuses/friends.json',
|
|
||||||
'method': 'GET',
|
|
||||||
},
|
|
||||||
'getFollowersStatus': {
|
|
||||||
'url': '/statuses/followers.json',
|
|
||||||
'method': 'GET',
|
|
||||||
},
|
|
||||||
'createFriendship': {
|
'createFriendship': {
|
||||||
'url': '/friendships/create.json',
|
'url': '/friendships/create.json',
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
|
|
@ -126,7 +110,7 @@ api_table = {
|
||||||
|
|
||||||
# Status methods - showing, updating, destroying, etc.
|
# Status methods - showing, updating, destroying, etc.
|
||||||
'showStatus': {
|
'showStatus': {
|
||||||
'url': '/statuses/show/{{id}}.json',
|
'url': '/statuses/show.json',
|
||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
},
|
},
|
||||||
'updateStatus': {
|
'updateStatus': {
|
||||||
|
|
@ -254,60 +238,64 @@ api_table = {
|
||||||
|
|
||||||
# List API methods/endpoints. Fairly exhaustive and annoying in general. ;P
|
# List API methods/endpoints. Fairly exhaustive and annoying in general. ;P
|
||||||
'createList': {
|
'createList': {
|
||||||
'url': '/{{username}}/lists.json',
|
'url': '/lists/create.json',
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
},
|
},
|
||||||
'updateList': {
|
'updateList': {
|
||||||
'url': '/{{username}}/lists/{{list_id}}.json',
|
'url': '/lists/update.json',
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
},
|
},
|
||||||
'showLists': {
|
'showLists': {
|
||||||
'url': '/{{username}}/lists.json',
|
'url': '/lists.json',
|
||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
},
|
},
|
||||||
'getListMemberships': {
|
'getListMemberships': {
|
||||||
'url': '/{{username}}/lists/memberships.json',
|
'url': '/lists/memberships.json',
|
||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
},
|
},
|
||||||
'getListSubscriptions': {
|
'getListSubscriptions': {
|
||||||
'url': '/{{username}}/lists/subscriptions.json',
|
'url': '/lists/subscriptions.json',
|
||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
},
|
},
|
||||||
'deleteList': {
|
'deleteList': {
|
||||||
'url': '/{{username}}/lists/{{list_id}}.json',
|
'url': '/lists/destroy.json',
|
||||||
'method': 'DELETE',
|
'method': 'POST',
|
||||||
},
|
},
|
||||||
'getListTimeline': {
|
'getListTimeline': {
|
||||||
'url': '/{{username}}/lists/{{list_id}}/statuses.json',
|
'url': '/{{username}}/lists/{{list_id}}/statuses.json',
|
||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
},
|
},
|
||||||
'getSpecificList': {
|
'getSpecificList': {
|
||||||
'url': '/{{username}}/lists/{{list_id}}/statuses.json',
|
'url': '/lists/show.json',
|
||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
},
|
},
|
||||||
|
'getListStatuses': {
|
||||||
|
'url': '/lists/statuses.json',
|
||||||
|
'method': 'GET'
|
||||||
|
},
|
||||||
'addListMember': {
|
'addListMember': {
|
||||||
'url': '/{{username}}/{{list_id}}/members.json',
|
'url': '/lists/members/create.json',
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
},
|
},
|
||||||
'getListMembers': {
|
'getListMembers': {
|
||||||
'url': '/{{username}}/{{list_id}}/members.json',
|
'url': '/lists/members.json',
|
||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
},
|
},
|
||||||
'deleteListMember': {
|
'deleteListMember': {
|
||||||
'url': '/{{username}}/{{list_id}}/members.json',
|
'url': '/lists/members/destroy.json',
|
||||||
'method': 'DELETE',
|
'method': 'POST',
|
||||||
},
|
},
|
||||||
'getListSubscribers': {
|
'getListSubscribers': {
|
||||||
'url': '/{{username}}/{{list_id}}/subscribers.json',
|
'url': '/lists/subscribers.json',
|
||||||
'method': 'GET',
|
'method': 'GET',
|
||||||
},
|
},
|
||||||
'subscribeToList': {
|
'subscribeToList': {
|
||||||
'url': '/{{username}}/{{list_id}}/subscribers.json',
|
'url': '/lists/subscribers/create.json',
|
||||||
'method': 'POST',
|
'method': 'POST',
|
||||||
},
|
},
|
||||||
'unsubscribeFromList': {
|
'unsubscribeFromList': {
|
||||||
'url': '/{{username}}/{{list_id}}/subscribers.json',
|
'url': '/lists/subscribers/destroy.json',
|
||||||
'method': 'DELETE',
|
'method': 'POST',
|
||||||
},
|
},
|
||||||
|
|
||||||
# The one-offs
|
# The one-offs
|
||||||
|
|
|
||||||
|
|
@ -68,7 +68,7 @@ class TwythonError(AttributeError):
|
||||||
twitter_http_status_codes[error_code][1],
|
twitter_http_status_codes[error_code][1],
|
||||||
self.msg)
|
self.msg)
|
||||||
|
|
||||||
if error_code == 400 or error_code == 420:
|
if error_code == 420:
|
||||||
raise TwythonRateLimitError(self.msg,
|
raise TwythonRateLimitError(self.msg,
|
||||||
error_code,
|
error_code,
|
||||||
retry_after=retry_after)
|
retry_after=retry_after)
|
||||||
|
|
@ -94,9 +94,9 @@ class TwythonRateLimitError(TwythonError):
|
||||||
retry_wait_seconds is the number of seconds to wait before trying again.
|
retry_wait_seconds is the number of seconds to wait before trying again.
|
||||||
"""
|
"""
|
||||||
def __init__(self, msg, error_code, retry_after=None):
|
def __init__(self, msg, error_code, retry_after=None):
|
||||||
|
if isinstance(retry_after, int):
|
||||||
retry_after = int(retry_after)
|
retry_after = int(retry_after)
|
||||||
self.msg = '%s (Retry after %s seconds)' % (msg, retry_after)
|
self.msg = '%s (Retry after %s seconds)' % (msg, retry_after)
|
||||||
TwythonError.__init__(self, msg, error_code)
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return repr(self.msg)
|
return repr(self.msg)
|
||||||
|
|
@ -175,11 +175,11 @@ class Twython(object):
|
||||||
OAuthHook.consumer_secret = twitter_secret
|
OAuthHook.consumer_secret = twitter_secret
|
||||||
|
|
||||||
# Needed for hitting that there API.
|
# Needed for hitting that there API.
|
||||||
self.request_token_url = 'https://twitter.com/oauth/request_token'
|
self.api_url = 'https://api.twitter.com/%s'
|
||||||
self.access_token_url = 'https://twitter.com/oauth/access_token'
|
self.request_token_url = self.api_url % 'oauth/request_token'
|
||||||
self.authorize_url = 'https://twitter.com/oauth/authorize'
|
self.access_token_url = self.api_url % 'oauth/access_token'
|
||||||
self.authenticate_url = 'https://twitter.com/oauth/authenticate'
|
self.authorize_url = self.api_url % 'oauth/authorize'
|
||||||
self.api_url = 'https://api.twitter.com/%s/'
|
self.authenticate_url = self.api_url % 'oauth/authenticate'
|
||||||
|
|
||||||
self.twitter_token = twitter_token
|
self.twitter_token = twitter_token
|
||||||
self.twitter_secret = twitter_secret
|
self.twitter_secret = twitter_secret
|
||||||
|
|
@ -299,7 +299,7 @@ class Twython(object):
|
||||||
if endpoint.startswith('http://') or endpoint.startswith('https://'):
|
if endpoint.startswith('http://') or endpoint.startswith('https://'):
|
||||||
url = endpoint
|
url = endpoint
|
||||||
else:
|
else:
|
||||||
url = '%s%s.json' % (self.api_url % version, endpoint)
|
url = '%s/%s.json' % (self.api_url % version, endpoint)
|
||||||
|
|
||||||
content = self._request(url, method=method, params=params, api_call=url)
|
content = self._request(url, method=method, params=params, api_call=url)
|
||||||
|
|
||||||
|
|
@ -694,7 +694,7 @@ class Twython(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
endpoint = 'users/profile_image/%s' % username
|
endpoint = 'users/profile_image/%s' % username
|
||||||
url = self.api_url % version + endpoint + '?' + urllib.urlencode({'size': size})
|
url = self.api_url % version + '/' + endpoint + '?' + urllib.urlencode({'size': size})
|
||||||
|
|
||||||
response = self.client.get(url, allow_redirects=False)
|
response = self.client.get(url, allow_redirects=False)
|
||||||
image_url = response.headers.get('location')
|
image_url = response.headers.get('location')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue