Skip to content

Commit 0751ee8

Browse files
committed
Remove GistComment dependence on BaseComment
Update our example response for unit tests to make this more testable and an accurate representation of what github3.py gets back.
1 parent d2fb594 commit 0751ee8

File tree

2 files changed

+83
-20
lines changed

2 files changed

+83
-20
lines changed

github3/gists/comment.py

+80-20
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,102 @@
11
# -*- coding: utf-8 -*-
2-
"""
3-
github3.gists.comment
4-
---------------------
5-
6-
Module containing the logic for a GistComment
7-
8-
"""
2+
"""Module containing the logic for a GistComment."""
93
from __future__ import unicode_literals
104

5+
from .. import decorators
6+
from .. import models
117
from .. import users
12-
from ..models import BaseComment
138

149

15-
class GistComment(BaseComment):
10+
class GistComment(models.GitHubCore):
11+
"""Representation of a comment left on a :class:`~github3.gists.Gist`.
12+
13+
See also: http://developer.github.com/v3/gists/comments/
1614
17-
"""This object represents a comment on a gist.
15+
.. versionchanged:: 1.0.0
1816
19-
Two comment instances can be checked like so::
17+
The ``links``, ``html_url``, and ``pull_request_url`` attributes were
18+
removed as none of them exist in the response from GitHub.
2019
21-
c1 == c2
22-
c1 != c2
20+
This object has the following attributes:
2321
24-
And is equivalent to::
22+
.. attribute:: author_association
2523
26-
c1.id == c2.id
27-
c1.id != c2.id
24+
The comment author's (:attr:`user`) association with this gist.
2825
29-
See also: http://developer.github.com/v3/gists/comments/
26+
.. attribute:: body
27+
28+
The markdown formatted original text written by the author.
29+
30+
.. attribute:: body_html
31+
32+
The HTML formatted comment body.
33+
34+
.. attribute:: body_text
35+
36+
The plain-text formatted comment body.
37+
38+
.. attribute:: created_at
3039
40+
A :class:`~datetime.datetime` object representing the date and time
41+
when this comment was created.
42+
43+
.. attribute:: id
44+
45+
The unique identifier for this comment.
46+
47+
.. attribute:: updated_at
48+
49+
A :class:`~datetime.datetime` object representing the date and time
50+
when this comment was most recently updated.
51+
52+
.. attribute:: user
53+
54+
A :class:`~github3.users.ShortUser` representing the author of this
55+
comment.
3156
"""
3257

3358
def _update_attributes(self, comment):
34-
self._api = self._get_attribute(comment, 'url')
35-
#: :class:`User <github3.users.User>` who made the comment
36-
#: Unless it is not associated with an account
59+
self._api = comment['url']
60+
self.author_association = comment['author_association']
61+
self.body = comment['body']
62+
self.body_html = comment['body_html']
63+
self.body_text = comment['body_text']
64+
self.created_at = comment['created_at']
65+
self.id = comment['id']
66+
self.updated_at = comment['updated_at']
3767
self.user = self._class_attribute(
3868
comment, 'user', users.ShortUser, self,
3969
)
4070

4171
def _repr(self):
4272
return '<Gist Comment [{0}]>'.format(self.user.login)
73+
74+
@decorators.requires_auth
75+
def delete(self):
76+
"""Delete this comment from the gist.
77+
78+
:returns:
79+
True if successful, False otherwise
80+
:rtype:
81+
bool
82+
"""
83+
return self._boolean(self._delete(self._api), 204, 404)
84+
85+
@decorators.requires_auth
86+
def edit(self, body):
87+
"""Edit this comment.
88+
89+
:param str body:
90+
(required), new body of the comment, Markdown-formatted
91+
:returns:
92+
True if successful, False otherwise
93+
:rtype:
94+
bool
95+
"""
96+
if body:
97+
json = self._json(self._patch(self._api,
98+
json={'body': body}), 200)
99+
if json:
100+
self._update_attributes(json)
101+
return True
102+
return False

tests/unit/json/gist_comment_example

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
2+
"author_association": "OWNER",
23
"body": "I was using curl, but this is awesome, too :)\r\n\r\n`curl -u <username> -XDELETE https://api.github.com/gists/<gist_id>/comments/<comment_id>`",
4+
"body_html": "I was using curl, but this is awesome, too",
5+
"body_text": "I was using curl, but this is awesome, too",
36
"created_at": "2012-12-17T19:56:05Z",
47
"id": 655725,
58
"updated_at": "2012-12-17T19:56:05Z",

0 commit comments

Comments
 (0)