aboutsummaryrefslogtreecommitdiffstats
path: root/github3/core.py
diff options
context:
space:
mode:
authorKenneth Reitz <me@kennethreitz.com>2011-04-24 21:32:05 -0400
committerKenneth Reitz <me@kennethreitz.com>2011-04-24 21:32:05 -0400
commit2b8fa24053877e37ccf362476d5fd58d47ed9753 (patch)
treecae50de13f21cca5ecadef31f54612afffad77e0 /github3/core.py
parentmodel improvements (diff)
downloadpython-github3-2b8fa24053877e37ccf362476d5fd58d47ed9753.tar.xz
python-github3-2b8fa24053877e37ccf362476d5fd58d47ed9753.zip
repo api works :)
Diffstat (limited to 'github3/core.py')
-rw-r--r--github3/core.py61
1 files changed, 58 insertions, 3 deletions
diff --git a/github3/core.py b/github3/core.py
index db8b213..73bbea2 100644
--- a/github3/core.py
+++ b/github3/core.py
@@ -10,7 +10,9 @@ This module contains the core GitHub 3 interface.
from .api import API_URL, get
-
+import json
+import models
+# TODO: switch to anyjson
class GitHub(object):
@@ -25,9 +27,14 @@ class GitHub(object):
self.__basic_auth = None
- def _get(self, *path):
+ def _get(self, *path, **kwargs):
+ """optional json=False, paged=False"""
+
headers = {'Accept': self.accept}
+ is_json = kwargs.get('json', False)
+ is_paged = kwargs.get('paged', False)
+
r = get(*path, auth=self.__basic_auth, headers=headers)
rate_left = r.headers.get('x-ratelimit-remaining', None)
@@ -37,6 +44,12 @@ class GitHub(object):
self.rate_limit = rate_limit
self.rate_left = rate_left
+ if is_json:
+ r = json.loads(r.content)
+
+ if is_paged:
+ pass
+ # TODO: paged support (__iter__)
return r
@@ -61,7 +74,49 @@ class GitHub(object):
else:
return False
-
+ def repo(self, username, reponame):
+ d = self._get('repos', username, '{0}.json'.format(reponame), json=True)
+
+
+ repo = models.Repo()
+ repo.from_dict(d)
+
+ return repo
+
+
+# {
+# "has_downloads": true,
+# "forks": 10,
+# "url": "https://api.github.com/repos/kennethreitz/requests.json",
+# "created_at": "2011-02-13T18:38:17Z",
+# "watchers": 166,
+# "description": "Python HTTP modules suck. This one doesn't.",
+# "master_branch": "develop",
+# "has_wiki": true,
+# "open_issues": 5,
+# "fork": false,
+# "html_url": "https://github.com/kennethreitz/requests",
+# "homepage": "http://pypi.python.org/pypi/requests/",
+# "has_issues": true,
+# "pushed_at": "2011-04-21T21:39:45Z",
+# "language": "Python",
+# "private": false,
+# "size": 2748,
+# "integrate_branch": null,
+# "owner": {
+# "email": "_@kennethreitz.com",
+# "type": "User",
+# "url": "https://api.github.com/users/kennethreitz.json",
+# "login": "kennethreitz",
+# "created_at": "2009-08-26T21:17:47Z",
+# "gravatar_url": "https://secure.gravatar.com/avatar/2eccc4005572c1e2b12a9c00580bc86f?s=30&d=https://d3nwyuy0nl342s.cloudfront.net%2Fimages%2Fgravatars%2Fgravatar-140.png",
+# "blog": "http://kennethreitz.com",
+# "name": "Kenneth Reitz",
+# "company": "NetApp, Inc",
+# "location": "Washington, DC"
+# },
+# "name": "requests"
+# }
# Default instance
github = GitHub() \ No newline at end of file