|
11 | 11 | from github3.decorators import requires_auth |
12 | 12 |
|
13 | 13 |
|
14 | | -class GistFile(GitHubObject): |
15 | | - """The :class:`GistFile <GistFile>` object. This is used to represent a |
16 | | - file object returned by GitHub while interacting with gists. |
17 | | - """ |
18 | | - def __init__(self, attributes): |
19 | | - super(GistFile, self).__init__(attributes) |
20 | | - |
21 | | - #: The raw URL for the file at GitHub. |
22 | | - self.raw_url = attributes.get('raw_url') |
23 | | - #: The name of the file. |
24 | | - self.filename = attributes.get('filename') |
25 | | - #: The name of the file. |
26 | | - self.name = attributes.get('filename') |
27 | | - #: The language associated with the file. |
28 | | - self.language = attributes.get('language') |
29 | | - #: The size of the file. |
30 | | - self.size = attributes.get('size') |
31 | | - #: The content of the file. |
32 | | - self.content = attributes.get('content') |
33 | | - |
34 | | - def __repr__(self): |
35 | | - return '<Gist File [{0}]>'.format(self.name) |
36 | | - |
37 | | - |
38 | | -class GistComment(BaseComment): |
39 | | - """The :class:`GistComment <GistComment>` object. This represents a comment |
40 | | - on a gist. |
41 | | - """ |
42 | | - def __init__(self, comment, session=None): |
43 | | - super(GistComment, self).__init__(comment, session) |
44 | | - |
45 | | - #: :class:`User <github3.users.User>` who made the comment |
46 | | - self.user = None |
47 | | - if comment.get('user'): |
48 | | - self.user = User(comment.get('user'), self) |
49 | | - |
50 | | - def __repr__(self): |
51 | | - return '<Gist Comment [{0}]>'.format(self.user.login) |
52 | | - |
53 | | - |
54 | 14 | class Gist(GitHubCore): |
55 | 15 | """The :class:`Gist <Gist>` object. This object holds all the information |
56 | 16 | returned by Github about a gist. With it you can comment on or fork the |
@@ -100,6 +60,9 @@ def __init__(self, data, session=None): |
100 | 60 | #: Number of files in this gist. |
101 | 61 | self.files = len(self._files) |
102 | 62 |
|
| 63 | + #: History of this gist, list of :class:`GistHistory <GistHistory>` |
| 64 | + self.history = [GistHistory(h, self) for h in data.get('history', [])] |
| 65 | + |
103 | 66 | def __repr__(self): |
104 | 67 | return '<Gist [{0}]>'.format(self.id) |
105 | 68 |
|
@@ -220,3 +183,84 @@ def unstar(self): |
220 | 183 | """ |
221 | 184 | url = self._build_url('star', base_url=self._api) |
222 | 185 | return self._boolean(self._delete(url), 204, 404) |
| 186 | + |
| 187 | + |
| 188 | +class GistComment(BaseComment): |
| 189 | + """The :class:`GistComment <GistComment>` object. This represents a comment |
| 190 | + on a gist. |
| 191 | + """ |
| 192 | + def __init__(self, comment, session=None): |
| 193 | + super(GistComment, self).__init__(comment, session) |
| 194 | + |
| 195 | + #: :class:`User <github3.users.User>` who made the comment |
| 196 | + self.user = None |
| 197 | + if comment.get('user'): |
| 198 | + self.user = User(comment.get('user'), self) |
| 199 | + |
| 200 | + def __repr__(self): |
| 201 | + return '<Gist Comment [{0}]>'.format(self.user.login) |
| 202 | + |
| 203 | + |
| 204 | +class GistFile(GitHubObject): |
| 205 | + """The :class:`GistFile <GistFile>` object. This is used to represent a |
| 206 | + file object returned by GitHub while interacting with gists. |
| 207 | + """ |
| 208 | + def __init__(self, attributes): |
| 209 | + super(GistFile, self).__init__(attributes) |
| 210 | + |
| 211 | + #: The raw URL for the file at GitHub. |
| 212 | + self.raw_url = attributes.get('raw_url') |
| 213 | + #: The name of the file. |
| 214 | + self.filename = attributes.get('filename') |
| 215 | + #: The name of the file. |
| 216 | + self.name = attributes.get('filename') |
| 217 | + #: The language associated with the file. |
| 218 | + self.language = attributes.get('language') |
| 219 | + #: The size of the file. |
| 220 | + self.size = attributes.get('size') |
| 221 | + #: The content of the file. |
| 222 | + self.content = attributes.get('content') |
| 223 | + |
| 224 | + def __repr__(self): |
| 225 | + return '<Gist File [{0}]>'.format(self.name) |
| 226 | + |
| 227 | + |
| 228 | +class GistHistory(GitHubCore): |
| 229 | + """The :class:`GistHistory <GistHistory>` object represents one version |
| 230 | + (or revision) of a gist.""" |
| 231 | + def __init__(self, history, session=None): |
| 232 | + super(GistHistory, self).__init__(history, session) |
| 233 | + self._api = history.get('url', '') |
| 234 | + |
| 235 | + #: SHA of the commit associated with this version |
| 236 | + self.version = history.get('version', '') |
| 237 | + |
| 238 | + #: user who made these changes |
| 239 | + self.user = User(history.get('user') or {}, session) |
| 240 | + |
| 241 | + #: dict containing the change status; see also: deletions, additions, |
| 242 | + #: total |
| 243 | + self.change_status = history.get('change_status', {}) |
| 244 | + |
| 245 | + #: number of additions made |
| 246 | + self.additions = self.change_status.get('additions', 0) |
| 247 | + |
| 248 | + #: number of deletions made |
| 249 | + self.deletions = self.change_status.get('deletions', 0) |
| 250 | + |
| 251 | + #: total number of changes made |
| 252 | + self.total = self.change_status.get('total', 0) |
| 253 | + |
| 254 | + #: datetime representation of when the commit was made |
| 255 | + self.committed_at = self._strptime(history.get('committed_at')) |
| 256 | + |
| 257 | + def __repr__(self): |
| 258 | + return '<Gist History [{0}]>'.format(self.version) |
| 259 | + |
| 260 | + def get_gist(self): |
| 261 | + """Retrieves the gist at this version. |
| 262 | +
|
| 263 | + :returns: :class:`Gist <Gist>` |
| 264 | + """ |
| 265 | + json = self._json(self._get(self._api), 200) |
| 266 | + return Gist(json, self) |
0 commit comments