From 5e55ecb19f02dc0432d919f8fb6ab5f471e5c726 Mon Sep 17 00:00:00 2001 From: Ask Solem Date: Fri, 13 Nov 2009 12:31:46 +0100 Subject: [PATCH] Make this thing work. Closes #2. Closes #3 --- README | 6 +++--- github2/commits.py | 3 +++ github2/core.py | 10 +++++----- github2/issues.py | 5 +++++ github2/repositories.py | 6 +++++- github2/request.py | 4 ++-- github2/users.py | 33 +++++++++++++++++++++++++-------- 7 files changed, 48 insertions(+), 19 deletions(-) diff --git a/README b/README index 972b029..b48a41a 100644 --- a/README +++ b/README @@ -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 ------------- diff --git a/github2/commits.py b/github2/commits.py index cb531ee..3d4a700 100644 --- a/github2/commits.py +++ b/github2/commits.py @@ -19,6 +19,9 @@ class Commit(BaseData): modified = Attribute("(If present) Datastructure representing what's " "been modified since last commit.") + def __repr__(self): + return "" % (self.id, self.message[:64]) + class Commits(GithubCommand): domain = "commits" diff --git a/github2/core.py b/github2/core.py index fe21f31..91ce29d 100644 --- a/github2/core.py +++ b/github2/core.py @@ -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) diff --git a/github2/issues.py b/github2/issues.py index c8552c6..af1f17d 100644 --- a/github2/issues.py +++ b/github2/issues.py @@ -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 "" % self.title + class Issues(GithubCommand): domain = "issues" diff --git a/github2/repositories.py b/github2/repositories.py index ef8e88e..1a3befb 100644 --- a/github2/repositories.py +++ b/github2/repositories.py @@ -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 "" % (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) diff --git a/github2/request.py b/github2/request.py index 3fef3fd..00a09a2 100644 --- a/github2/request.py +++ b/github2/request.py @@ -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)) diff --git a/github2/users.py b/github2/users.py index c761820..863dc72 100644 --- a/github2/users.py +++ b/github2/users.py @@ -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 "" % (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)