This commit is contained in:
Kenneth Reitz
2011-04-13 19:34:50 -04:00
parent 4a173283eb
commit 9cf503801a
2 changed files with 12 additions and 3 deletions
+3 -1
View File
@@ -28,11 +28,12 @@ API_MIME = 'application/vnd.github.v3+json'
# ======= # =======
def _safe_response(r, error=None): def _safe_response(r, error=None):
try: try:
r.raise_for_status() r.raise_for_status()
return r return r
except requests.HTTPError: except requests.HTTPError:
if r.status_code == 401: if (r.status_code == 404) or (r.status_code == 401):
raise LoginFailed raise LoginFailed
else: else:
raise APIError(error) if error else APIError raise APIError(error) if error else APIError
@@ -47,6 +48,7 @@ def get(*path, **params):
api.get('groups', 'id') api.get('groups', 'id')
api.get('accounts', 'verify') api.get('accounts', 'verify')
""" """
url = '{0}{1}'.format(API_URL, '/'.join(map(str, path))) url = '{0}{1}'.format(API_URL, '/'.join(map(str, path)))
# params = kwargs.get('params', None) # params = kwargs.get('params', None)
+9 -2
View File
@@ -22,7 +22,6 @@ class GitHub(object):
def __init__(self, apiurl=API_URL): def __init__(self, apiurl=API_URL):
self.__basic_auth = None self.__basic_auth = None
return self.logged_in()
def _get(self, *path): def _get(self, *path):
r = get(*path, auth=self.__basic_auth) r = get(*path, auth=self.__basic_auth)
@@ -38,13 +37,21 @@ class GitHub(object):
def auth(self, username, password): def auth(self, username, password):
self.__basic_auth = (username, password) self.__basic_auth = (username, password)
return self.logged_in
def oauth(self): def oauth(self):
# TODO: oAuth # TODO: oAuth
pass pass
@property
def logged_in(self): def logged_in(self):
print self._get('').headers r = self._get('')
# print r
if r.status_code == 200:
return True
else:
return False