diff options
author | 2011-06-23 02:59:49 -0400 | |
---|---|---|
committer | 2011-06-23 02:59:49 -0400 | |
commit | ecad4a9e256a10208b5e97d66f88416fecdf9cb3 (patch) | |
tree | 9c8922645118812cb2c3dd7bce57b46cb78f6a66 /github3/api.py | |
parent | clean slate (diff) | |
download | python-github3-ecad4a9e256a10208b5e97d66f88416fecdf9cb3.tar.xz python-github3-ecad4a9e256a10208b5e97d66f88416fecdf9cb3.zip |
updates
Diffstat (limited to 'github3/api.py')
-rw-r--r-- | github3/api.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/github3/api.py b/github3/api.py index 8d2361d..b8b7617 100644 --- a/github3/api.py +++ b/github3/api.py @@ -10,3 +10,79 @@ This module implements the GitHub3 API wrapper objects. """ +import urllib + + +from .config import settings +from .helpers import is_collection +from .packages import omnijson as json + + +class GithubCore(object): + """The main GitHub API Interface.""" + + def __init__(self): + self.username = None + self._auth = None + + + @staticmethod + def _resource_serialize(o): + """Returns JSON serialization of given object.""" + return json.dumps(o) + + + @staticmethod + def _resource_deserialize(s): + """Returns dict deserialization of a given JSON string.""" + + try: + return json.loads(s) + except ValueError: + raise ResponseError('The API Response was not valid.') + + + def _generate_url(self, resource, params): + """Generates Readability API Resource URL.""" + + if is_collection(resource): + resource = map(str, resource) + resource = '/'.join(resource) + + if params: + resource += '?%s' % (urllib.urlencode(params)) + + return settings.domain + '/' + resource + + +class Github(GithubCore): + """The user-facing GitHub API Interface.""" + + def __init__(self): + super(Github, self).__init__() + + +# ---------- +# Exceptions +# ---------- + +class APIError(Exception): + """There was an API Error.""" + +class PermissionsError(APIError): + """You do not have proper permission.""" + +class AuthenticationError(APIError): + """Authentication failed.""" + +class ResponseError(APIError): + """The API Response was unexpected.""" + +class MissingError(APIError): + """The Resource does not exist.""" + +class BadRequestError(APIError): + """The request could not be understood due to bad syntax. Check your request and try again.""" + +class ServerError(APIError): + """The server encountered an error and was unable to complete your request."""
\ No newline at end of file |