Skip to content

Commit

Permalink
Add reset_timestamp to reddit.auth.limits
Browse files Browse the repository at this point in the history
  • Loading branch information
bboe committed Jan 29, 2017
1 parent caf07b1 commit e3cd25c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
8 changes: 8 additions & 0 deletions 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)
------------------

Expand Down
12 changes: 10 additions & 2 deletions praw/models/auth.py
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/models/test_auth.py
Expand Up @@ -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')
Expand Down

0 comments on commit e3cd25c

Please sign in to comment.