Skip to content

Commit 2cd81be

Browse files
committed
Initial work on gist support
1 parent 0e467b1 commit 2cd81be

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

github.js

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,16 @@
9292
cb(err, res);
9393
});
9494
};
95+
96+
// List all user gists
97+
// This will return all public gists if user is not authenticated
98+
// -------
99+
100+
this.userGists = function(username,cb) {
101+
_request("GET", "/gists", null, function(err, res) {
102+
cb(err,res);
103+
});
104+
};
95105
};
96106

97107

@@ -333,6 +343,110 @@
333343
};
334344
};
335345

346+
// Gists API
347+
// =======
348+
349+
Github.Gist = function(options) {
350+
var id = options.id;
351+
var that = this;
352+
var gistPath = "/gists/"+id;
353+
354+
// Read the gist
355+
// --------
356+
357+
this.show = function(cb) {
358+
_request("GET", gistPath, null, function(err,info) {
359+
cb(err,info);
360+
});
361+
};
362+
363+
// Star the gist
364+
// --------
365+
366+
this.star = function(cb) {
367+
_request("PUT", gistPath+"/star", null, function(err,res) {
368+
cb(err,res);
369+
});
370+
}
371+
372+
// Check if the Gist is starred
373+
// --------
374+
375+
this.isStarred = function(cb) {
376+
_request("GET", gistPath+"/star", null, function(err,res) {
377+
cb(err,res);
378+
});
379+
};
380+
381+
// Unstar the gist
382+
// --------
383+
384+
this.unstar = function(cb) {
385+
_request("DELETE", gistPath+"/star", null, function(err,res) {
386+
cb(err,res);
387+
});
388+
};
389+
390+
// Delete the gist
391+
// --------
392+
393+
this.delete = function(cb) {
394+
_request("DELETE", gistPath, null, function(err,res) {
395+
cb(err,res);
396+
});
397+
};
398+
399+
// Fork a gist
400+
// --------
401+
402+
this.fork = function(cb) {
403+
_request("POST", gistPath+"/fork", null, function(err,res) {
404+
cb(err,res);
405+
});
406+
};
407+
408+
// Update a gist with the new stuff
409+
// --------
410+
411+
this.edit = function(cb,options) {
412+
_request("PATCH", gistPath, options, function(err,res) {
413+
cb(err,res);
414+
});
415+
};
416+
417+
// Update Gist Description
418+
// --------
419+
420+
this.updateDescription = function(cb,description) {
421+
that.edit(cb,{description: description});
422+
};
423+
424+
// Rename a file in the gist
425+
// --------
426+
427+
this.renameFile = function(oldName, newName, cb) {
428+
var options = {files:{}};
429+
options.files[oldName] = newName;
430+
that.edit(cb, options);
431+
};
432+
433+
// Delete a file in the gist
434+
// --------
435+
436+
this.deleteFile = function(fileName, cb) {
437+
var options = {files:{}};
438+
options.files[fileName] = null;
439+
that.edit(cb,options);
440+
};
441+
442+
// Update a particular file in the gist
443+
this.updateFile = function(filename, contents, cb) {
444+
var options = {files:{}};
445+
options.files[filename] = {content: contents};
446+
that.edit(cb,options);
447+
}
448+
};
449+
336450
// Top Level API
337451
// -------
338452

@@ -343,5 +457,9 @@
343457
this.getUser = function() {
344458
return new Github.User();
345459
};
460+
461+
this.getGist = function(id) {
462+
return new Github.Gist({id: id});
463+
};
346464
};
347465
}).call(this);

0 commit comments

Comments
 (0)