diff --git a/.gitignore b/.gitignore index 7f913291a6..1e979b5faf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ node_modules .settings.xml .settings .c9revisions -/nbproject/private/ \ No newline at end of file +/nbproject/private/ +.idea \ No newline at end of file diff --git a/index.js b/index.js index 12f1ff531e..41a2368006 100644 --- a/index.js +++ b/index.js @@ -5,6 +5,7 @@ var fs = require("fs"); var mime = require("mime"); var Util = require("./util"); var Url = require("url"); +var Promise = require('es6-promise').Promise; /** section: github * class Client @@ -349,7 +350,10 @@ var Client = module.exports = function(config) { }; } - self[section][funcName] = function(msg, callback) { + + + + self[section][funcName] = function(msg, callback){ try { parseParams(msg, block.params); } @@ -363,7 +367,20 @@ var Client = module.exports = function(config) { return; } - api[section][funcName].call(api, msg, block, callback); + // good description for standart: http://www.html5rocks.com/en/tutorials/es6/promises/ + return new Promise(function (resolve, reject) { + api[section][funcName].call(api, msg, block, function(err, response){ + if (Util.isFunction(callback)) { + callback.apply(null, arguments) + } + + if (Util.isNull(err)) { + resolve(response); + } else { + reject(err); + } + }); + }); }; } else { diff --git a/package.json b/package.json index 71b9d5ce4a..69509d6505 100644 --- a/package.json +++ b/package.json @@ -1,34 +1,43 @@ { - "name" : "github", - "version" : "0.2.3", - "description" : "NodeJS wrapper for the GitHub API", - "author": "Mike de Boer ", - "contributors": [ - { "name": "Mike de Boer", "email": "info@mikedeboer.nl" }, - { "name": "Fabian Jakobs", "email": "fabian@c9.io" } - ], - "homepage": "http://github.com/mikedeboer/node-github", - "repository" : { - "type" : "git", - "url" : "http://github.com/mikedeboer/node-github.git" + "name": "github", + "version": "0.2.3", + "description": "NodeJS wrapper for the GitHub API", + "author": "Mike de Boer ", + "contributors": [ + { + "name": "Mike de Boer", + "email": "info@mikedeboer.nl" }, - "engine" : { - "node": ">=0.4.0" - }, - "dependencies": { - "mime": "^1.2.11" - }, - "devDependencies": { - "oauth": "~0.9.7", - "optimist": "~0.6.0", - "mocha": "~1.13.0" - }, - "main" : ".", - "scripts": { - "test": "node ./test/all.js" - }, - "licenses": [{ - "type": "The MIT License", - "url": "http://www.opensource.org/licenses/mit-license.php" - }] + { + "name": "Fabian Jakobs", + "email": "fabian@c9.io" + } + ], + "homepage": "http://github.com/mikedeboer/node-github", + "repository": { + "type": "git", + "url": "http://github.com/mikedeboer/node-github.git" + }, + "engine": { + "node": ">=0.4.0" + }, + "dependencies": { + "es6-promise": "^2.0.1", + "mime": "^1.2.11" + }, + "devDependencies": { + "oauth": "~0.9.7", + "optimist": "~0.6.0", + "mocha": "~1.13.0" + }, + "main": ".", + "scripts": { + "test": "node ./test/all.js" + }, + "licenses": [ + { + "type": "The MIT License", + "url": "http://www.opensource.org/licenses/mit-license.php" + } + ] } diff --git a/util.js b/util.js index 7d536d6a1a..df895876e5 100644 --- a/util.js +++ b/util.js @@ -105,19 +105,19 @@ var _slice = Array.prototype.slice; * - arg1 (mixed): messages to be printed to the standard output * - type (String): type denotation of the message. Possible values: * 'info', 'error', 'fatal', 'exit'. Optional, defaults to 'info'. - * + * * Unified logging to the console; arguments passed to this function will put logged * to the standard output of the current process and properly formatted. * Any non-String object will be inspected by the NodeJS util#inspect utility * function. * Messages will be prefixed with its type (with corresponding font color), like so: - * + * * [info] informational message * [error] error message * [fatal] fatal error message * [exit] program exit message (not an error) - * - * The type of message can be defined by passing it to this function as the last/ + * + * The type of message can be defined by passing it to this function as the last/ * final argument. If the type can not be found, this last/ final argument will be * regarded as yet another message. **/ @@ -138,3 +138,17 @@ exports.log = function() { console.log(pfx + " " + line); }); }; + + + +exports.isUndefined = function isUndefined(x) { + return typeof x === 'undefined'; +}; + +exports.isNull = function isNull(x) { + return x === null; +}; + +exports.isFunction = function isFunction(x) { + return typeof x === 'function'; +}; \ No newline at end of file