1010
1111
1212from .api import API_URL , get
13-
13+ import json
14+ import models
15+ # TODO: switch to anyjson
1416
1517
1618class GitHub (object ):
@@ -25,9 +27,14 @@ def __init__(self, apiurl=API_URL):
2527 self .__basic_auth = None
2628
2729
28- def _get (self , * path ):
30+ def _get (self , * path , ** kwargs ):
31+ """optional json=False, paged=False"""
32+
2933 headers = {'Accept' : self .accept }
3034
35+ is_json = kwargs .get ('json' , False )
36+ is_paged = kwargs .get ('paged' , False )
37+
3138 r = get (* path , auth = self .__basic_auth , headers = headers )
3239
3340 rate_left = r .headers .get ('x-ratelimit-remaining' , None )
@@ -37,6 +44,12 @@ def _get(self, *path):
3744 self .rate_limit = rate_limit
3845 self .rate_left = rate_left
3946
47+ if is_json :
48+ r = json .loads (r .content )
49+
50+ if is_paged :
51+ pass
52+ # TODO: paged support (__iter__)
4053 return r
4154
4255
@@ -61,7 +74,49 @@ def logged_in(self):
6174 else :
6275 return False
6376
64-
77+ def repo (self , username , reponame ):
78+ d = self ._get ('repos' , username , '{0}.json' .format (reponame ), json = True )
79+
80+
81+ repo = models .Repo ()
82+ repo .from_dict (d )
83+
84+ return repo
85+
86+
87+ # {
88+ # "has_downloads": true,
89+ # "forks": 10,
90+ # "url": "https://api.github.com/repos/kennethreitz/requests.json",
91+ # "created_at": "2011-02-13T18:38:17Z",
92+ # "watchers": 166,
93+ # "description": "Python HTTP modules suck. This one doesn't.",
94+ # "master_branch": "develop",
95+ # "has_wiki": true,
96+ # "open_issues": 5,
97+ # "fork": false,
98+ # "html_url": "https://github.com/kennethreitz/requests",
99+ # "homepage": "http://pypi.python.org/pypi/requests/",
100+ # "has_issues": true,
101+ # "pushed_at": "2011-04-21T21:39:45Z",
102+ # "language": "Python",
103+ # "private": false,
104+ # "size": 2748,
105+ # "integrate_branch": null,
106+ # "owner": {
107+ # "email": "_@kennethreitz.com",
108+ # "type": "User",
109+ # "url": "https://api.github.com/users/kennethreitz.json",
110+ # "login": "kennethreitz",
111+ # "created_at": "2009-08-26T21:17:47Z",
112+ # "gravatar_url": "https://secure.gravatar.com/avatar/2eccc4005572c1e2b12a9c00580bc86f?s=30&d=https://d3nwyuy0nl342s.cloudfront.net%2Fimages%2Fgravatars%2Fgravatar-140.png",
113+ # "blog": "http://kennethreitz.com",
114+ # "name": "Kenneth Reitz",
115+ # "company": "NetApp, Inc",
116+ # "location": "Washington, DC"
117+ # },
118+ # "name": "requests"
119+ # }
65120
66121# Default instance
67122github = GitHub ()
0 commit comments