1- """
2- github3.gists
3- =============
4-
5- Module which contains all the gist related material.
6-
7- """
8-
91from json import dumps
10- from github3 .models import GitHubObject , GitHubCore , BaseComment
11- from github3 .users import User
2+ from github3 .models import GitHubCore
123from github3 .decorators import requires_auth
4+ from github3 .gists .comment import GistComment
5+ from github3 .gists .file import GistFile
6+ from github3 .gists .history import GistHistory
7+ from github3 .users import User
138
149
1510class Gist (GitHubCore ):
@@ -22,6 +17,9 @@ class Gist(GitHubCore):
2217
2318 def __init__ (self , data , session = None ):
2419 super (Gist , self ).__init__ (data , session )
20+ #: Number of comments on this gist
21+ self .comments = data .get ('comments' , 0 )
22+
2523 #: Unique id for this gist.
2624 self .id = '{0}' .format (data .get ('id' , '' ))
2725
@@ -79,7 +77,7 @@ def create_comment(self, body):
7977 """Create a comment on this gist.
8078
8179 :param str body: (required), body of the comment
82- :returns: :class:`GistComment <GistComment>`
80+ :returns: :class:`GistComment <github3.gists.comment. GistComment>`
8381 """
8482 json = None
8583 if body :
@@ -152,11 +150,29 @@ def iter_comments(self, number=-1, etag=None):
152150 Default: -1 will iterate over all comments on the gist
153151 :param str etag: (optional), ETag from a previous request to the same
154152 endpoint
155- :returns: generator of :class:`GistComment <GistComment>`\ s
153+ :returns: generator of
154+ :class:`GistComment <github3.gists.comment.GistComment>`\ s
156155 """
157156 url = self ._build_url ('comments' , base_url = self ._api )
158157 return self ._iter (int (number ), url , GistComment , etag = etag )
159158
159+ def iter_commits (self , number = - 1 ):
160+ """Iter over the commits on this gist.
161+
162+ These commits will be requested from the API and should be the same as
163+ what is in ``Gist.history``.
164+
165+ .. versionadded:: 0.6
166+
167+ :param int number: (optional), number of commits to iterate over.
168+ Default: -1 will iterate over all commits associated with this
169+ gist.
170+ :returns: generator of
171+ :class: `GistHistory <github3.gists.history.GistHistory>`\ s
172+ """
173+ url = self ._build_url ('commits' , base_url = self ._api )
174+ return self ._iter (int (number ), url , GistHistory )
175+
160176 def iter_files (self ):
161177 """List of :class:`GistFile <GistFile>` objects representing the files
162178 stored in this gist."""
@@ -183,84 +199,3 @@ def unstar(self):
183199 """
184200 url = self ._build_url ('star' , base_url = self ._api )
185201 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 ) # (No coverage)
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