|
1 | 1 | # -*- 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.""" |
9 | 3 | from __future__ import unicode_literals
|
10 | 4 |
|
| 5 | +from .. import decorators |
| 6 | +from .. import models |
11 | 7 | from .. import users
|
12 |
| -from ..models import BaseComment |
13 | 8 |
|
14 | 9 |
|
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/ |
16 | 14 |
|
17 |
| - """This object represents a comment on a gist. |
| 15 | + .. versionchanged:: 1.0.0 |
18 | 16 |
|
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. |
20 | 19 |
|
21 |
| - c1 == c2 |
22 |
| - c1 != c2 |
| 20 | + This object has the following attributes: |
23 | 21 |
|
24 |
| - And is equivalent to:: |
| 22 | + .. attribute:: author_association |
25 | 23 |
|
26 |
| - c1.id == c2.id |
27 |
| - c1.id != c2.id |
| 24 | + The comment author's (:attr:`user`) association with this gist. |
28 | 25 |
|
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 |
30 | 39 |
|
| 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. |
31 | 56 | """
|
32 | 57 |
|
33 | 58 | 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'] |
37 | 67 | self.user = self._class_attribute(
|
38 | 68 | comment, 'user', users.ShortUser, self,
|
39 | 69 | )
|
40 | 70 |
|
41 | 71 | def _repr(self):
|
42 | 72 | 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 |
0 commit comments