diff options
author | 2012-03-03 11:26:04 +0100 | |
---|---|---|
committer | 2012-03-03 11:29:56 +0100 | |
commit | 8345cf66caedf989a8b176e1ecf551bb6d9e846e (patch) | |
tree | fe629e13576b1af33a8aedc1cb3e703dea560bd9 /pygithub3 | |
parent | Service repos done (diff) | |
download | python-github3-8345cf66caedf989a8b176e1ecf551bb6d9e846e.tar.xz python-github3-8345cf66caedf989a8b176e1ecf551bb6d9e846e.zip |
remaining_requests attr to Github and Services
Updated with each request
Diffstat (limited to 'pygithub3')
-rw-r--r-- | pygithub3/core/client.py | 4 | ||||
-rw-r--r-- | pygithub3/github.py | 6 | ||||
-rw-r--r-- | pygithub3/services/base.py | 4 |
3 files changed, 14 insertions, 0 deletions
diff --git a/pygithub3/core/client.py b/pygithub3/core/client.py index a8e33a1..ee7c97f 100644 --- a/pygithub3/core/client.py +++ b/pygithub3/core/client.py @@ -14,6 +14,8 @@ VALID_REQUEST_ARGS = set(( class Client(object): """ Client to send configurated requests""" + remaining_requests = '~' + def __init__(self, **kwargs): self.requester = requests.session() self.config = { @@ -72,6 +74,8 @@ class Client(object): def request(self, verb, request, **kwargs): request = "%s%s" % (self.config['base_url'], request) response = self.requester.request(verb, request, **kwargs) + Client.remaining_requests = response.headers.get( + 'x-ratelimit-remaining', -1) GithubError(response).process() return response diff --git a/pygithub3/github.py b/pygithub3/github.py index fd1cb26..23b5b0b 100644 --- a/pygithub3/github.py +++ b/pygithub3/github.py @@ -19,6 +19,12 @@ class Github(object): self._repos = Repos(**config) @property + def remaining_requests(self): + """ Limit of Github API v3 """ + from pygithub3.core.client import Client + return Client.remaining_requests + + @property def users(self): """ :ref:`User service <User service>` diff --git a/pygithub3/services/base.py b/pygithub3/services/base.py index 84379b0..1d33470 100644 --- a/pygithub3/services/base.py +++ b/pygithub3/services/base.py @@ -41,6 +41,10 @@ class Service(object): self._client = Client(**config) self.request_builder = Factory() + @property + def remaining_requests(self): + return Client.remaining_requests + def get_user(self): return self._client.user |