Make this thing work. Closes #2. Closes #3

This commit is contained in:
Ask Solem
2009-11-13 12:31:46 +01:00
parent f6abaa5dba
commit 5e55ecb19f
7 changed files with 48 additions and 19 deletions
+3 -3
View File
@@ -41,7 +41,7 @@ by doing the following,::
Creating a request
==================
>>> from github.client import Github
>>> from github2.client import Github
>>> github = Github(username="ask", api_token=".......")
Users
@@ -89,8 +89,8 @@ Issues
List a Projects Issues
----------------------
>>> github.issues("ask/chishop", state="open")
>>> github.issues("ask/chishop", state="closed")
>>> github.issues.list("ask/chishop", state="open")
>>> github.issues.list("ask/chishop", state="closed")
View an Issue
-------------
+3
View File
@@ -19,6 +19,9 @@ class Commit(BaseData):
modified = Attribute("(If present) Datastructure representing what's "
"been modified since last commit.")
def __repr__(self):
return "<Commit: %s %s>" % (self.id, self.message[:64])
class Commits(GithubCommand):
domain = "commits"
+5 -5
View File
@@ -131,11 +131,11 @@ class BaseDataType(type):
def constructor(self, **kwargs):
for attr_name, attr_value in kwargs.items():
if attr_name not in self._meta:
raise TypeError("%s.__init__() doesn't support the "
"%s argument." % (name, attr_name))
attr = self._meta[attr_name]
setattr(self, attr_name, attr.to_python(attr_value))
attr = self._meta.get(attr_name)
if attr:
setattr(self, attr_name, attr.to_python(attr_value))
else:
setattr(self, attr_name, attr_value)
_contribute_method("__init__", constructor)
+5
View File
@@ -8,9 +8,14 @@ class Issue(BaseData):
title = Attribute("Issue title.")
user = Attribute("The username of the user that created this issue.")
state = Attribute("State of this issue. Can be ``open`` or ``closed``.")
labels = Attribute("Labels associated with this issue.")
created_at = DateAttribute("The date this issue was created.")
closed_at = DateAttribute("The date this issue was closed.")
updated_at = DateAttribute("The date when this issue was last updated.")
def __repr__(self):
return "<Issue: %s>" % self.title
class Issues(GithubCommand):
domain = "issues"
+5 -1
View File
@@ -11,6 +11,10 @@ class Repository(BaseData):
fork = Attribute("If True, this is a fork of another repository.")
owner = Attribute("Username of the user owning this repository.")
homepage = Attribute("Homepage for this project.")
open_issues = Attribute("List of open issues for this repository.")
def __repr__(self):
return "<Repository: %s/%s>" % (self.owner, self.name)
class Repositories(GithubCommand):
@@ -56,7 +60,7 @@ class Repositories(GithubCommand):
def list_collaborators(self, project):
return self.make_request("show", project, "collaborators",
filter="collaborators")
def add_collaborator(self, repo_name, username):
return self.make_request("collaborators", repo_name, "add", username)
+2 -2
View File
@@ -34,7 +34,7 @@ class GithubRequest(object):
"api_version": self.api_version,
"api_format": self.api_format,
}
def encode_authentication_data(self, extra_post_data):
post_data = {"login": self.username,
"token": self.api_token}
@@ -68,7 +68,7 @@ class GithubRequest(object):
connection = connector(resource.hostname, resource.port)
connection.request("GET", resource.path, post_data, headers)
response = connection.getresponse()
response_text = response.read().encode("utf-8")
response_text = response.read()
if self.debug:
sys.stderr.write("URL:[%s] POST_DATA:%s RESPONSE_TEXT: [%s]\n" % (
url, post_data, response_text))
+25 -8
View File
@@ -1,23 +1,40 @@
from github2.core import BaseData, GithubCommand
from github2.core import BaseData, GithubCommand, Attribute, DateAttribute
class User(BaseData):
attributes = ("id", "login", "name", "company", "location",
"email", "blog", "following_count", "followers_count",
"public_gist_count", "public_repo_count",
"total_private_repo_count", "collaborators",
"disk_usage", "owned_private_repo_count",
"private_gist_count", "plan")
id = Attribute("The user id")
login = Attribute("The login username")
name = Attribute("The users full name")
company = Attribute("Name of the company the user is associated with")
location = Attribute("Location of the user")
email = Attribute("The users e-mail address")
blog = Attribute("The users blog")
following_count = Attribute("Number of other users the user is following")
followers_count = Attribute("Number of users following this user")
public_gist_count = Attribute(
"Number of active public gists owned by the user")
public_repo_count = Attribute(
"Number of active repositories owned by the user")
total_private_repo_count = Attribute("Number of private repositories")
collaborators = Attribute("Number of collaborators")
disk_usage = Attribute("Currently used disk space")
owned_private_repo_count = Attribute("Number of privately owned repos")
private_gist_count = Attribute(
"Number of private gists owned by the user")
plan = Attribute("Current active github plan")
def is_authenticated(self):
return self.plan is not None
def __repr__(self):
return "<User: %s>" % (self.login)
class Users(GithubCommand):
domain = "user"
def search(self, query):
return self.make_request("search", query, filter="users")
return self.get_values("search", query, filter="users", datatype=User)
def show(self, username):
return self.get_value("show", username, filter="user", datatype=User)