From 6f53d4a0ba6889ba4bacf498c58d1f8cdf10cc93 Mon Sep 17 00:00:00 2001 From: Phillip Dornauer Date: Thu, 10 May 2012 21:04:18 +0200 Subject: [PATCH 1/2] Added support for require() / node.js --- README.md | 4 ++-- github.js | 20 +++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 309ea9e6..a37c3b0c 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,8 @@ repo.write('master', 'path/to/file', 'YOUR_NEW_CONTENTS', 'YOUR_COMMIT_MESSAGE', Not only can you can write files, you can of course read them. ```js +// Retrieve contents of a certain file (assumes UTF-8) + repo.read('master', 'path/to/file', function(err, data) { }); @@ -43,8 +45,6 @@ repo.read('master', 'path/to/file', function(err, data) { Listing all files of a repository is easy too. ```js -// Retrieve contents of a certain file (assumes UTF-8) - repo.list('master', 'path/to/file', function(err, data) { }); diff --git a/github.js b/github.js index 84113ad0..d95dedc7 100644 --- a/github.js +++ b/github.js @@ -5,10 +5,10 @@ // http://substance.io/michael/github (function() { - var Github; + var API_URL = 'https://api.github.com'; - - Github = window.Github = function(options) { + + var Github = function(options) { var username = options.username; var password = options.password; @@ -236,4 +236,18 @@ return new Github.User(); }; }; + + // Export the Github object for Node.js, with + // backwards-compatibility for the old `require()` API. If we're in + // the browser, add `Github` as a global object via a string identifier, + // for Closure Compiler "advanced" mode. + if (typeof exports !== "undefined") { + if (typeof module !== "undefined" && module.exports) { + exports = module.exports = Github; + } + exports.Github = Github; + } else { + this['Github'] = Github; + } + }).call(this); \ No newline at end of file From ca9ec19d76c192b46ea1a330b6557b0bd3dbda24 Mon Sep 17 00:00:00 2001 From: Phillip Dornauer Date: Thu, 10 May 2012 21:08:26 +0200 Subject: [PATCH 2/2] Updated README for Node.js usage --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a37c3b0c..7a5940c0 100644 --- a/README.md +++ b/README.md @@ -48,4 +48,20 @@ Listing all files of a repository is easy too. repo.list('master', 'path/to/file', function(err, data) { }); -``` \ No newline at end of file +``` + + +Node.js +-------------- + +To use Github.js on a node.js server, include it with require(): + +```js +var Github = require("/path/to/github.js"); + +var github = new Github({ + username: "YOU_USER", + password: "YOUR_PASSWORD", + auth: "basic" +}); +```