diff options
Diffstat (limited to 'github3/api.py')
-rw-r--r-- | github3/api.py | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/github3/api.py b/github3/api.py index e9eebb5..9dbe52f 100644 --- a/github3/api.py +++ b/github3/api.py @@ -10,6 +10,7 @@ from handlers import users, gists RESOURCES_PER_PAGE = 100 + class GithubCore(object): """ Wrapper to github api requests @@ -88,22 +89,21 @@ class GithubCore(object): """ Arg's parser to `_request` method - It check keyword args to parse extra request args to params - Sample: - _parse_args(arg1=1, arg2=2) => params = {'arg1': 1, 'arg2': 2} + Put extra request_args in params """ request_core = ( - 'params','data','headers','cookies','files','auth','tiemout', - 'allow_redirects','proxies','return_response','config') + 'params', 'data', 'headers', 'cookies', 'files', 'auth', 'tiemout', + 'allow_redirects', 'proxies', 'return_response', 'config') request_params = request_args.get('params') extra_params = {} for k, v in request_args.items(): - if k in request_core: continue + if k in request_core: + continue extra_params.update({k: v}) del request_args[k] - if request_params: + if request_params and getattr(request_params, 'update'): request_args['params'].update(extra_params) - else: + elif extra_params: request_args['params'] = extra_params return request_args @@ -117,15 +117,16 @@ class GithubCore(object): :param kwargs: Keyword args to request """ request = self.base_url + request - parsed_args = self._parse_args(kwargs) - response = self.session.request(verb, request, **parsed_args) + self._parse_args(kwargs) + response = self.session.request(verb, request, **kwargs) self.requests_remaining = response.headers.get( - 'x-ratelimit-remaining',-1) + 'x-ratelimit-remaining', -1) error = GithubError(response) error.process() return response + class Github(GithubCore): """ Library enter """ @@ -133,10 +134,10 @@ class Github(GithubCore): super(Github, self).__init__() self.authenticated = False auth = len(args) - if auth == 2: # Basic auth - self.session.auth = tuple(map(str,args)) + if auth == 2: # Basic auth + self.session.auth = tuple(map(str, args)) self.authenticated = True - elif auth == 1: # Token oauth + elif auth == 1: # Token oauth raise NotImplementedError elif auth > 2: raise TypeError("user, password or token") |