From 27617181b1d41ee0af3746b8f90c4159f0dcd2bd Mon Sep 17 00:00:00 2001 From: Diego Allen Date: Sun, 31 Aug 2014 23:14:49 -0400 Subject: [PATCH 01/11] Fix issue #317 TwythonRateLimitError.retry_after is always None. --- twython/api.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/twython/api.py b/twython/api.py index 3a37909..499b83b 100644 --- a/twython/api.py +++ b/twython/api.py @@ -194,8 +194,7 @@ class Twython(EndpointsMixin, object): raise ExceptionType(error_message, error_code=response.status_code, - retry_after=response.headers.get('retry-\ - after')) + retry_after=response.headers.get('X-Rate-Limit-Reset')) try: content = response.json() @@ -497,8 +496,7 @@ class Twython(EndpointsMixin, object): # Add 1 to the id because since_id and # max_id are inclusive if hasattr(function, 'iter_metadata'): - since_id = content[function.iter_metadata]\ - .get('since_id_str') + since_id = content[function.iter_metadata].get('since_id_str') else: since_id = content[0]['id_str'] params['since_id'] = (int(since_id) - 1) From f2a535b2508b9bb1f622b34d74994838af810bfe Mon Sep 17 00:00:00 2001 From: Diego Allen Date: Mon, 1 Sep 2014 09:06:07 -0400 Subject: [PATCH 02/11] Formatting fixes --- twython/api.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/twython/api.py b/twython/api.py index 499b83b..6e33904 100644 --- a/twython/api.py +++ b/twython/api.py @@ -192,9 +192,10 @@ class Twython(EndpointsMixin, object): # app keys/user tokens ExceptionType = TwythonAuthError - raise ExceptionType(error_message, - error_code=response.status_code, - retry_after=response.headers.get('X-Rate-Limit-Reset')) + raise ExceptionType( + error_message, + error_code=response.status_code, + retry_after=response.headers.get('X-Rate-Limit-Reset')) try: content = response.json() From f22dcebbbbb319aaa484e7dcf0511f367e60a7fb Mon Sep 17 00:00:00 2001 From: Renan Cakirerk Date: Fri, 19 Sep 2014 01:48:37 -0700 Subject: [PATCH 03/11] Update README.rst --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 143a277..e15e73c 100644 --- a/README.rst +++ b/README.rst @@ -137,7 +137,7 @@ Now that you have the ``oauth_verifier`` stored to a variable, you'll want to cr Once you have the final user tokens, store them in a database for later use!:: OAUTH_TOKEN = final_step['oauth_token'] - OAUTH_TOKEN_SECERT = final_step['oauth_token_secret'] + OAUTH_TOKEN_SECRET = final_step['oauth_token_secret'] For OAuth 2 (Application Only, read-only) authentication, see `our documentation `_ From 83379b42e6ba5249265a26e23cd2345a521fb21b Mon Sep 17 00:00:00 2001 From: Filipe Ximenes Date: Thu, 23 Oct 2014 12:03:33 -0300 Subject: [PATCH 04/11] adding upload media endpoint --- twython/endpoints.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/twython/endpoints.py b/twython/endpoints.py index bafdd7f..9b6fca1 100644 --- a/twython/endpoints.py +++ b/twython/endpoints.py @@ -120,6 +120,16 @@ class EndpointsMixin(object): """ return self.post('statuses/update_with_media', params=params) + def upload_media(self, **params): + """Uploads media file to Twitter servers. The file will be available to be attached + to a status for 60 minutes. To attach to a update, pass a list of returned media ids + to the 'update_status' method using the 'media_ids' param. + + Docs: + https://dev.twitter.com/rest/public/uploading-media-multiple-photos + """ + return self.post('https://upload.twitter.com/1.1/media/upload.json', params=params) + def get_oembed_tweet(self, **params): """Returns information allowing the creation of an embedded representation of a Tweet on third party sites. From 28290cd7c3b1f7f0d2b63cf912869313e9c95e29 Mon Sep 17 00:00:00 2001 From: Mertcan Mermerkaya Date: Wed, 29 Oct 2014 01:26:03 +0200 Subject: [PATCH 05/11] Update advanced_usage.rst Fixed wrong variable name in function arguments. --- docs/usage/advanced_usage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage/advanced_usage.rst b/docs/usage/advanced_usage.rst index db36301..b95cdb3 100644 --- a/docs/usage/advanced_usage.rst +++ b/docs/usage/advanced_usage.rst @@ -55,7 +55,7 @@ Posting a Status with an Editing Image # unable to be read image_io.seek(0) - twitter.update_status_with_media(media=photo, status='Check out my edited image!') + twitter.update_status_with_media(media=image_io, status='Check out my edited image!') Search Generator From 8548a312389703d02722bdde6fbfff587133a771 Mon Sep 17 00:00:00 2001 From: Mike Helmick Date: Tue, 12 Aug 2014 13:38:20 -0400 Subject: [PATCH 06/11] Changing versions, adding AUTHORS & HISTORY --- AUTHORS.rst | 11 +++++++++-- HISTORY.rst | 12 ++++++++++++ docs/conf.py | 4 ++-- setup.py | 4 ++-- twython/__init__.py | 2 +- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index 6cddac6..ab86784 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -27,7 +27,7 @@ Patches and Suggestions - `Jonathan Elsas `_, Fix for original Streaming API stub causing import errors. - `LuqueDaniel `_, Extended example code where necessary. - `Mesar Hameed `_, Commit to swap ``__getattr__`` trick for a more debuggable solution. -- `Remy DeCausemaker `_, PEP-8 contributions. +- `Remy DeCausemaker `_, PEP 8 contributions. - `mckellister `_ Twitter Spring 2012 Clean Up fixes to ``Exception`` raised by Twython (Rate Limits, etc). - `Tatz Tsuchiya `_, Fix for ``lambda`` scoping in key injection phase. - `Mohammed ALDOUB `_, Fixes for ``http/https`` access endpoints. @@ -35,7 +35,7 @@ Patches and Suggestions - `Terry Jones `_, Error cleanup and Exception processing in 2.3.0. - `Leandro Ferreira `_, Fix for double-encoding of search queries in 2.3.0. - `Chris Brown `_, Updated to use v1.1 endpoints over v1 -- `Virendra Rajput `_, Fixed unicode (json) encoding in twython.py 2.7.2. +- `Virendra Rajput `_, Fixed unicode (json) encoding in twython.py 2.7.2. - `Paul Solbach `_, fixed requirement for oauth_verifier - `Greg Nofi `_, fixed using built-in Exception attributes for storing & retrieving error message - `Jonathan Vanasco `_, Debugging support, error_code tracking, Twitter error API tracking, other fixes @@ -43,3 +43,10 @@ Patches and Suggestions - `Ruben Varela Rosa `_, Fixed search example - `Oleg Anashkin `_, streaming ``handlers`` functionality - `Luis Alberto Santana `_, Fixed issue where Twython was unnecessarily disabling compression +- `Cory Dolphin `_, Added retry_after attribute to TwythonRateLimitError +- `Natan L `_, Fixed typo in documentation +- `Cash Costello `_, Moved tests to use `responsoes`, fixed typos in documentation +- `Joe Cabrera `_, PEP 8 contributions +- `bsbkeven `_, Added `lookup_status` function to `endpoints.py` +- `drevicko `_, Added option to yield full page vs individual results in `cursor` diff --git a/HISTORY.rst b/HISTORY.rst index 1259227..4be8b5a 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,6 +3,18 @@ History ------- +3.2.0 (2014-08-xx) +++++++++++++++++++ +- PEP8'd some code +- Added `lookup_status` function to `endpoints.py` +- Added keyword argument to `cursor` to return full pages rather than individual results +- `cursor` now uses while loop rather than recursion +- Fixed issue where Twython was unnecessarily disabling compression +- Using `responses` to mock API calls in tests +- Fixed some typos in documentation +- Added retry_after attribute to TwythonRateLimitError + + 3.1.2 (2013-12-05) ++++++++++++++++++ diff --git a/docs/conf.py b/docs/conf.py index b0b98eb..a0f9ef4 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -50,9 +50,9 @@ copyright = u'2013, Ryan McGrath' # built documents. # # The short X.Y version. -version = '3.1.2' +version = '3.2.0' # The full version, including alpha/beta/rc tags. -release = '3.1.2' +release = '3.2.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/setup.py b/setup.py index e6c8e94..09ea8ec 100755 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ except ImportError: from distutils.core import setup __author__ = 'Ryan McGrath ' -__version__ = '3.1.2' +__version__ = '3.2.0' packages = [ 'twython', @@ -23,7 +23,7 @@ if sys.argv[-1] == 'publish': setup( name='twython', version=__version__, - install_requires=['requests==2.1.0', 'requests_oauthlib==0.4.0'], + install_requires=['requests2.1.0', 'requests_oauthlib==0.4.0'], author='Ryan McGrath', author_email='ryan@venodesigns.net', license=open('LICENSE').read(), diff --git a/twython/__init__.py b/twython/__init__.py index e0920a6..a79667d 100644 --- a/twython/__init__.py +++ b/twython/__init__.py @@ -19,7 +19,7 @@ Questions, comments? ryan@venodesigns.net """ __author__ = 'Ryan McGrath ' -__version__ = '3.1.2' +__version__ = '3.2.0' from .api import Twython from .streaming import TwythonStreamer From 23a0b62f2c2464d446444d98dadf466288facbcb Mon Sep 17 00:00:00 2001 From: Mike Helmick Date: Thu, 30 Oct 2014 11:07:18 -0400 Subject: [PATCH 07/11] Update AUTHORS, HISTORY, DeprecationWarning on update_status_with_media --- AUTHORS.rst | 4 ++++ HISTORY.rst | 6 ++++-- twython/endpoints.py | 9 +++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index ab86784..24bd911 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -50,3 +50,7 @@ Patches and Suggestions - `Joe Cabrera `_, PEP 8 contributions - `bsbkeven `_, Added `lookup_status` function to `endpoints.py` - `drevicko `_, Added option to yield full page vs individual results in `cursor` +- `Filipe A Ximenes `_, Added `upload_media` function to `endpoints.py` +- `Mertcan Mermerkaya `_, Fixed code example in documentation +- `Donne Martin `_, Fixed typos in `README.rst` +- `Diego Allen `_, Add missing comma in documentation code snippet diff --git a/HISTORY.rst b/HISTORY.rst index 4be8b5a..03567f4 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,8 +11,10 @@ History - `cursor` now uses while loop rather than recursion - Fixed issue where Twython was unnecessarily disabling compression - Using `responses` to mock API calls in tests -- Fixed some typos in documentation -- Added retry_after attribute to TwythonRateLimitError +- Fixed some typos in documentation +- Added `retry_after` attribute to `TwythonRateLimitError` +- Added `upload_media` method to `Twython` in favor of `update_with_media` +- Deprecating `update_with_media` per Twitter API 1.1 (https://dev.twitter.com/rest/reference/post/statuses/update_with_media) 3.1.2 (2013-12-05) diff --git a/twython/endpoints.py b/twython/endpoints.py index 9b6fca1..444a920 100644 --- a/twython/endpoints.py +++ b/twython/endpoints.py @@ -14,6 +14,10 @@ This map is organized the order functions are documented at: https://dev.twitter.com/docs/api/1.1 """ +import warnings + +from .advisory import TwythonDeprecationWarning + class EndpointsMixin(object): # Timelines @@ -118,6 +122,11 @@ class EndpointsMixin(object): https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media """ + warnings.warn( + 'This method is deprecated. You should use Twython.upload_media instead.', + TwythonDeprecationWarning, + stacklevel=2 + ) return self.post('statuses/update_with_media', params=params) def upload_media(self, **params): From e42728166095b1ad1b9fa07dfb00ce0bcf245a67 Mon Sep 17 00:00:00 2001 From: Mike Helmick Date: Thu, 30 Oct 2014 11:07:23 -0400 Subject: [PATCH 08/11] Fixes #305 --- twython/api.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/twython/api.py b/twython/api.py index 6e33904..0b421c3 100644 --- a/twython/api.py +++ b/twython/api.py @@ -9,6 +9,8 @@ Twitter Authentication, and miscellaneous methods that are useful when dealing with the Twitter API """ +import warnings + import requests from requests.auth import HTTPBasicAuth from requests_oauthlib import OAuth1, OAuth2 @@ -20,8 +22,6 @@ from .endpoints import EndpointsMixin from .exceptions import TwythonError, TwythonAuthError, TwythonRateLimitError from .helpers import _transparent_params -import warnings - warnings.simplefilter('always', TwythonDeprecationWarning) # For Python 2.7 > @@ -243,9 +243,12 @@ class Twython(EndpointsMixin, object): :rtype: dict """ + if endpoint.startswith('http://'): + raise TwythonError('api.twitter.com is restricted to SSL/TLS traffic.') + # In case they want to pass a full Twitter URL # i.e. https://api.twitter.com/1.1/search/tweets.json - if endpoint.startswith('http://') or endpoint.startswith('https://'): + if endpoint.startswith('https://'): url = endpoint else: url = '%s/%s.json' % (self.api_url % version, endpoint) From 02d1a946c19b52229b7522d1c4acf227b5aaf284 Mon Sep 17 00:00:00 2001 From: Mike Helmick Date: Thu, 30 Oct 2014 16:49:03 -0400 Subject: [PATCH 09/11] Unpin requests --- requirements.txt | 6 +++--- setup.py | 2 +- tests/test_core.py | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index 917c31a..126cbe4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ coverage==3.6.0 -requests==2.1.0 -requests_oauthlib==0.4.0 +requests>=2.1.0 +requests_oauthlib>=0.4.0 python-coveralls==2.1.0 nose-cov==1.6 -responses==0.2.0 +responses==0.3.0 diff --git a/setup.py b/setup.py index 09ea8ec..e203cc9 100755 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ if sys.argv[-1] == 'publish': setup( name='twython', version=__version__, - install_requires=['requests2.1.0', 'requests_oauthlib==0.4.0'], + install_requires=['requests>=2.1.0', 'requests_oauthlib>=0.4.0'], author='Ryan McGrath', author_email='ryan@venodesigns.net', license=open('LICENSE').read(), diff --git a/tests/test_core.py b/tests/test_core.py index 98d3a47..1aa0eea 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -262,16 +262,16 @@ class TwythonAPITestCase(unittest.TestCase): """Test getting last specific header of the last API call works""" endpoint = 'statuses/home_timeline' url = self.get_url(endpoint) - self.register_response(responses.GET, url, adding_headers={'x-rate-limit-remaining': 37}) + self.register_response(responses.GET, url, adding_headers={'x-rate-limit-remaining': '37'}) self.api.get(endpoint) value = self.api.get_lastfunction_header('x-rate-limit-remaining') - self.assertEqual(37, value) + self.assertEqual('37', value) value2 = self.api.get_lastfunction_header('does-not-exist') self.assertIsNone(value2) - value3 = self.api.get_lastfunction_header('not-there-either', 96) - self.assertEqual(96, value3) + value3 = self.api.get_lastfunction_header('not-there-either', '96') + self.assertEqual('96', value3) def test_get_lastfunction_header_should_raise_error_when_no_previous_call(self): """Test attempting to get a header when no API call was made raises a TwythonError""" @@ -286,7 +286,7 @@ class TwythonAPITestCase(unittest.TestCase): self.api.get(endpoint) - self.assertEqual(b'gzip, deflate, compress', responses.calls[0].request.headers['Accept-Encoding']) + self.assertEqual(b'gzip, deflate', responses.calls[0].request.headers['Accept-Encoding']) # Static methods def test_construct_api_url(self): From 1d383d93033976056c7afb5ea2ba101ba78770ea Mon Sep 17 00:00:00 2001 From: Mike Helmick Date: Thu, 30 Oct 2014 16:49:58 -0400 Subject: [PATCH 10/11] Update HISTORY.rst --- HISTORY.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/HISTORY.rst b/HISTORY.rst index 03567f4..4454d4c 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -15,6 +15,7 @@ History - Added `retry_after` attribute to `TwythonRateLimitError` - Added `upload_media` method to `Twython` in favor of `update_with_media` - Deprecating `update_with_media` per Twitter API 1.1 (https://dev.twitter.com/rest/reference/post/statuses/update_with_media) +- Unpin `requests` and `requests-oauthlib` in `requirements.txt` 3.1.2 (2013-12-05) From 134414c87a3aa7b26b1800c188de412aca162b87 Mon Sep 17 00:00:00 2001 From: Mike Helmick Date: Thu, 30 Oct 2014 17:05:14 -0400 Subject: [PATCH 11/11] Update HISTORY.rst --- HISTORY.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index 4454d4c..f9d129c 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -3,7 +3,7 @@ History ------- -3.2.0 (2014-08-xx) +3.2.0 (2014-10-30) ++++++++++++++++++ - PEP8'd some code - Added `lookup_status` function to `endpoints.py`