aboutsummaryrefslogtreecommitdiffstats
path: root/pygithub3
diff options
context:
space:
mode:
Diffstat (limited to 'pygithub3')
-rw-r--r--pygithub3/requests/gists/comments.py40
-rw-r--r--pygithub3/resources/gists.py8
-rw-r--r--pygithub3/services/gists/__init__.py2
-rw-r--r--pygithub3/services/gists/comments.py64
-rw-r--r--pygithub3/tests/services/test_gists.py39
5 files changed, 152 insertions, 1 deletions
diff --git a/pygithub3/requests/gists/comments.py b/pygithub3/requests/gists/comments.py
new file mode 100644
index 0000000..32f01ec
--- /dev/null
+++ b/pygithub3/requests/gists/comments.py
@@ -0,0 +1,40 @@
+# -*- encoding: utf-8 -*-
+
+from pygithub3.requests.base import Request
+from pygithub3.resources.gists import Comment
+
+class List(Request):
+
+ uri = 'gists/{gist_id}/comments'
+ resource = Comment
+
+
+class Get(Request):
+
+ uri = 'gists/comments/{id}'
+ resource = Comment
+
+
+class Create(Request):
+
+ uri = 'gists/{gist_id}/comments'
+ resource = Comment
+ body_schema = {
+ 'schema': ('body', ),
+ 'required': ('body', )
+ }
+
+
+class Update(Request):
+
+ uri = 'gists/comments/{id}'
+ resource = Comment
+ body_schema = {
+ 'schema': ('body', ),
+ 'required': ('body', )
+ }
+
+
+class Delete(Request):
+
+ uri = 'gists/comments/1'
diff --git a/pygithub3/resources/gists.py b/pygithub3/resources/gists.py
index 8345f84..7e9550a 100644
--- a/pygithub3/resources/gists.py
+++ b/pygithub3/resources/gists.py
@@ -35,3 +35,11 @@ class Gist(Resource):
def __str__(self):
return '<Gist (%s)>' % getattr(self, 'description', '')
+
+class Comment(Resource):
+
+ _dates = ('created_at', )
+ _maps = {'user': User}
+
+ def __str__(self):
+ return '<GistComment (%s)>' % getattr(self, 'user', '')
diff --git a/pygithub3/services/gists/__init__.py b/pygithub3/services/gists/__init__.py
index b983fea..5fbfe7a 100644
--- a/pygithub3/services/gists/__init__.py
+++ b/pygithub3/services/gists/__init__.py
@@ -2,12 +2,14 @@
# -*- 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):
diff --git a/pygithub3/services/gists/comments.py b/pygithub3/services/gists/comments.py
new file mode 100644
index 0000000..397d583
--- /dev/null
+++ b/pygithub3/services/gists/comments.py
@@ -0,0 +1,64 @@
+#!/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
+ """
+ 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
+ """
+ request = self.request_builder('gists.comments.delete', id=id)
+ self._delete(request)
diff --git a/pygithub3/tests/services/test_gists.py b/pygithub3/tests/services/test_gists.py
index 66ff537..8cf93ed 100644
--- a/pygithub3/tests/services/test_gists.py
+++ b/pygithub3/tests/services/test_gists.py
@@ -6,7 +6,7 @@ from mock import patch, Mock
from pygithub3.tests.utils.core import TestCase
from pygithub3.resources.base import json
-from pygithub3.services.gists import Gist
+from pygithub3.services.gists import Gist, Comments
from pygithub3.tests.utils.base import (mock_response, mock_response_result,
mock_json)
from pygithub3.tests.utils.services import _
@@ -91,3 +91,40 @@ class TestGistService(TestCase):
self.gs.delete(1)
self.assertEqual(request_method.call_args[0],
('delete', _('gists/1')))
+
+
+@patch.object(requests.sessions.Session, 'request')
+class TestCommentService(TestCase):
+
+ def setUp(self):
+ self.cs = Comments()
+
+ def test_LIST(self, request_method):
+ request_method.return_value = mock_response_result()
+ self.cs.list(1).all()
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('gists/1/comments')))
+
+ def test_GET(self, request_method):
+ request_method.return_value = mock_response()
+ self.cs.get(1)
+ self.assertEqual(request_method.call_args[0],
+ ('get', _('gists/comments/1')))
+
+ def test_CREATE(self, request_method):
+ request_method.return_value = mock_response('post')
+ self.cs.create(1, dict(body='comment'))
+ self.assertEqual(request_method.call_args[0],
+ ('post', _('gists/1/comments')))
+
+ def test_UPDATE(self, request_method):
+ request_method.return_value = mock_response('patch')
+ self.cs.update(1, dict(body='new_comment'))
+ self.assertEqual(request_method.call_args[0],
+ ('patch', _('gists/comments/1')))
+
+ def test_DELETE(self, request_method):
+ request_method.return_value = mock_response('delete')
+ self.cs.delete(1)
+ self.assertEqual(request_method.call_args[0],
+ ('delete', _('gists/comments/1')))