From 64ff82d871b87a8f38edc7e10e95eb63ab648535 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 10 Jan 2016 02:04:27 +0800 Subject: [PATCH 1/3] Message:added support for access_token authentication for gitlab Jira: Detail: Reviewer: Alex Signed-off-by: Alex --- lib/ApiBaseHTTP.js | 55 +++++++++++++++++++++++------------------- src/ApiBaseHTTP.coffee | 10 +++++--- 2 files changed, 37 insertions(+), 28 deletions(-) diff --git a/lib/ApiBaseHTTP.js b/lib/ApiBaseHTTP.js index 52ae2c8..ddb15f8 100644 --- a/lib/ApiBaseHTTP.js +++ b/lib/ApiBaseHTTP.js @@ -1,9 +1,9 @@ -// Generated by CoffeeScript 1.7.1 +// Generated by CoffeeScript 1.10.0 (function() { var ApiBase, debug, querystring, slumber, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - __hasProp = {}.hasOwnProperty, - __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; debug = require('debug')('gitlab:ApiBaseHTTP'); @@ -13,39 +13,39 @@ slumber = require('slumber'); - module.exports.ApiBaseHTTP = (function(_super) { - __extends(ApiBaseHTTP, _super); + module.exports.ApiBaseHTTP = (function(superClass) { + extend(ApiBaseHTTP, superClass); function ApiBaseHTTP() { - this.patch = __bind(this.patch, this); - this.put = __bind(this.put, this); - this.post = __bind(this.post, this); - this["delete"] = __bind(this["delete"], this); - this.get = __bind(this.get, this); - this.fn_wrapper = __bind(this.fn_wrapper, this); - this.prepare_opts = __bind(this.prepare_opts, this); - this.init = __bind(this.init, this); - this.handleOptions = __bind(this.handleOptions, this); + this.patch = bind(this.patch, this); + this.put = bind(this.put, this); + this.post = bind(this.post, this); + this["delete"] = bind(this["delete"], this); + this.get = bind(this.get, this); + this.fn_wrapper = bind(this.fn_wrapper, this); + this.prepare_opts = bind(this.prepare_opts, this); + this.init = bind(this.init, this); + this.handleOptions = bind(this.handleOptions, this); return ApiBaseHTTP.__super__.constructor.apply(this, arguments); } ApiBaseHTTP.prototype.handleOptions = function() { - var _base, _base1, _base2; + var base, base1, base2; ApiBaseHTTP.__super__.handleOptions.apply(this, arguments); - if ((_base = this.options).base_url == null) { - _base.base_url = ''; + if ((base = this.options).base_url == null) { + base.base_url = ''; } if (!this.options.url) { throw "`url` is mandatory"; } - if (!this.options.token) { - throw "`private_token` is mandatory"; + if (!this.options.token && !this.options.access_token) { + throw "`private_token or access_token` is mandatory"; } - if ((_base1 = this.options).slumber == null) { - _base1.slumber = {}; + if ((base1 = this.options).slumber == null) { + base1.slumber = {}; } - if ((_base2 = this.options.slumber).append_slash == null) { - _base2.append_slash = false; + if ((base2 = this.options.slumber).append_slash == null) { + base2.append_slash = false; } if (this.options.auth != null) { this.options.slumber.auth = this.options.auth; @@ -64,7 +64,12 @@ if (opts.__query == null) { opts.__query = {}; } - opts.__query.private_token = this.options.token; + if (this.options.token) { + opts.__query.private_token = this.options.token; + } + if (this.options.access_token) { + opts.__query.access_token = this.options.access_token; + } return opts; }; diff --git a/src/ApiBaseHTTP.coffee b/src/ApiBaseHTTP.coffee index dcacdcf..ebe1ef6 100644 --- a/src/ApiBaseHTTP.coffee +++ b/src/ApiBaseHTTP.coffee @@ -12,8 +12,8 @@ class module.exports.ApiBaseHTTP extends ApiBase unless @options.url throw "`url` is mandatory" - unless @options.token - throw "`private_token` is mandatory" + if !@options.token and !@options.access_token + throw "`private_token or access_token` is mandatory" @options.slumber ?= {} @options.slumber.append_slash ?= false @@ -30,7 +30,11 @@ class module.exports.ApiBaseHTTP extends ApiBase prepare_opts: (opts) => opts.__query ?= {} - opts.__query.private_token = @options.token + if @options.token + opts.__query.private_token = @options.token + if @options.access_token + opts.__query.access_token = @options.access_token + return opts fn_wrapper: (fn) => From 7de890e70642422bf9839540ce969afc45c148dc Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 10 Jan 2016 17:13:33 +0800 Subject: [PATCH 2/3] Message:support for broswerify Jira: Detail: Reviewer: Alex Signed-off-by: Alex --- lib/BaseModel.js | 35 ++++++++++++++++++++++++++++++----- src/BaseModel.coffee | 13 ++++++++++++- 2 files changed, 42 insertions(+), 6 deletions(-) diff --git a/lib/BaseModel.js b/lib/BaseModel.js index d621e47..75839ec 100644 --- a/lib/BaseModel.js +++ b/lib/BaseModel.js @@ -1,20 +1,43 @@ -// Generated by CoffeeScript 1.7.1 +// Generated by CoffeeScript 1.10.0 (function() { var debug, - __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; debug = require('debug')('gitlab:BaseModel'); module.exports = (function() { function exports(client) { this.client = client; - this._init = __bind(this._init, this); - this.load = __bind(this.load, this); + this._init = bind(this._init, this); + this.load = bind(this.load, this); this._init(); } exports.prototype.load = function(model) { - return require("./Models/" + model)(this.client); + switch (model) { + case "Groups": + return require("./Models/Groups")(this.client); + case "Issues": + return require("./Models/Issues")(this.client); + case "ProjectDeployKeys": + return require("./Models/ProjectDeployKeys")(this.client); + case "ProjectHooks": + return require("./Models/ProjectHooks")(this.client); + case "ProjectIssues": + return require("./Models/ProjectIssues")(this.client); + case "ProjectMembers": + return require("./Models/ProjectMembers")(this.client); + case "ProjectMergeRequests": + return require("./Models/ProjectMergeRequests")(this.client); + case "ProjectMilestones": + return require("./Models/ProjectMilestones")(this.client); + case "ProjectRepository": + return require("./Models/ProjectRepository")(this.client); + case "Projects": + return require("./Models/Projects")(this.client); + case "Users": + return require("./Models/Users")(this.client); + } }; exports.prototype._init = function() { @@ -33,3 +56,5 @@ })(); }).call(this); + +//# sourceMappingURL=BaseModel.js.map diff --git a/src/BaseModel.coffee b/src/BaseModel.coffee index 557c1a2..67cc785 100644 --- a/src/BaseModel.coffee +++ b/src/BaseModel.coffee @@ -6,7 +6,18 @@ class module.exports do @_init load: (model) => - require("./Models/#{model}") @client + switch model + when "Groups" then require("./Models/Groups") @client + when "Issues" then require("./Models/Issues") @client + when "ProjectDeployKeys" then require("./Models/ProjectDeployKeys") @client + when "ProjectHooks" then require("./Models/ProjectHooks") @client + when "ProjectIssues" then require("./Models/ProjectIssues") @client + when "ProjectMembers" then require("./Models/ProjectMembers") @client + when "ProjectMergeRequests" then require("./Models/ProjectMergeRequests") @client + when "ProjectMilestones" then require("./Models/ProjectMilestones") @client + when "ProjectRepository" then require("./Models/ProjectRepository") @client + when "Projects" then require("./Models/Projects") @client + when "Users" then require("./Models/Users") @client _init: => @debug = require('debug') "gitlab:Models:#{@constructor.name}" From 4e969b34d53d7041fb060cfdbb84ad658aa8ae84 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 11 Jan 2016 13:23:36 +0800 Subject: [PATCH 3/3] Message:support access_token and broswer Jira: Detail: Reviewer: Alex Signed-off-by: Alex --- .gitignore | 27 ++++ README.md | 21 ++- lib/ApiBaseHTTP.js | 332 ++++++++++++++++++++++------------------- lib/BaseModel.js | 108 +++++++------- package.json | 147 +++++++++--------- src/ApiBaseHTTP.coffee | 32 ++-- 6 files changed, 369 insertions(+), 298 deletions(-) diff --git a/.gitignore b/.gitignore index 1b9b91b..afae8a9 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,30 @@ logs results npm-debug.log + + +# Created by .ignore support plugin (hsz.mobi) +### Java template +*.class + +# Mobile Tools for Java (J2ME) +.mtj.tmp/ + +# Package Files # +*.jar +*.war +*.ear + +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +hs_err_pid* + + + +logs/* +.idea +*.iml +target +disconf/* +disconf + + diff --git a/README.md b/README.md index 0cc79bb..72d6921 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -nxt-gitlab +nct-gitlab(fork from nxt-gitlab) =========== - +This is a fork of This is a fork of original node-gitlab repository (https://github.com/moul/node-gitlab), we add some new features and bugfixes. All our changes are submited to the original repository as pull request, but in order to speed up the process of producing a new node and meteor module we decide to host own package. @@ -17,7 +17,7 @@ Install ```bash # Install from npm -npm install nxt-gitlab +npm install nct-gitlab ``` Usage @@ -31,6 +31,11 @@ gitlab = (require 'gitlab') url: 'http://example.com' token: 'abcdefghij123456' +or +gitlab = (require 'gitlab') + url: 'http://example.com' + access_token: 'abcdefghij123456' + # Listing users gitlab.users.all (users) -> console.log "##{user.id}: #{user.email}, #{user.name}, #{user.created_at}" for user in users @@ -50,6 +55,14 @@ var gitlab = require('gitlab')({ token: 'abcdefghij123456' }); +or + +var gitlab = require('gitlab')({ + url: 'http://example.com', + access_token: 'abcdefghij123456' +}); + + // Listing users gitlab.users.all(function(users) { for (var i = 0; i < users.length; i++) { @@ -77,7 +90,7 @@ Use `cake watch` to build files continuously while developing. Contributors ------------ - +- [cccssw](https://github.com/cccssw) - [Dave Irvine](https://github.com/dave-irvine) - [Glavin Wiechert](https://github.com/Glavin001) - [Florian Quiblier](https://github.com/fofoy) diff --git a/lib/ApiBaseHTTP.js b/lib/ApiBaseHTTP.js index ddb15f8..af95451 100644 --- a/lib/ApiBaseHTTP.js +++ b/lib/ApiBaseHTTP.js @@ -1,161 +1,181 @@ // Generated by CoffeeScript 1.10.0 (function() { - var ApiBase, debug, querystring, slumber, - bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, - extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, - hasProp = {}.hasOwnProperty; - - debug = require('debug')('gitlab:ApiBaseHTTP'); - - ApiBase = require('./ApiBase').ApiBase; - - querystring = require('querystring'); - - slumber = require('slumber'); - - module.exports.ApiBaseHTTP = (function(superClass) { - extend(ApiBaseHTTP, superClass); - - function ApiBaseHTTP() { - this.patch = bind(this.patch, this); - this.put = bind(this.put, this); - this.post = bind(this.post, this); - this["delete"] = bind(this["delete"], this); - this.get = bind(this.get, this); - this.fn_wrapper = bind(this.fn_wrapper, this); - this.prepare_opts = bind(this.prepare_opts, this); - this.init = bind(this.init, this); - this.handleOptions = bind(this.handleOptions, this); - return ApiBaseHTTP.__super__.constructor.apply(this, arguments); - } - - ApiBaseHTTP.prototype.handleOptions = function() { - var base, base1, base2; - ApiBaseHTTP.__super__.handleOptions.apply(this, arguments); - if ((base = this.options).base_url == null) { - base.base_url = ''; - } - if (!this.options.url) { - throw "`url` is mandatory"; - } - if (!this.options.token && !this.options.access_token) { - throw "`private_token or access_token` is mandatory"; - } - if ((base1 = this.options).slumber == null) { - base1.slumber = {}; - } - if ((base2 = this.options.slumber).append_slash == null) { - base2.append_slash = false; - } - if (this.options.auth != null) { - this.options.slumber.auth = this.options.auth; - } - return debug("handleOptions()"); - }; - - ApiBaseHTTP.prototype.init = function() { - var api; - ApiBaseHTTP.__super__.init.apply(this, arguments); - api = slumber.API(this.options.url, this.options.slumber); - return this.slumber = api(this.options.base_url); - }; - - ApiBaseHTTP.prototype.prepare_opts = function(opts) { - if (opts.__query == null) { - opts.__query = {}; - } - if (this.options.token) { - opts.__query.private_token = this.options.token; - } - if (this.options.access_token) { - opts.__query.access_token = this.options.access_token; - } - return opts; - }; - - ApiBaseHTTP.prototype.fn_wrapper = function(fn) { - return (function(_this) { - return function(err, response, ret) { - var arity; - if (err) { - debug('an error has occured', err); - } - arity = fn.length; - switch (arity) { - case 1: - return fn(ret); - case 2: - return fn(err, ret); - case 3: - return fn(err, response, ret); - } + var ApiBase, debug, querystring, rest, + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }, + extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, + hasProp = {}.hasOwnProperty; + + debug = require('debug')('gitlab:ApiBaseHTTP'); + + ApiBase = require('./ApiBase').ApiBase; + + querystring = require('querystring'); + + rest = require('rest-js'); + + module.exports.ApiBaseHTTP = (function(superClass) { + extend(ApiBaseHTTP, superClass); + + function ApiBaseHTTP() { + this.patch = bind(this.patch, this); + this.put = bind(this.put, this); + this.post = bind(this.post, this); + this["delete"] = bind(this["delete"], this); + this.get = bind(this.get, this); + this.authPath = bind(this.authPath, this); + this.fn_wrapper = bind(this.fn_wrapper, this); + this.prepare_opts = bind(this.prepare_opts, this); + this.init = bind(this.init, this); + this.handleOptions = bind(this.handleOptions, this); + return ApiBaseHTTP.__super__.constructor.apply(this, arguments); + } + + ApiBaseHTTP.prototype.handleOptions = function() { + var base, base1, base2, base3; + ApiBaseHTTP.__super__.handleOptions.apply(this, arguments); + if ((base = this.options).base_url == null) { + base.base_url = ''; + } + if (!this.options.url) { + throw "`url` is mandatory"; + } + if (!this.options.token && !this.options.access_token) { + throw "`private_token or access_token` is mandatory"; + } + (base1 = this.options).restOption || (base1.restOption = { + defaultFormat: '', + crossDomain: true + }); + if ((base2 = this.options).slumber == null) { + base2.slumber = {}; + } + if ((base3 = this.options.slumber).append_slash == null) { + base3.append_slash = false; + } + if (this.options.auth != null) { + this.options.slumber.auth = this.options.auth; + } + return debug("handleOptions()"); }; - })(this); - }; - - ApiBaseHTTP.prototype.get = function(path, query, fn) { - var opts; - if (query == null) { - query = {}; - } - if (fn == null) { - fn = null; - } - if ('function' === typeof query) { - fn = query; - query = {}; - } - opts = this.prepare_opts(query); - return this.slumber(path).get(opts, this.fn_wrapper(fn)); - }; - - ApiBaseHTTP.prototype["delete"] = function(path, fn) { - var opts; - if (fn == null) { - fn = null; - } - opts = this.prepare_opts({}); - return this.slumber(path)["delete"](opts, this.fn_wrapper(fn)); - }; - - ApiBaseHTTP.prototype.post = function(path, data, fn) { - var opts; - if (data == null) { - data = {}; - } - if (fn == null) { - fn = null; - } - opts = this.prepare_opts(data); - return this.slumber(path).post(opts, this.fn_wrapper(fn)); - }; - - ApiBaseHTTP.prototype.put = function(path, data, fn) { - var opts; - if (data == null) { - data = {}; - } - if (fn == null) { - fn = null; - } - opts = this.prepare_opts(data); - return this.slumber(path).put(opts, this.fn_wrapper(fn)); - }; - - ApiBaseHTTP.prototype.patch = function(path, data, fn) { - var opts; - if (data == null) { - data = {}; - } - if (fn == null) { - fn = null; - } - opts = this.prepare_opts(data); - return this.slumber(path).patch(opts, this.fn_wrapper(fn)); - }; - - return ApiBaseHTTP; - - })(ApiBase); + + ApiBaseHTTP.prototype.init = function() { + ApiBaseHTTP.__super__.init.apply(this, arguments); + return this.slumber = rest(this.options.url + "/" + this.options.base_url + "/", this.options.restOption); + }; + + ApiBaseHTTP.prototype.prepare_opts = function(opts) { + if (opts.__query == null) { + opts.__query = {}; + } + if (this.options.token) { + opts.__query.private_token = this.options.token; + } + if (this.options.access_token) { + opts.__query.access_token = this.options.access_token; + } + return opts; + }; + + ApiBaseHTTP.prototype.fn_wrapper = function(fn) { + return (function(_this) { + return function(err, ret) { + var arity; + if (err) { + debug('an error has occured', err); + } + arity = fn.length; + switch (arity) { + case 1: + return fn(ret); + case 2: + return fn(err, ret); + } + }; + })(this); + }; + + ApiBaseHTTP.prototype.authPath = function(path, query) { + var opts; + opts = this.prepare_opts(query); + if (opts.__query.private_token) { + path += "?private_token=" + opts.__query.private_token; + } + if (opts.__query.access_token) { + path += "?access_token=" + opts.__query.access_token; + } + return path; + }; + + ApiBaseHTTP.prototype.get = function(path, query, fn) { + var opts; + if (query == null) { + query = {}; + } + if (fn == null) { + fn = null; + } + if ('function' === typeof query) { + fn = query; + query = {}; + } + opts = this.prepare_opts(query); + path = this.authPath(path, query); + return this.slumber.read(path, opts, this.fn_wrapper(fn)); + }; + + ApiBaseHTTP.prototype["delete"] = function(path, fn) { + var opts; + if (fn == null) { + fn = null; + } + opts = this.prepare_opts({}); + path = this.authPath(path, {}); + return this.slumber.remove(path, opts, this.fn_wrapper(fn)); + }; + + ApiBaseHTTP.prototype.post = function(path, data, fn) { + var opts; + if (data == null) { + data = {}; + } + if (fn == null) { + fn = null; + } + opts = this.prepare_opts(data); + path = this.authPath(path, data); + return this.slumber.create(path, opts, this.fn_wrapper(fn)); + }; + + ApiBaseHTTP.prototype.put = function(path, data, fn) { + var opts; + if (data == null) { + data = {}; + } + if (fn == null) { + fn = null; + } + opts = this.prepare_opts(data); + path = this.authPath(path, data); + return this.slumber.update(path, opts, this.fn_wrapper(fn)); + }; + + ApiBaseHTTP.prototype.patch = function(path, data, fn) { + var opts; + if (data == null) { + data = {}; + } + if (fn == null) { + fn = null; + } + opts = this.prepare_opts(data); + path = this.authPath(path, data); + return this.slumber.update(path, opts, this.fn_wrapper(fn)); + }; + + return ApiBaseHTTP; + + })(ApiBase); }).call(this); + +//# sourceMappingURL=ApiBaseHTTP.js.map diff --git a/lib/BaseModel.js b/lib/BaseModel.js index 75839ec..4566ead 100644 --- a/lib/BaseModel.js +++ b/lib/BaseModel.js @@ -1,59 +1,59 @@ // Generated by CoffeeScript 1.10.0 (function() { - var debug, - bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; - - debug = require('debug')('gitlab:BaseModel'); - - module.exports = (function() { - function exports(client) { - this.client = client; - this._init = bind(this._init, this); - this.load = bind(this.load, this); - this._init(); - } - - exports.prototype.load = function(model) { - switch (model) { - case "Groups": - return require("./Models/Groups")(this.client); - case "Issues": - return require("./Models/Issues")(this.client); - case "ProjectDeployKeys": - return require("./Models/ProjectDeployKeys")(this.client); - case "ProjectHooks": - return require("./Models/ProjectHooks")(this.client); - case "ProjectIssues": - return require("./Models/ProjectIssues")(this.client); - case "ProjectMembers": - return require("./Models/ProjectMembers")(this.client); - case "ProjectMergeRequests": - return require("./Models/ProjectMergeRequests")(this.client); - case "ProjectMilestones": - return require("./Models/ProjectMilestones")(this.client); - case "ProjectRepository": - return require("./Models/ProjectRepository")(this.client); - case "Projects": - return require("./Models/Projects")(this.client); - case "Users": - return require("./Models/Users")(this.client); - } - }; - - exports.prototype._init = function() { - this.debug = require('debug')("gitlab:Models:" + this.constructor.name); - this.get = this.client.get; - this.post = this.client.post; - this.put = this.client.put; - this["delete"] = this.client["delete"]; - if (this.init != null) { - return this.init(); - } - }; - - return exports; - - })(); + var debug, + bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + + debug = require('debug')('gitlab:BaseModel'); + + module.exports = (function() { + function exports(client) { + this.client = client; + this._init = bind(this._init, this); + this.load = bind(this.load, this); + this._init(); + } + + exports.prototype.load = function(model) { + switch (model) { + case "Groups": + return require("./Models/Groups")(this.client); + case "Issues": + return require("./Models/Issues")(this.client); + case "ProjectDeployKeys": + return require("./Models/ProjectDeployKeys")(this.client); + case "ProjectHooks": + return require("./Models/ProjectHooks")(this.client); + case "ProjectIssues": + return require("./Models/ProjectIssues")(this.client); + case "ProjectMembers": + return require("./Models/ProjectMembers")(this.client); + case "ProjectMergeRequests": + return require("./Models/ProjectMergeRequests")(this.client); + case "ProjectMilestones": + return require("./Models/ProjectMilestones")(this.client); + case "ProjectRepository": + return require("./Models/ProjectRepository")(this.client); + case "Projects": + return require("./Models/Projects")(this.client); + case "Users": + return require("./Models/Users")(this.client); + } + }; + + exports.prototype._init = function() { + this.debug = require('debug')("gitlab:Models:" + this.constructor.name); + this.get = this.client.get; + this.post = this.client.post; + this.put = this.client.put; + this["delete"] = this.client["delete"]; + if (this.init != null) { + return this.init(); + } + }; + + return exports; + + })(); }).call(this); diff --git a/package.json b/package.json index 58a6637..fc0b38f 100644 --- a/package.json +++ b/package.json @@ -1,80 +1,81 @@ { - "name": "nxt-gitlab", - "version": "0.9.0", - "description": "GitLab API Nodejs library. Fork of node-gitlab library with bugfixes and new functionalities", - "main": "lib/index.js", - "directories": { - "example": "examples", - "test": "test" + "name": "nct-gitlab", + "version": "0.9.1", + "description": "GitLab API Nodejs library. Fork of nxt-gitlab which fork node-gitlab library with bugfixes and new functionalities,now avaliable for broswer to use", + "main": "lib/index.js", + "directories": { + "example": "examples", + "test": "test" + }, + "scripts": { + "test": "./node_modules/mocha/bin/mocha tests", + "build": "./node_modules/coffee-script/bin/cake build" + }, + "repository": { + "type": "git", + "url": "https://github.com/Ermlab/nxt-gitlab.git" + }, + "dependencies": { + "debug": "*", + "rest-js": "^1.1.2", + "slumber": "0.3.3" + }, + "devDependencies": { + "coffee-script": "*", + "mocha": "" + }, + "keywords": [ + "gitlab", + "git", + "api", + "request" + ], + "author": { + "name": "Ermlab LLC", + "email": "office@ermlab.com" + }, + "contributors": [ + { + "name": "Manfred Touron ", + "url": "https://github.com/moul" }, - "scripts": { - "test": "./node_modules/mocha/bin/mocha tests", - "build": "./node_modules/coffee-script/bin/cake build" + { + "name": "Dave Irvine", + "url": "https://github.com/dave-irvine" }, - "repository": { - "type": "git", - "url": "https://github.com/Ermlab/nxt-gitlab.git" + { + "name": "Glavin Wiechert", + "url": "https://github.com/Glavin001" }, - "dependencies": { - "debug": "*", - "slumber": "0.3.3" + { + "name": "Florian Quiblier", + "url": "https://github.com/fofoy" }, - "devDependencies": { - "coffee-script": "*", - "mocha": "" + { + "name": "Anthony Heber", + "url": "https://github.com/aheber" }, - "keywords": [ - "gitlab", - "git", - "api", - "request" - ], - "author": { - "name": "Ermlab LLC", - "email": "office@ermlab.com" + { + "name": "Evan Heidtmann", + "url": "https://github.com/ezheidtmann" }, - "contributors": [ - { - "name": "Manfred Touron ", - "url": "https://github.com/moul" - }, - { - "name": "Dave Irvine", - "url": "https://github.com/dave-irvine" - }, - { - "name": "Glavin Wiechert", - "url": "https://github.com/Glavin001" - }, - { - "name": "Florian Quiblier", - "url": "https://github.com/fofoy" - }, - { - "name": "Anthony Heber", - "url": "https://github.com/aheber" - }, - { - "name": "Evan Heidtmann", - "url": "https://github.com/ezheidtmann" - }, - { - "name": "luoqpolyvi", - "url": "https://github.com/luoqpolyvi" - }, - { - "name": "Przemyslaw Gorecki", - "url": "https://github.com/pgorecki" - }, - { - "name": "Mateusz Kalinowski", - "url": "https://github.com/mkkalinowski" - }, - { - "name": "Krzysztof Sopyla", - "url": "https://github.com/ksirg" - } - ], - "license": "MIT", - "readmeFilename": "README.md" -} \ No newline at end of file + { + "name": "luoqpolyvi", + "url": "https://github.com/luoqpolyvi" + }, + { + "name": "Przemyslaw Gorecki", + "url": "https://github.com/pgorecki" + }, + { + "name": "Mateusz Kalinowski", + "url": "https://github.com/mkkalinowski" + }, + { + "name": "Krzysztof Sopyla", + "url": "https://github.com/ksirg" + } + ], + "license": "MIT", + "readmeFilename": "README.md" +} diff --git a/src/ApiBaseHTTP.coffee b/src/ApiBaseHTTP.coffee index ebe1ef6..2341a58 100644 --- a/src/ApiBaseHTTP.coffee +++ b/src/ApiBaseHTTP.coffee @@ -1,8 +1,7 @@ debug = require('debug') 'gitlab:ApiBaseHTTP' {ApiBase} = require './ApiBase' querystring = require 'querystring' -slumber = require 'slumber' - +rest = require 'rest-js' class module.exports.ApiBaseHTTP extends ApiBase handleOptions: => @@ -15,6 +14,7 @@ class module.exports.ApiBaseHTTP extends ApiBase if !@options.token and !@options.access_token throw "`private_token or access_token` is mandatory" + @options.restOption ||= {defaultFormat: '',crossDomain: true,} @options.slumber ?= {} @options.slumber.append_slash ?= false @@ -25,8 +25,7 @@ class module.exports.ApiBaseHTTP extends ApiBase init: => super - api = slumber.API @options.url, @options.slumber - @slumber = api(@options.base_url) + @slumber = rest @options.url+"/"+@options.base_url+"/",@options.restOption prepare_opts: (opts) => opts.__query ?= {} @@ -38,34 +37,45 @@ class module.exports.ApiBaseHTTP extends ApiBase return opts fn_wrapper: (fn) => - return (err, response, ret) => + return (err, ret) => if err debug 'an error has occured', err arity = fn.length switch arity when 1 then fn ret when 2 then fn err, ret - when 3 then fn err, response, ret + authPath:(path,query)=> + opts = @prepare_opts query + if opts.__query.private_token + path+="?private_token="+opts.__query.private_token + if opts.__query.access_token + path+="?access_token="+opts.__query.access_token + return path get: (path, query={}, fn=null) => if 'function' is typeof query fn = query query = {} opts = @prepare_opts query - @slumber(path).get opts, @fn_wrapper fn + path = @authPath path,query + @slumber.read path,opts, @fn_wrapper fn delete: (path, fn=null) => opts = @prepare_opts {} - @slumber(path).delete opts, @fn_wrapper fn + path = @authPath path,{} + @slumber.remove path, opts, @fn_wrapper fn post: (path, data={}, fn=null) => opts = @prepare_opts data - @slumber(path).post opts, @fn_wrapper fn + path = @authPath path,data + @slumber.create path, opts, @fn_wrapper fn put: (path, data={}, fn=null) => opts = @prepare_opts data - @slumber(path).put opts, @fn_wrapper fn + path = @authPath path,data + @slumber.update path, opts, @fn_wrapper fn patch: (path, data={}, fn=null) => opts = @prepare_opts data - @slumber(path).patch opts, @fn_wrapper fn + path = @authPath path,data + @slumber.update path, opts, @fn_wrapper fn