diff --git a/CHANGES.rst b/CHANGES.rst index ea685be03..d0ef1a67d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,14 @@ Change Log ========== +Unreleased +---------- + +**Added** + +* ``reset_timestamp`` to :attr:`.limits` to provide insight into when the + current rate limit window will expire. + 4.3.0 (2017/01/19) ------------------ diff --git a/praw/models/auth.py b/praw/models/auth.py index b646f4858..01931714b 100644 --- a/praw/models/auth.py +++ b/praw/models/auth.py @@ -17,15 +17,23 @@ def limits(self): :remaining: The number of requests remaining to be made in the current rate limit window. + :reset_timestamp: A unix timestamp providing an upper bound on when the + rate limit counters will reset. :used: The number of requests made in the current rate limit window. - Both values are initially ``None`` as these values are set in response + All values are initially ``None`` as these values are set in response to issued requests. + The ``reset_timestamp`` value is an upper bound as the real timestamp + is computed on Reddit's end in preparation for sending the + response. This value may change slightly within a given window due to + slight changes in response times and rounding. + """ data = self._reddit._core._rate_limiter - return {'remaining': data.remaining, 'used': data.used} + return {'remaining': data.remaining, + 'reset_timestamp': data.reset_timestamp, 'used': data.used} def authorize(self, code): """Complete the web authorization flow and return the refresh token. diff --git a/setup.py b/setup.py index e76a916f3..3e791045f 100644 --- a/setup.py +++ b/setup.py @@ -37,7 +37,7 @@ description=('PRAW, an acronym for `Python Reddit API Wrapper`, is a ' 'python package that allows for simple access to ' 'reddit\'s API.'), - install_requires=['prawcore >=0.7.0, <0.8', + install_requires=['prawcore >=0.8.0, <0.9', 'update_checker >=0.16'], keywords='reddit api wrapper', license='Simplified BSD License', diff --git a/tests/unit/models/test_auth.py b/tests/unit/models/test_auth.py index 163687b16..284d8eb45 100644 --- a/tests/unit/models/test_auth.py +++ b/tests/unit/models/test_auth.py @@ -36,8 +36,9 @@ def test_implicit__from_script_app(self): script_app().auth.implicit('dummy token', 10, '') def test_limits(self): + expected = {'remaining': None, 'reset_timestamp': None, 'used': None} for app in [installed_app(), script_app(), web_app()]: - assert {'remaining': None, 'used': None} == app.auth.limits + assert expected == app.auth.limits def test_url__installed_app(self): url = installed_app().auth.url(['dummy scope'], 'dummy state')