From 4a173283eb55d7405bc56c75e47e94b2eb294795 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Wed, 13 Apr 2011 19:13:24 -0400 Subject: move api --- api.py | 86 -------------------------------------------------------- github3/api.py | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+), 86 deletions(-) delete mode 100644 api.py create mode 100644 github3/api.py diff --git a/api.py b/api.py deleted file mode 100644 index 3d2bd78..0000000 --- a/api.py +++ /dev/null @@ -1,86 +0,0 @@ -# -*- coding: utf-8 -*- -""" - github3.api - ~~~~~~~~~~~ - - This module implements the GitHub3 API wrapper objects. - - :copyright: (c) 2011 by Kenneth Reitz. - :license: ISC, see LICENSE for more details. -""" - -from convore.packages.anyjson import deserialize - -import requests - -from . import models - - - -API_URL = 'https://api.github.com' -AUTH = None - -# ======= -# Helpers -# ======= - -def _safe_response(r, error=None): - try: - r.raise_for_status() - return r - except requests.HTTPError: - if r.status_code == 401: - raise LoginFailed - else: - raise APIError(error) if error else APIError - - -def get(*path, **kwargs): - """ - Accepts optional error parameter, which will be passed in the event of a - non-401 HTTP error. - - api.get('groups') - api.get('groups', 'id') - api.get('accounts', 'verify') - """ - url = '%s%s%s' % (API_URL, '/'.join(map(str, path)), '.json') - - params = kwargs.get('params', None) - - r = requests.get(url, params=params, auth=auth) - - error = kwargs.get('error', None) - return _safe_response(r, error) - - -def post(params, *path): - - url = '%s%s%s' % (API_URL, '/'.join(map(str, path)), '.json') - r = requests.post(url, params=params, auth=auth) - return _safe_response(r) - - -# ========== -# Exceptions -# ========== - -class LoginFailed(RuntimeError): - """Login falied!""" - -class APIError(RuntimeError): - """There was a problem properly accessing the Convore API.""" - - - -def login(username, password): - """Configured API Credentials""" - global auth - - auth = (username, password) - # print requests.auth_manager.__dict__ - -# ========== -# End Points -# ========== - diff --git a/github3/api.py b/github3/api.py new file mode 100644 index 0000000..c1f7687 --- /dev/null +++ b/github3/api.py @@ -0,0 +1,88 @@ +# -*- coding: utf-8 -*- +""" + github3.api + ~~~~~~~~~~~ + + This module implements the GitHub3 API wrapper objects. + + :copyright: (c) 2011 by Kenneth Reitz. + :license: ISC, see LICENSE for more details. +""" + +from . import models +from .packages.anyjson import deserialize + +import requests + + + + +API_URL = 'https://api.github.com' +API_MIME = 'application/vnd.github.v3+json' + + + + +# ======= +# Helpers +# ======= + +def _safe_response(r, error=None): + try: + r.raise_for_status() + return r + except requests.HTTPError: + if r.status_code == 401: + raise LoginFailed + else: + raise APIError(error) if error else APIError + + +def get(*path, **params): + """ + Accepts optional error parameter, which will be passed in the event of a + non-401 HTTP error. + + api.get('groups') + api.get('groups', 'id') + api.get('accounts', 'verify') + """ + url = '{0}{1}'.format(API_URL, '/'.join(map(str, path))) + + # params = kwargs.get('params', None) + + r = requests.get(url, params=params, auth=None) + + return _safe_response(r) + + +def post(params, *path): + + url = '%s%s%s' % (API_URL, '/'.join(map(str, path)), '.json') + r = requests.post(url, params=params, auth=auth) + return _safe_response(r) + + +# ========== +# Exceptions +# ========== + +class LoginFailed(RuntimeError): + """Login falied!""" + +class APIError(RuntimeError): + """There was a problem properly accessing the Convore API.""" + + + +def login(username, password): + """Configured API Credentials""" + global auth + + auth = (username, password) + # print requests.auth_manager.__dict__ + +# ========== +# End Points +# ========== + -- cgit v1.3-8-gc7d7