aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3/services
diff options
context:
space:
mode:
authorDavid Medina <davidmedina9@gmail.com>2012-04-04 00:07:50 +0200
committerDavid Medina <davidmedina9@gmail.com>2012-04-04 00:07:50 +0200
commit3e551e6801a0031f1482ad5d9f30af9df78e9471 (patch)
tree9d28cc75691279ff75f079cd4e085e77241517af /pygithub3/services
parent:sparkles: Relase 0.2 :sparkles: (diff)
parentFix bug (diff)
downloadpython-github3-3e551e6801a0031f1482ad5d9f30af9df78e9471.tar.xz
python-github3-3e551e6801a0031f1482ad5d9f30af9df78e9471.zip
Gists service done
Diffstat (limited to 'pygithub3/services')
-rw-r--r--pygithub3/services/gists/__init__.py154
-rw-r--r--pygithub3/services/gists/comments.py71
-rw-r--r--pygithub3/services/repos/__init__.py6
3 files changed, 228 insertions, 3 deletions
diff --git a/pygithub3/services/gists/__init__.py b/pygithub3/services/gists/__init__.py
new file mode 100644
index 0000000..aadb136
--- /dev/null
+++ b/pygithub3/services/gists/__init__.py
@@ -0,0 +1,154 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+from pygithub3.services.base import Service
+from comments import Comments
+
+
+class Gist(Service):
+ """ Consume `Gists API <http://developer.github.com/v3/gists>`_ """
+
+ def __init__(self, **config):
+ self.comments = Comments(**config)
+ super(Gist, self).__init__(**config)
+
+ def list(self, user=None):
+ """ Get user's gists
+
+ :param str user: Username
+ :returns: A :doc:`result`
+
+ If you call it without user and you are authenticated, get the
+ authenticated user's gists. but if you aren't authenticated get the
+ public gists
+
+ ::
+
+ gist_service.list('copitux')
+ gist_service.list()
+ """
+ request = self.request_builder('gists.list', user=user)
+ return self._get_result(request)
+
+ def public(self):
+ """ Get public gists
+
+ :returns: A :doc:`result`
+
+ .. note ::
+ Be careful iterating the result
+ """
+ request = self.request_builder('gists.public')
+ return self._get_result(request)
+
+ def starred(self):
+ """ Get authenticated user's starred gists
+
+ :returns: A :doc:`result`
+
+ .. warning::
+ You must be authenticated
+ """
+ request = self.request_builder('gists.starred')
+ return self._get_result(request)
+
+ def get(self, id):
+ """ Get a single gist
+
+ :param int id: Gist id
+ """
+ request = self.request_builder('gists.get', id=id)
+ return self._get(request)
+
+ def create(self, data):
+ """ Create a gist
+
+ :param dict data: Input. See `github gists doc`_
+
+ ::
+
+ gist_service.create(dict(description='some gist', public=True,
+ files={'xample.py': {'content': 'import code'}}))
+ """
+ request = self.request_builder('gists.create', body=data)
+ return self._post(request)
+
+ def update(self, id, data):
+ """ Update a single gist
+
+ :param int id: Gist id
+ :param dict data: Input. See `github gists doc`_
+
+ .. warning ::
+ You must be authenticated
+
+ ::
+
+ gist_service.update(dict(description='edited',
+ files={'xample.py': {
+ 'filename': 'new_xample.py',
+ 'content': 'import new_code'}}))
+ """
+ request = self.request_builder('gists.update', id=id, body=data)
+ return self._patch(request)
+
+ def star(self, id):
+ """ Star a gist
+
+ :param int id: Gist id
+
+ .. warning ::
+ You must be authenticated
+
+ """
+ request = self.request_builder('gists.star', id=id)
+ self._put(request)
+
+ def unstar(self, id):
+ """ Unstar a gist
+
+ :param int id: Gist id
+
+ .. warning ::
+ You must be authenticated
+
+ """
+ request = self.request_builder('gists.unstar', id=id)
+ return self._delete(request)
+
+ def is_starred(self, id):
+ """ Check if a gist is starred
+
+ :param int id: Gist id
+
+ .. warning ::
+ You must be authenticated
+
+ """
+ request = self.request_builder('gists.is_starred', id=id)
+ return self._bool(request)
+
+ def fork(self, id):
+ """ Fork a gist
+
+ :param int id: Gist id
+
+ .. warning ::
+ You must be authenticated
+
+ """
+
+ request = self.request_builder('gists.fork', id=id)
+ return self._post(request)
+
+ def delete(self, id):
+ """ Delete a gist
+
+ :param int id: Gist id
+
+ .. warning ::
+ You must be authenticated
+
+ """
+ request = self.request_builder('gists.delete', id=id)
+ return self._delete(request)
diff --git a/pygithub3/services/gists/comments.py b/pygithub3/services/gists/comments.py
new file mode 100644
index 0000000..7f4955f
--- /dev/null
+++ b/pygithub3/services/gists/comments.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+from pygithub3.services.base import Service, MimeTypeMixin
+
+
+class Comments(Service, MimeTypeMixin):
+ """ Consume `Comments API
+ <http://developer.github.com/v3/gists/comments>`_
+
+ .. note::
+ This service support :ref:`mimetypes-section` configuration
+ """
+
+ def list(self, gist_id):
+ """ Get gist's comments
+
+ :param int gist_id: Gist id
+ :returns: A :doc:`result`
+ """
+ request = self.request_builder('gists.comments.list', gist_id=gist_id)
+ return self._get_result(request, **self._get_mimetype_as_header())
+
+ def get(self, id):
+ """ Get a single comment
+
+ :param int id: Comment id
+ """
+ request = self.request_builder('gists.comments.get', id=id)
+ return self._get(request, **self._get_mimetype_as_header())
+
+ def create(self, gist_id, message):
+ """ Create a comment
+
+ :param int gist_id: Gist id
+ :param str message: Comment's message
+
+ .. warning::
+ You must be authenticated
+
+ ::
+
+ comment_service.create(1, 'comment')
+ """
+ request = self.request_builder('gists.comments.create',
+ gist_id=gist_id, body={'body': message})
+ return self._post(request, **self._get_mimetype_as_header())
+
+ def update(self, id, message):
+ """ Update a comment
+
+ :param int id: Comment id
+ :param str message: Comment's message
+
+ .. warning::
+ You must be authenticated
+ """
+ request = self.request_builder('gists.comments.update', id=id,
+ body={'body': message})
+ return self._patch(request, **self._get_mimetype_as_header())
+
+ def delete(self, id):
+ """ Delete a comment
+
+ :param int id: Comment id
+
+ .. warning::
+ You must be authenticated
+ """
+ request = self.request_builder('gists.comments.delete', id=id)
+ self._delete(request)
diff --git a/pygithub3/services/repos/__init__.py b/pygithub3/services/repos/__init__.py
index 3ef1fb4..628e9d6 100644
--- a/pygithub3/services/repos/__init__.py
+++ b/pygithub3/services/repos/__init__.py
@@ -11,7 +11,7 @@ from .watchers import Watchers
from .hooks import Hooks
-class Repos(Service):
+class Repo(Service):
""" Consume `Repos API <http://developer.github.com/v3/repos>`_ """
def __init__(self, **config):
@@ -22,7 +22,7 @@ class Repos(Service):
self.keys = Keys(**config)
self.watchers = Watchers(**config)
self.hooks = Hooks(**config)
- super(Repos, self).__init__(**config)
+ super(Repo, self).__init__(**config)
def list(self, user=None, type='all'):
""" Get user's repositories
@@ -133,7 +133,7 @@ class Repos(Service):
return self.__list_contributors(user, repo)
def list_contributors_with_anonymous(self, user=None, repo=None):
- """ Like :attr:`~pygithub3.services.repos.Repos.list_contributors` plus
+ """ Like :attr:`~pygithub3.services.repos.Repo.list_contributors` plus
anonymous """
return self.__list_contributors(user, repo, anom=True)