Skip to content

Commit 8345cf6

Browse files
committed
remaining_requests attr to Github and Services
Updated with each request
1 parent 221aae6 commit 8345cf6

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

pygithub3/core/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
class Client(object):
1515
""" Client to send configurated requests"""
1616

17+
remaining_requests = '~'
18+
1719
def __init__(self, **kwargs):
1820
self.requester = requests.session()
1921
self.config = {
@@ -72,6 +74,8 @@ def wrapper(self, verb, request, **kwargs):
7274
def request(self, verb, request, **kwargs):
7375
request = "%s%s" % (self.config['base_url'], request)
7476
response = self.requester.request(verb, request, **kwargs)
77+
Client.remaining_requests = response.headers.get(
78+
'x-ratelimit-remaining', -1)
7579
GithubError(response).process()
7680
return response
7781

pygithub3/github.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ def __init__(self, **config):
1818
self._users = User(**config)
1919
self._repos = Repos(**config)
2020

21+
@property
22+
def remaining_requests(self):
23+
""" Limit of Github API v3 """
24+
from pygithub3.core.client import Client
25+
return Client.remaining_requests
26+
2127
@property
2228
def users(self):
2329
"""

pygithub3/services/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ def __init__(self, **config):
4141
self._client = Client(**config)
4242
self.request_builder = Factory()
4343

44+
@property
45+
def remaining_requests(self):
46+
return Client.remaining_requests
47+
4448
def get_user(self):
4549
return self._client.user
4650

0 commit comments

Comments
 (0)