Skip to content

Commit 5d069f3

Browse files
committed
Improved Gist API.
1 parent bb05672 commit 5d069f3

File tree

1 file changed

+30
-77
lines changed

1 file changed

+30
-77
lines changed

github.js

Lines changed: 30 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Github.js 0.6.2
1+
// Github.js 0.7.0
22
// (c) 2012 Michael Aufreiter, Development Seed
33
// Github.js is freely distributable under the MIT license.
44
// For all details and documentation:
@@ -59,6 +59,15 @@
5959
});
6060
};
6161

62+
// List authenticated user's gists
63+
// -------
64+
65+
this.gists = function(cb) {
66+
_request("GET", "/gists", null, function(err, res) {
67+
cb(err,res);
68+
});
69+
};
70+
6271
// Show user information
6372
// -------
6473

@@ -77,22 +86,21 @@
7786
});
7887
};
7988

80-
// List organization repositories
89+
// List a user's gists
8190
// -------
8291

83-
this.orgRepos = function(orgname, cb) {
84-
_request("GET", "/orgs/"+orgname+"/repos?type=all&per_page=1000&sort=updated&direction=desc", null, function(err, res) {
85-
cb(err, res);
92+
this.userGists = function(username, cb) {
93+
_request("GET", "/users/"+username+"/gists", null, function(err, res) {
94+
cb(err,res);
8695
});
8796
};
8897

89-
// List all user gists
90-
// This will return all public gists if user is not authenticated
98+
// List organization repositories
9199
// -------
92100

93-
this.userGists = function(username,cb) {
94-
_request("GET", "/gists", null, function(err, res) {
95-
cb(err,res);
101+
this.orgRepos = function(orgname, cb) {
102+
_request("GET", "/orgs/"+orgname+"/repos?type=all&per_page=1000&sort=updated&direction=desc", null, function(err, res) {
103+
cb(err, res);
96104
});
97105
};
98106
};
@@ -180,11 +188,14 @@
180188
// -------
181189

182190
this.postBlob = function(content, cb) {
183-
var data = {
184-
"content": content,
185-
"encoding": "utf-8"
186-
};
187-
_request("POST", repoPath + "/git/blobs", data, function(err, res) {
191+
if (typeof(content) === "string") {
192+
content = {
193+
"content": content,
194+
"encoding": "utf-8"
195+
};
196+
}
197+
198+
_request("POST", repoPath + "/git/blobs", content, function(err, res) {
188199
if (err) return cb(err);
189200
cb(null, res.sha);
190201
});
@@ -346,38 +357,12 @@
346357
// Read the gist
347358
// --------
348359

349-
this.show = function(cb) {
350-
_request("GET", gistPath, null, function(err,info) {
351-
cb(err,info);
352-
});
353-
};
354-
355-
// Star the gist
356-
// --------
357-
358-
this.star = function(cb) {
359-
_request("PUT", gistPath+"/star", null, function(err,res) {
360-
cb(err,res);
361-
});
362-
}
363-
364-
// Check if the Gist is starred
365-
// --------
366-
367-
this.isStarred = function(cb) {
368-
_request("GET", gistPath+"/star", null, function(err,res) {
369-
cb(err,res);
360+
this.read = function(cb) {
361+
_request("GET", gistPath, null, function(err, gist) {
362+
cb(err, gist);
370363
});
371364
};
372365

373-
// Unstar the gist
374-
// --------
375-
376-
this.unstar = function(cb) {
377-
_request("DELETE", gistPath+"/star", null, function(err,res) {
378-
cb(err,res);
379-
});
380-
};
381366

382367
// Delete the gist
383368
// --------
@@ -400,43 +385,11 @@
400385
// Update a gist with the new stuff
401386
// --------
402387

403-
this.edit = function(cb,options) {
388+
this.update = function(options, cb) {
404389
_request("PATCH", gistPath, options, function(err,res) {
405390
cb(err,res);
406391
});
407392
};
408-
409-
// Update Gist Description
410-
// --------
411-
412-
this.updateDescription = function(cb,description) {
413-
that.edit(cb,{description: description});
414-
};
415-
416-
// Rename a file in the gist
417-
// --------
418-
419-
this.renameFile = function(oldName, newName, cb) {
420-
var options = {files:{}};
421-
options.files[oldName] = newName;
422-
that.edit(cb, options);
423-
};
424-
425-
// Delete a file in the gist
426-
// --------
427-
428-
this.deleteFile = function(fileName, cb) {
429-
var options = {files:{}};
430-
options.files[fileName] = null;
431-
that.edit(cb,options);
432-
};
433-
434-
// Update a particular file in the gist
435-
this.updateFile = function(filename, contents, cb) {
436-
var options = {files:{}};
437-
options.files[filename] = {content: contents};
438-
that.edit(cb,options);
439-
}
440393
};
441394

442395
// Top Level API

0 commit comments

Comments
 (0)