diff --git a/README.markdown b/README.markdown index bb8631f..7775ef4 100644 --- a/README.markdown +++ b/README.markdown @@ -49,7 +49,25 @@ Example Use # More function definitions can be found by reading over twython/twitter_endpoints.py, as well # as skimming the source file. Both are kept human-readable, and are pretty well documented or # very self documenting. + + Twython is now implemented using requests(http://python-requests.org). + from twythonrequests import Twython + twitter = Twython() + results = twitter.search(q='python') + + # All the functions of twython is supported in twythonrequests. + Note: + Don't do this + from twython import Twython + from twythonrequests import Twython + + instead try this + import twython + import twythonrequests + + since you can hack both twython features. + A note about the development of Twython (specifically, 1.3) ---------------------------------------------------------------------------------------------------- As of version 1.3, Twython has been extensively overhauled. Most API endpoint definitions are stored diff --git a/README.txt b/README.txt index 6eb928f..e801f15 100644 --- a/README.txt +++ b/README.txt @@ -49,7 +49,24 @@ Example Use # More function definitions can be found by reading over twython/twitter_endpoints.py, as well # as skimming the source file. Both are kept human-readable, and are pretty well documented or # very self documenting. - + Twython is now implemented using requests(http://python-requests.org). + from twythonrequests import Twython + + twitter = Twython() + results = twitter.search(q='python') + + # All the functions of twython is supported in twythonrequests. + Note: + Don't do this + from twython import Twython + from twythonrequests import Twython + + instead try this + import twython + import twythonrequests + +since you can hack both twython features. + A note about the development of Twython (specifically, 1.3) ---------------------------------------------------------------------------------------------------- As of version 1.3, Twython has been extensively overhauled. Most API endpoint definitions are stored diff --git a/setup.py b/setup.py index 7618ec2..13b5b9e 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,8 @@ setup( include_package_data = True, # Package dependencies. - install_requires = ['simplejson', 'oauth2', 'httplib2'], + install_requires = ['simplejson', 'oauth2', 'httplib2', 'requests', + 'oauth_hook'], # Metadata for PyPI. author = 'Ryan McGrath', diff --git a/twython/tests.py b/twython/tests.py index dc3b766..dad116b 100644 --- a/twython/tests.py +++ b/twython/tests.py @@ -5,13 +5,20 @@ import json import requests import twythonrequests +twitter = twythonrequests.Twython() class TestTwythonRequests(unittest.TestCase): def test_search(self): - twitter = twythonrequests.Twython() result = twitter.search(q='python') self.assertTrue(result['results']) + def test_searchTwitter(self): + result = twitter.searchTwitter(q='python') + self.assertTrue(result['results']) + + def test_getProfileImageUrl(self): + result = twitter.getProfileImageUrl(username='kracetheking') + self.assertTrue(result) if __name__ == "__main__": unittest.main() diff --git a/twython/twythonrequests.py b/twython/twythonrequests.py index bd0bf03..e7a2fb8 100644 --- a/twython/twythonrequests.py +++ b/twython/twythonrequests.py @@ -18,10 +18,6 @@ __version__ = "0.0.1" requests supports 2.5 and above and no support for 3.x. """ -import mimetypes -import mimetools -import re -import inspect from urlparse import parse_qs from urllib2 import HTTPError try: @@ -446,15 +442,15 @@ class Twython(object): url = "http://api.twitter.com/%s/users/profile_image/%s.json"%\ (version, username) try: - self.response = requests.post(url, size=size) - self.raise_for_status() + self.response = requests.get(url, data={'size': size}) if self.response.status_code in (301, 302, 303, 307): - return self.response['location'] - else: - return json.loads(self.response.content) - except: - return TwythonError("getProfileIMageUrl() failed with %d \ - error code"% self.response.status_code) + return self.response.headers['location'] + elif self.response.status_code == 200: + return self.response.url + self.raise_for_status() + except HTTPError, e: + raise TwythonError("getProfileIMageUrl() failed with %d \ + error code"% `e.code`, e.code) @staticmethod def unicode2utf8(text):