Skip to content

Commit 5e55ecb

Browse files
author
Ask Solem
committed
Make this thing work. Closes #2. Closes #3
1 parent f6abaa5 commit 5e55ecb

7 files changed

Lines changed: 48 additions & 19 deletions

File tree

README

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ by doing the following,::
4141
Creating a request
4242
==================
4343

44-
>>> from github.client import Github
44+
>>> from github2.client import Github
4545
>>> github = Github(username="ask", api_token=".......")
4646

4747
Users
@@ -89,8 +89,8 @@ Issues
8989
List a Projects Issues
9090
----------------------
9191

92-
>>> github.issues("ask/chishop", state="open")
93-
>>> github.issues("ask/chishop", state="closed")
92+
>>> github.issues.list("ask/chishop", state="open")
93+
>>> github.issues.list("ask/chishop", state="closed")
9494

9595
View an Issue
9696
-------------

github2/commits.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class Commit(BaseData):
1919
modified = Attribute("(If present) Datastructure representing what's "
2020
"been modified since last commit.")
2121

22+
def __repr__(self):
23+
return "<Commit: %s %s>" % (self.id, self.message[:64])
24+
2225

2326
class Commits(GithubCommand):
2427
domain = "commits"

github2/core.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ def _contribute_method(name, func):
131131

132132
def constructor(self, **kwargs):
133133
for attr_name, attr_value in kwargs.items():
134-
if attr_name not in self._meta:
135-
raise TypeError("%s.__init__() doesn't support the "
136-
"%s argument." % (name, attr_name))
137-
attr = self._meta[attr_name]
138-
setattr(self, attr_name, attr.to_python(attr_value))
134+
attr = self._meta.get(attr_name)
135+
if attr:
136+
setattr(self, attr_name, attr.to_python(attr_value))
137+
else:
138+
setattr(self, attr_name, attr_value)
139139

140140
_contribute_method("__init__", constructor)
141141

github2/issues.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ class Issue(BaseData):
88
title = Attribute("Issue title.")
99
user = Attribute("The username of the user that created this issue.")
1010
state = Attribute("State of this issue. Can be ``open`` or ``closed``.")
11+
labels = Attribute("Labels associated with this issue.")
1112
created_at = DateAttribute("The date this issue was created.")
13+
closed_at = DateAttribute("The date this issue was closed.")
1214
updated_at = DateAttribute("The date when this issue was last updated.")
1315

16+
def __repr__(self):
17+
return "<Issue: %s>" % self.title
18+
1419

1520
class Issues(GithubCommand):
1621
domain = "issues"

github2/repositories.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class Repository(BaseData):
1111
fork = Attribute("If True, this is a fork of another repository.")
1212
owner = Attribute("Username of the user owning this repository.")
1313
homepage = Attribute("Homepage for this project.")
14+
open_issues = Attribute("List of open issues for this repository.")
15+
16+
def __repr__(self):
17+
return "<Repository: %s/%s>" % (self.owner, self.name)
1418

1519

1620
class Repositories(GithubCommand):
@@ -56,7 +60,7 @@ def set_public(self, repo_name):
5660
def list_collaborators(self, project):
5761
return self.make_request("show", project, "collaborators",
5862
filter="collaborators")
59-
63+
6064
def add_collaborator(self, repo_name, username):
6165
return self.make_request("collaborators", repo_name, "add", username)
6266

github2/request.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, username, api_token, url_prefix=None, debug=False):
3434
"api_version": self.api_version,
3535
"api_format": self.api_format,
3636
}
37-
37+
3838
def encode_authentication_data(self, extra_post_data):
3939
post_data = {"login": self.username,
4040
"token": self.api_token}
@@ -68,7 +68,7 @@ def raw_request(self, url, extra_post_data):
6868
connection = connector(resource.hostname, resource.port)
6969
connection.request("GET", resource.path, post_data, headers)
7070
response = connection.getresponse()
71-
response_text = response.read().encode("utf-8")
71+
response_text = response.read()
7272
if self.debug:
7373
sys.stderr.write("URL:[%s] POST_DATA:%s RESPONSE_TEXT: [%s]\n" % (
7474
url, post_data, response_text))

github2/users.py

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,40 @@
1-
from github2.core import BaseData, GithubCommand
1+
from github2.core import BaseData, GithubCommand, Attribute, DateAttribute
22

33

44
class User(BaseData):
5-
attributes = ("id", "login", "name", "company", "location",
6-
"email", "blog", "following_count", "followers_count",
7-
"public_gist_count", "public_repo_count",
8-
"total_private_repo_count", "collaborators",
9-
"disk_usage", "owned_private_repo_count",
10-
"private_gist_count", "plan")
5+
id = Attribute("The user id")
6+
login = Attribute("The login username")
7+
name = Attribute("The users full name")
8+
company = Attribute("Name of the company the user is associated with")
9+
location = Attribute("Location of the user")
10+
email = Attribute("The users e-mail address")
11+
blog = Attribute("The users blog")
12+
following_count = Attribute("Number of other users the user is following")
13+
followers_count = Attribute("Number of users following this user")
14+
public_gist_count = Attribute(
15+
"Number of active public gists owned by the user")
16+
public_repo_count = Attribute(
17+
"Number of active repositories owned by the user")
18+
total_private_repo_count = Attribute("Number of private repositories")
19+
collaborators = Attribute("Number of collaborators")
20+
disk_usage = Attribute("Currently used disk space")
21+
owned_private_repo_count = Attribute("Number of privately owned repos")
22+
private_gist_count = Attribute(
23+
"Number of private gists owned by the user")
24+
plan = Attribute("Current active github plan")
1125

1226
def is_authenticated(self):
1327
return self.plan is not None
1428

29+
def __repr__(self):
30+
return "<User: %s>" % (self.login)
31+
1532

1633
class Users(GithubCommand):
1734
domain = "user"
1835

1936
def search(self, query):
20-
return self.make_request("search", query, filter="users")
37+
return self.get_values("search", query, filter="users", datatype=User)
2138

2239
def show(self, username):
2340
return self.get_value("show", username, filter="user", datatype=User)

0 commit comments

Comments
 (0)