diff options
author | 2011-11-09 00:35:13 +0100 | |
---|---|---|
committer | 2011-11-09 00:35:13 +0100 | |
commit | ed34830ab64837d16b2943887045a44f0760ee8e (patch) | |
tree | f91c1bebb8b11cccc5bab07dfb54ea5031923888 /github3/models | |
parent | Fix/update typo. avatar_url in User (diff) | |
download | python-github3-ed34830ab64837d16b2943887045a44f0760ee8e.tar.xz python-github3-ed34830ab64837d16b2943887045a44f0760ee8e.zip |
New design. Merge develop branch
Diffstat (limited to 'github3/models')
-rw-r--r-- | github3/models/__init__.py | 4 | ||||
-rw-r--r-- | github3/models/base.py | 19 | ||||
-rw-r--r-- | github3/models/gists.py | 77 | ||||
-rw-r--r-- | github3/models/orgs.py | 25 | ||||
-rw-r--r-- | github3/models/repos.py | 31 | ||||
-rw-r--r-- | github3/models/user.py | 65 |
6 files changed, 221 insertions, 0 deletions
diff --git a/github3/models/__init__.py b/github3/models/__init__.py new file mode 100644 index 0000000..ff0c28a --- /dev/null +++ b/github3/models/__init__.py @@ -0,0 +1,4 @@ +from .user import AuthUser, User, Key +from .repos import Repo +from .orgs import Org +from .gists import Gist diff --git a/github3/models/base.py b/github3/models/base.py new file mode 100644 index 0000000..df0c82b --- /dev/null +++ b/github3/models/base.py @@ -0,0 +1,19 @@ +""" +github3.models +~~~~~~~~~~~~~~ + +This package provides the Github3 object model. +""" + +class BaseResource(object): + """A BaseResource object.""" + + def __init__(self, attrs=None): + if attrs: + for attr, value in attrs.items(): + setattr(self, attr, value) + super(BaseResource, self).__init__() + + @classmethod + def idl(self): + raise NotImplementedError('Each model need subcass that method') diff --git a/github3/models/gists.py b/github3/models/gists.py new file mode 100644 index 0000000..d1b416d --- /dev/null +++ b/github3/models/gists.py @@ -0,0 +1,77 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- +# +# author: David Medina + +from .base import BaseResource +from .user import User + +class File(BaseResource): + """ File model """ + + @classmethod + def idl(self): + return { + 'strs': ['filename', 'raw_url', 'content', 'language', 'type'], + 'ints': ['size'], + } + + def __repr__(self): + return '<File gist> %s' % self.filename + +class GistFork(BaseResource): + """ GistFork model """ + + @classmethod + def idl(self): + return { + 'strs': ['url'], + 'dates': ['created_at'], + 'maps': {'user': User} + } + + def __repr__(self): + return '<Gist fork> %s>' % self.user.login + +class ChangeStatus(BaseResource): + """ ChangeStatus model """ + + @classmethod + def idl(self): + return { + 'ints': ['deletions', 'additions', 'total'], + } + + def __repr__(self): + return '<Gist history> change_status>' + +class GistHistory(BaseResource): + """ """ + + @classmethod + def idl(self): + return { + 'strs': ['url', 'version'], + 'maps': {'user': User, 'change_status': ChangeStatus}, + 'dates': ['committed_at'], + } + + def __repr__(self): + return '<GistHistory %s/%s>' % (self.user, self.committed_at) + +class Gist(BaseResource): + """ """ + + @classmethod + def idl(self): + return { + 'strs': ['url', 'description', 'html_url', 'git_pull_url', 'git_push_url'], + 'ints': ['id', 'comments'], + 'bools': ['public'], + 'dates': ['created_at'], + 'maps': {'user': User}, + 'collection_maps': {'files': File, 'forks': GistFork, 'history': GistHistory}, + } + + def __repr__(self): + return '<Gist %s/%s>' % (self.user, self.description) diff --git a/github3/models/orgs.py b/github3/models/orgs.py new file mode 100644 index 0000000..840b51a --- /dev/null +++ b/github3/models/orgs.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- +# +# author: David Medina + +from .base import BaseResource +from .user import Plan + +class Org(BaseResource): + """Github Organization object model.""" + + @classmethod + def idl(self): + return { + 'strs': ['login', 'url', 'avatar_url', 'name', 'company', 'blog', + 'location', 'email', 'html_url', 'type', 'billing_email'], + 'ints': ['id', 'public_repos', 'public_gists', 'followers', + 'following', 'total_private_repos', 'owned_private_repos', + 'private_gists', 'disk_usage', 'collaborators'], + 'dates': ['created_at'], + 'maps': {'plan': plan} + } + + def __repr__(self): + return '<Org %s>' % self.login diff --git a/github3/models/repos.py b/github3/models/repos.py new file mode 100644 index 0000000..ba6ac33 --- /dev/null +++ b/github3/models/repos.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- +# +# author: David Medina + +from .base import BaseResource +from .user import User +from .orgs import Org + +class Repo(BaseResource): + """ Repo model """ + + @classmethod + def idl(self): + return { + 'strs': [ + 'url', 'html_url', 'clone_url', 'git_url', 'ssh_url', 'svn_url', + 'name', 'description', 'homepage', 'language', 'master_branch'], + 'ints': ['forks', 'watchers', 'size', 'open_issues'], + 'dates': ['created_at', 'pushed_at'], + 'bools': ['private', 'fork', 'has_issues', 'has_wiki', 'has_downloads'], + 'maps': { + 'owner': User, + 'organization': Org, + 'parent': 'self', + 'source': 'self', + } + } + + def __repr__(self): + return '<Repo %s/%s>' % (self.owner.login, self.name) diff --git a/github3/models/user.py b/github3/models/user.py new file mode 100644 index 0000000..7ec7999 --- /dev/null +++ b/github3/models/user.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python +# -*- encoding: utf-8 -*- +# +# author: David Medina + +from .base import BaseResource + +class Plan(BaseResource): + """Github Plan object model.""" + + @classmethod + def idl(self): + return { + 'strs': ['name'], + 'ints': ['space', 'collaborators', 'private_repos'], + } + + def __repr__(self): + return '<Plan %s>' % self.name + +class Key(BaseResource): + """Github Key object model.""" + + @classmethod + def idl(self): + return { + 'strs': ['url', 'title', 'key'], + 'ints': ['id'], + } + + def __repr__(self): + return '<Key %s>' % self.title + +class User(BaseResource): + """Github User object model.""" + + @classmethod + def idl(self): + return { + 'strs': ['login','avatar_url', 'url', 'name', 'company', 'blog', + 'location', 'email', 'bio', 'html_url', 'type'], + 'ints': [ + 'id', 'public_repos', 'public_gists', 'followers', 'following', + 'total_private_repos', 'owned_private_repos', 'private_gists', + 'disk_usage', 'collaborators'], + 'maps': {'plan': Plan}, + 'dates': ['created_at',], + 'bools': ['hireable', ], + } + + def __repr__(self): + return '<User %s>' % self.login + + #def handler(self): + # return self._gh.user_handler(self.login, force=True) + +class AuthUser(User): + """Github Authenticated User object model.""" + + #def handler(self): + # return self._gh.user_handler(self.login, force=True, private=True) + + def __repr__(self): + return '<AuthUser %s>' % self.login + |