Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added a `GettableModel`

  • Loading branch information...
commit e296198e73a565913558d72435d2e0bd45ad557c 1 parent ab74628
@Singletoned authored
Showing with 18 additions and 42 deletions.
  1. +18 −42 github.py
View
60 github.py
@@ -55,6 +55,21 @@ def user(self):
return user
+class GettableModel(BaseModel):
+ @classmethod
+ def get_all(cls, *args, **kwargs):
+ url = cls._get_all_url(*args, **kwargs)
+ data = _get_data(url)
+ repos = [cls(i) for i in data]
+ return repos
+
+ @classmethod
+ def get(cls, *args, **kwargs):
+ url = cls._get_url(*args, **kwargs)
+ data = _get_data(url)
+ return cls(data)
+
+
class User(BaseModel):
_keys = ['name', 'email', 'login']
@@ -71,7 +86,7 @@ def get_repo(self, name):
return Repo.get(self, name)
-class Repo(UserOwnedModel):
+class Repo(GettableModel, UserOwnedModel):
_keys = ['name', 'git_url', 'html_url', 'owner']
@staticmethod
@@ -82,19 +97,6 @@ def _get_all_url(user):
def _get_url(user, name):
return make_url("repos", user.login, name)
- @classmethod
- def get_all(cls, user):
- url = cls._get_all_url(user)
- data = _get_data(url)
- repos = [cls(r) for r in data]
- return repos
-
- @classmethod
- def get(cls, user, name):
- url = cls._get_url(user, name)
- data = _get_data(url)
- return cls(data)
-
@property
def issues(self):
return Issue.get_all(self)
@@ -110,7 +112,7 @@ def get_pull(self, number):
return Pull.get(self, number)
-class Issue(UserLinkedModel):
+class Issue(GettableModel, UserLinkedModel):
_keys = ['title']
@staticmethod
@@ -121,21 +123,8 @@ def _get_all_url(repo):
def _get_url(repo, number):
return make_url("repos", repo.user.login, repo.name, "issues", number)
- @classmethod
- def get_all(cls, repo):
- url = cls._get_all_url(repo)
- data = _get_data(url)
- issues = [cls(i) for i in data]
- return issues
-
- @classmethod
- def get(cls, repo, number):
- url = cls._get_url(repo, number)
- data = _get_data(url)
- return cls(data)
-
-class Pull(UserLinkedModel):
+class Pull(GettableModel, UserLinkedModel):
_keys = ['title']
@staticmethod
@@ -145,16 +134,3 @@ def _get_all_url(repo):
@staticmethod
def _get_url(repo, number):
return make_url("repos", repo.user.login, repo.name, "pulls", number)
-
- @classmethod
- def get_all(cls, repo):
- url = cls._get_all_url(repo)
- data = _get_data(url)
- pulls = [cls(p) for p in data]
- return pulls
-
- @classmethod
- def get(cls, repo, number):
- url = cls._get_url(repo, number)
- data = _get_data(url)
- return cls(data)
Please sign in to comment.
Something went wrong with that request. Please try again.