Author: Maximillian Dornseif <m.dornseif@hudora.de>

Date:   Thu Dec 31 18:42:07 2009 +0100

    Add authentiation for GET requests.

    This for example allows you to list private repositories:

        >>> from github2.client import Github
        >>> github = Github(username="company", api_token="2e66a5c7e24d1d066230f368ce8b094e")
        >>> repos = github.repos.list("company")

    `repos` now contains a list of public and private repositories of "company".
This commit is contained in:
Maximillian Dornseif
2009-12-31 19:02:02 +01:00
parent af679985b2
commit b8463cc8df
2 changed files with 12 additions and 6 deletions
+1 -1
View File
@@ -2,6 +2,6 @@ VERSION = (0, 1, 1)
__doc__ = "Github API v2 library for Python"
__author__ = "Ask Solem"
__contact__ = "askh@opera.com"
__homepage__ = "http://github.com/ask/pygithub-issues"
__homepage__ = "http://github.com/ask/python-github2"
__version__ = ".".join(map(str, VERSION))
+11 -5
View File
@@ -1,7 +1,7 @@
import sys
import httplib
import simplejson
from urlparse import urlparse
from urlparse import urlparse, parse_qs, urlunparse
from urllib import urlencode
GITHUB_URL = "http://github.com"
@@ -57,6 +57,8 @@ class GithubRequest(object):
def raw_request(self, url, extra_post_data, method="GET"):
resource = urlparse(url)
scheme, netloc, path, params, query, fragment = urlparse(url)
hostname = netloc.split(':')[0]
post_data = None
headers = self.http_headers
headers["Accept"] = "text/html"
@@ -64,14 +66,18 @@ class GithubRequest(object):
if extra_post_data or method == "POST":
post_data = self.encode_authentication_data(extra_post_data)
headers["Content-Length"] = str(len(post_data))
connector = self.connector_for_scheme[resource.scheme]
connection = connector(resource.hostname, resource.port)
connection.request(method, resource.path, post_data, headers)
else:
path = urlunparse((scheme, netloc, path, params,
self.encode_authentication_data(parse_qs(query)),
fragment))
connector = self.connector_for_scheme[scheme]
connection = connector(hostname)
connection.request(method, path, post_data, headers)
response = connection.getresponse()
response_text = response.read()
if self.debug:
sys.stderr.write("URL:[%s] POST_DATA:%s RESPONSE_TEXT: [%s]\n" % (
url, post_data, response_text))
path, post_data, response_text))
json = simplejson.loads(response_text)
if json.get("error"):
raise self.GithubError(json["error"][0]["error"])