From a423c22a02c85ea16ae42c1b5a0a0a365eccd61c Mon Sep 17 00:00:00 2001 From: Antti Kaihola Date: Mon, 7 Nov 2011 14:38:32 +0200 Subject: _post_resource --- github3/api.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/github3/api.py b/github3/api.py index 81ae3e7..78f87b3 100644 --- a/github3/api.py +++ b/github3/api.py @@ -105,6 +105,11 @@ class GithubCore(object): return msg + def _post_resource(self, resource, obj, data, **kwargs): + r = self._http_resource('POST', resource, data=data, params=kwargs) + item = self._resource_deserialize(r.content) + + return obj.new_from_dict(item, gh=self) @staticmethod def _total_pages_from_header(link_header): -- cgit v1.3-14-g43fede From 6d7b6547d48c66c607a2e674034cef662a08e2f7 Mon Sep 17 00:00:00 2001 From: Antti Kaihola Date: Mon, 7 Nov 2011 14:38:55 +0200 Subject: Added the create_gist() method --- github3/models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/github3/models.py b/github3/models.py index 3c86687..8c4f9ba 100644 --- a/github3/models.py +++ b/github3/models.py @@ -113,6 +113,14 @@ class User(BaseResource): def gists(self): return self._gh._get_resources(('users', self.login, 'gists'), Gist) + def create_gist(self, description, public=True, files={}): + data = {'description': description, + 'public': public, + 'files': files} + deploy = json.dumps(data) + return self._gh._post_resource(('users', self.login, 'gists'), Gist, deploy) + + class CurrentUser(User): """Github Current User object model.""" -- cgit v1.3-14-g43fede From 86da17c1ee6d9664b3db2c77d2f8ecefbafd5e37 Mon Sep 17 00:00:00 2001 From: Antti Kaihola Date: Mon, 7 Nov 2011 14:42:33 +0200 Subject: Added akaihola to authors --- AUTHORS | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AUTHORS b/AUTHORS index bcf74ac..d562a71 100644 --- a/AUTHORS +++ b/AUTHORS @@ -11,4 +11,5 @@ Patches and Suggestions ``````````````````````` - Mahdi Yusuf -- Rok Garbas \ No newline at end of file +- Rok Garbas +- Antti Kaihola \ No newline at end of file -- cgit v1.3-14-g43fede From 878a2fab086e9569a1ba8f2e6175305b01ced31a Mon Sep 17 00:00:00 2001 From: Antti Kaihola Date: Mon, 7 Nov 2011 14:46:13 +0200 Subject: Added create_gist() example to readme --- README.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.rst b/README.rst index 4e5df72..ab6d9c7 100644 --- a/README.rst +++ b/README.rst @@ -18,7 +18,10 @@ Usage gh.get_repo('kennethreitz', 'python-github3') + me = gh.get_me() + me.create_gist(u'Description', + files={'file1.txt': {'content': u'Content of first file'}}) -- cgit v1.3-14-g43fede From 15fd9291bf32cf027b490adc6f03856c28f3ab64 Mon Sep 17 00:00:00 2001 From: Antti Kaihola Date: Wed, 9 Nov 2011 13:05:10 +0200 Subject: Updated example in README.rst to work with current version --- README.rst | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index c924c4b..1686d89 100644 --- a/README.rst +++ b/README.rst @@ -16,16 +16,21 @@ Usage :: - import github3 + from github3.api import Github + from github3.handlers.user import AuthUser + from github3.handlers.gists import Gist - gh = github3.basic_auth('username', 'password') + gh = Github() + gh.session.auth = ('kennethreitz', 'password') - gh.get_repo('kennethreitz', 'python-github3') + me = AuthUser(gh) + for repo in me.get_repos(): + print repo - me = gh.get_me() - - me.create_gist(u'Description', - files={'file1.txt': {'content': u'Content of first file'}}) + gists = Gist(gh) + gists.create_gist( + u'Description', + files={'file1.txt': {'content': u'Content of first file'}}) -- cgit v1.3-14-g43fede