|
1 | | -// Github.js 0.6.2 |
| 1 | +// Github.js 0.7.0 |
2 | 2 | // (c) 2012 Michael Aufreiter, Development Seed |
3 | 3 | // Github.js is freely distributable under the MIT license. |
4 | 4 | // For all details and documentation: |
|
59 | 59 | }); |
60 | 60 | }; |
61 | 61 |
|
| 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 | + |
62 | 71 | // Show user information |
63 | 72 | // ------- |
64 | 73 |
|
|
77 | 86 | }); |
78 | 87 | }; |
79 | 88 |
|
80 | | - // List organization repositories |
| 89 | + // List a user's gists |
81 | 90 | // ------- |
82 | 91 |
|
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); |
86 | 95 | }); |
87 | 96 | }; |
88 | 97 |
|
89 | | - // List all user gists |
90 | | - // This will return all public gists if user is not authenticated |
| 98 | + // List organization repositories |
91 | 99 | // ------- |
92 | 100 |
|
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); |
96 | 104 | }); |
97 | 105 | }; |
98 | 106 | }; |
|
180 | 188 | // ------- |
181 | 189 |
|
182 | 190 | 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) { |
188 | 199 | if (err) return cb(err); |
189 | 200 | cb(null, res.sha); |
190 | 201 | }); |
|
346 | 357 | // Read the gist |
347 | 358 | // -------- |
348 | 359 |
|
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); |
370 | 363 | }); |
371 | 364 | }; |
372 | 365 |
|
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 | | - }; |
381 | 366 |
|
382 | 367 | // Delete the gist |
383 | 368 | // -------- |
|
400 | 385 | // Update a gist with the new stuff |
401 | 386 | // -------- |
402 | 387 |
|
403 | | - this.edit = function(cb,options) { |
| 388 | + this.update = function(options, cb) { |
404 | 389 | _request("PATCH", gistPath, options, function(err,res) { |
405 | 390 | cb(err,res); |
406 | 391 | }); |
407 | 392 | }; |
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 | | - } |
440 | 393 | }; |
441 | 394 |
|
442 | 395 | // Top Level API |
|
0 commit comments