mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
Retrieve rate limiting information
This commit is contained in:
@@ -9,6 +9,7 @@ Class `Github`
|
||||
* `get_organization( login )`: `Organization`
|
||||
* `get_gist( id )`: `Gist`
|
||||
* `get_gists()`: list of `Gist`
|
||||
* `rate_limiting`: tuple of two integers: remaining and limit, as explained in [Rate Limiting](http://developer.github.com/v3/#rate-limiting)
|
||||
|
||||
{% for class in classes|dictsort:"name" %}
|
||||
Class `{{ class.name }}`
|
||||
|
||||
@@ -8,6 +8,7 @@ Class `Github`
|
||||
* `get_organization( login )`: `Organization`
|
||||
* `get_gist( id )`: `Gist`
|
||||
* `get_gists()`: list of `Gist`
|
||||
* `rate_limiting`: tuple of two integers: remaining and limit, as explained in [Rate Limiting](http://developer.github.com/v3/#rate-limiting)
|
||||
|
||||
Class `AuthenticatedUser`
|
||||
=========================
|
||||
|
||||
@@ -6,10 +6,14 @@ import Gist
|
||||
import PaginatedList
|
||||
from GithubObject import LazyCompletion, ImmediateCompletion
|
||||
|
||||
class Github:
|
||||
class Github( object ):
|
||||
def __init__( self, login, password ):
|
||||
self.__requester = Requester( login, password )
|
||||
|
||||
@property
|
||||
def rate_limiting( self ):
|
||||
return self.__requester.rate_limiting
|
||||
|
||||
def get_user( self, login = None ):
|
||||
if login is None:
|
||||
attributes = {
|
||||
|
||||
@@ -9,6 +9,7 @@ class UnknownGithubObject( Exception ):
|
||||
class Requester:
|
||||
def __init__( self, login, password ):
|
||||
self.__authorizationHeader = "Basic " + base64.b64encode( login + ":" + password ).replace( '\n', '' )
|
||||
self.rate_limiting = ( 5000, 5000 )
|
||||
|
||||
def request( self, verb, url, parameters, input ):
|
||||
assert verb in [ "HEAD", "GET", "POST", "PATCH", "PUT", "DELETE" ]
|
||||
@@ -30,6 +31,8 @@ class Requester:
|
||||
|
||||
cnx.close()
|
||||
|
||||
self.rate_limiting = ( int( headers[ "x-ratelimit-remaining" ] ), int( headers[ "x-ratelimit-limit" ] ) )
|
||||
|
||||
# print verb, url, parameters, input, "==>", status, str( headers )[ :30 ], str( output )[ :30 ]
|
||||
return status, headers, output
|
||||
|
||||
|
||||
@@ -10,5 +10,6 @@ from MilestonesAndIssues import *
|
||||
from NamedUser import *
|
||||
from Hook import *
|
||||
from Gist import *
|
||||
from RateLimiting import *
|
||||
|
||||
Framework.main()
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
import Framework
|
||||
|
||||
class RateLimiting( Framework.TestCase ):
|
||||
def testRateLimiting( self ):
|
||||
self.assertEqual( self.g.rate_limiting, ( 5000, 5000 ) )
|
||||
self.g.get_user( "jacquev6" )
|
||||
self.assertEqual( self.g.rate_limiting, ( 4999, 5000 ) )
|
||||
@@ -0,0 +1,5 @@
|
||||
GET /users/jacquev6 {} null
|
||||
200
|
||||
[('status', '200 OK'), ('x-ratelimit-remaining', '4999'), ('content-length', '801'), ('server', 'nginx/1.0.13'), ('connection', 'keep-alive'), ('x-ratelimit-limit', '5000'), ('etag', '"8cd01ddcd0adee5501abc607e6a640b0"'), ('date', 'Mon, 21 May 2012 11:08:21 GMT'), ('content-type', 'application/json; charset=utf-8')]
|
||||
{"total_private_repos":5,"public_gists":1,"type":"User","owned_private_repos":5,"private_gists":5,"company":"Criteo","url":"https://api.github.com/users/jacquev6","gravatar_id":"b68de5ae38616c296fa345d2b9df2225","avatar_url":"https://secure.gravatar.com/avatar/b68de5ae38616c296fa345d2b9df2225?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png","plan":{"private_repos":5,"collaborators":1,"name":"micro","space":614400},"followers":13,"blog":"http://vincent-jacques.net","collaborators":0,"login":"jacquev6","email":"vincent@vincent-jacques.net","disk_usage":16812,"public_repos":11,"html_url":"https://github.com/jacquev6","name":"Vincent Jacques","hireable":false,"created_at":"2010-07-09T06:10:06Z","location":"Paris, France","id":327146,"following":24,"bio":""}
|
||||
|
||||
Reference in New Issue
Block a user