Permalink
Browse files

Improved interaction with repository and issue fetching

  • Loading branch information...
thedjpetersen committed Aug 5, 2011
1 parent fdcdda9 commit e132972668b1fe8efe6d7c743271eb39d8d02043
Showing with 62 additions and 0 deletions.
  1. +18 −0 pygithub/core.py
  2. +4 −0 pygithub/issue.py
  3. +24 −0 pygithub/repository.py
  4. +16 −0 pygithub/url_fetch.py
View
@@ -0,0 +1,18 @@
+from url_fetch import url_open
+import repository, issue
+
+class Github:
+ def __init__(self, username, password):
+ self.username = username
+ self.password = password
+
+ def get_url(self, url):
+ return url_open(self.username, self.password, url)
+
+ def get_repository(self, repo):
+ response = self.get_url(repo)
+ return repository.repository(self, response)
+
+ def get_issue(self, issue):
+ response - self.get_url(issue)
+ return issue.issue(response)
View
@@ -0,0 +1,4 @@
+class issue:
+ def __init__(self, data):
+ self.data = data
+ self.title = data['title']
View
@@ -0,0 +1,24 @@
+import issue
+
+class repository:
+ def __init__(self, github, data):
+ self.github = github
+ self.data = data
+ self.name = data['name']
+ (self.user, self.repo) = self.data['html_url'].split('/')[3:]
+ self.issues = {}
+
+ def get_issues(self):
+ open_issues = self.data['open_issues']
+ url = '/' + '/'.join(['repos',self.user,self.repo,'issues'])
+ for x in range(open_issues/100+1):
+ x += 1
+ fetch_url = url + '?page{0}&per_age=100'.format(str(x))
+ for issue_data in self.github.get_url(fetch_url):
+ self.issues[issue_data['number']]=(issue.issue(issue_data))
+
+ def get_issue(self, number):
+ if number in self.issues:
+ return self.issues[number]
+ url = '/' + '/'.join(['repos',self.user,self.repo,'issues',str(number)])
+ return self.github.get_url(url)
View
@@ -0,0 +1,16 @@
+import urllib2
+import auth
+
+try: import simplejson as json
+except ImportError: import json
+
+def url_open(username, password, url):
+ base_url = 'https://api.github.com'
+ encoded_auth = auth.encode_auth(username, password)
+
+ fetch_url = base_url + url
+ print fetch_url
+ req = urllib2.Request(fetch_url)
+ req.add_header('Authorization', 'Basic {0}'.format(encoded_auth))
+ response = urllib2.urlopen(req)
+ return json.loads(response.read())

0 comments on commit e132972

Please sign in to comment.