diff options
author | 2011-10-19 02:36:09 -0400 | |
---|---|---|
committer | 2011-10-19 02:36:09 -0400 | |
commit | 68ba47c4648695c2890ecdd54e6163a67f16222f (patch) | |
tree | 610b216971497b171991d13f1637fdd339bd8304 | |
parent | cache response data, update patched resources! (diff) | |
download | python-github3-68ba47c4648695c2890ecdd54e6163a67f16222f.tar.xz python-github3-68ba47c4648695c2890ecdd54e6163a67f16222f.zip |
proper requests authentication
-rw-r--r-- | github3/api.py | 32 | ||||
-rw-r--r-- | github3/core.py | 6 | ||||
-rw-r--r-- | github3/models.py | 7 | ||||
-rw-r--r-- | reqs.txt | 2 |
4 files changed, 17 insertions, 30 deletions
diff --git a/github3/api.py b/github3/api.py index 87aca4d..00a6db8 100644 --- a/github3/api.py +++ b/github3/api.py @@ -27,6 +27,8 @@ class GithubCore(object): def __init__(self): self.session = requests.session() + self.session.params = {'per_page': 100} + @staticmethod def _resource_serialize(o): @@ -57,12 +59,6 @@ class GithubCore(object): return (settings.base_url + resource) - def _requests_pre_hook(*args, **kwargs): - """Pre-processing for HTTP requests arguments.""" - - return args, kwargs - - def _requests_post_hook(self, r): """Post-processing for HTTP response objects.""" @@ -72,18 +68,18 @@ class GithubCore(object): return r - def _http_resource(self, verb, endpoint, params=None, authed=True, **etc): + def _http_resource(self, verb, endpoint, params=None, **etc): url = self._generate_url(endpoint) + # print self.session.__dict__ - if authed: - args, kwargs = self._requests_pre_hook(verb, url, params=params) - else: - args = (verb, url) - kwargs = {'params': params} + args = (verb, url) + kwargs = {'params': params} kwargs.update(etc) + print self.session.__dict__ + r = self.session.request(*args, **kwargs) r = self._requests_post_hook(r) @@ -94,23 +90,23 @@ class GithubCore(object): return r - def _get_resource(self, resource, obj, authed=True, **kwargs): + def _get_resource(self, resource, obj, **kwargs): - r = self._http_resource('GET', resource, params=kwargs, authed=authed) + r = self._http_resource('GET', resource, params=kwargs) item = self._resource_deserialize(r.content) return obj.new_from_dict(item, gh=self) - def _patch_resource(self, resource, data, authed=True, **kwargs): - r = self._http_resource('PATCH', resource, data=data, params=kwargs, authed=authed) + def _patch_resource(self, resource, data, **kwargs): + r = self._http_resource('PATCH', resource, data=data, params=kwargs) msg = self._resource_deserialize(r.content) return msg - def _get_resources(self, resource, obj, authed=True, **kwargs): + def _get_resources(self, resource, obj, **kwargs): - r = self._http_resource('GET', resource, params=kwargs, authed=authed) + r = self._http_resource('GET', resource, params=kwargs) d_items = self._resource_deserialize(r.content) items = [] diff --git a/github3/core.py b/github3/core.py index 5968ace..6221f9e 100644 --- a/github3/core.py +++ b/github3/core.py @@ -29,13 +29,9 @@ def no_auth(): def basic_auth(username, password): """Returns an authenticated Github object, via HTTP Basic.""" - def enable_auth(*args, **kwargs): - kwargs['auth'] = (username, password) - return args, kwargs - gh = Github() gh.is_authenticated = True - gh._requests_pre_hook = enable_auth + gh.session.auth = (username, password) return gh diff --git a/github3/models.py b/github3/models.py index 1e7f2b4..b95d479 100644 --- a/github3/models.py +++ b/github3/models.py @@ -59,6 +59,7 @@ class BaseResource(object): _gh = gh ) + def update(self): deploy = key_diff(self._cache, self.dict(), pack=True) @@ -69,12 +70,6 @@ class BaseResource(object): return r - - def setattr(self, k, v): - # TODO: when writable key changed, - pass - - class Plan(BaseResource): """Github Plan object model.""" @@ -1,4 +1,4 @@ -requests==0.6.4 +requests==0.6.5 python-dateutil==2.0 decorator==3.3.1 envoy==0.0.2
\ No newline at end of file |