Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions lib/redmine.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
/**
* Module dependencies
*/
var request = require('request');
var Url = require('url');
var querystring = require('querystring');

////////////////////////////////////////////////////////////////////////////////////
/**
Expand Down Expand Up @@ -39,7 +39,30 @@ function Redmine(host, config, port) {
}

var baseUrl = Url.format(host);
this._request = request.defaults({baseUrl: baseUrl});
this._request = function (path, opts, callback) {
var fullpath = new Url.URL(baseUrl);
fullpath.pathname += path;
fullpath.search = querystring.stringify(opts.qs);

var http = require(fullpath.protocol.replace(/:$/, ''));
var req = http.request(fullpath, opts, function (res) {
var body = [];
res.on('data', function (chunk){
body.push(chunk);
});
res.on('end', function () {
body = Buffer.concat(body);
if (opts.json) {
body = JSON.parse(body);
}
//console.debug(body);
callback(null, res, body);
});
});
req.on('error', function (err) { callback(err); });
req.end();
return req;
};

if (!config || !(config.apiKey || (config.username && config.password))) {
throw new Error('You should provide an API key or username & password !');
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"author": "wayne@zanran.me",
"license": "GPL-3.0",
"dependencies": {
"debug": "^2.2.0",
"request": "^2.75.0"
"debug": "^2.2.0"
},
"devDependencies": {
"grunt": "^1.0.1",
Expand Down