Commit 7a8beadc authored by Aaron Tidwell's avatar Aaron Tidwell Committed by GitHub

Merge pull request #18 from patresi/master

Make requests through requestjs lib to support proxies
parents f75aa593 08ed763b
key.js key.js
\ No newline at end of file node_modules
'use strict'; 'use strict';
var qs = require('querystring'); var qs = require('querystring');
var https = require('https'); var request = require('request');
var errorHandler = require('./error-handler'); var errorHandler = require('./error-handler');
/* /*
...@@ -127,41 +127,37 @@ Client.prototype.makeRequest = function(obj) { ...@@ -127,41 +127,37 @@ Client.prototype.makeRequest = function(obj) {
var versionPaths = { var versionPaths = {
1: '/v1/tournaments' 1: '/v1/tournaments'
}; };
path = versionPaths[this.options.get('version')] + (path ? path : '') + '.' + this.options.get('format') + '?' + qs.stringify(obj) + compiledParams; path = versionPaths[this.options.get('version')] + (path ? path : '') + '.' + this.options.get('format');
// create options for the https call // create options for the https call
var options = { var options = {
hostname: 'api.challonge.com', baseUrl: 'https://api.challonge.com',
path: path, url: path,
qs: obj,
method: method, method: method,
headers: { headers: {
'Content-Length': 0 // server throws nginx error without a content-length 'Content-Length': 0 // server throws nginx error without a content-length
} }
}; };
var req = https.request(options, function(res) { request.get(options, function (error, response, body) {
// store the chunked data as it comes back if(error) {
var resData = ''; return;
res.on('data', function(chunk) { }
resData += chunk;
}); if(response.statusCode !== 200){
errorHandler.handle(response, body, callback, self.options.get('format'));
res.on('end', function() {
// error
if (res.statusCode !== 200) {
errorHandler.handle(res, resData, callback, self.options.get('format'));
return; return;
}
var resData = '';
if (self.options.get('format') === 'json') {
resData = JSON.parse(body);
if (self.options.get('massageProperties')) {
resData = convertProperties(resData,UnderscoreToCamel);
} }
// 200 ok }
if (self.options.get('format') == 'json') { callback(null, resData); //no error, so no err object
resData = JSON.parse(resData);
if (self.options.get('massageProperties')) {
resData = convertProperties(resData,UnderscoreToCamel);
}
}
callback(null, resData); //no error, so no err object
});
}); });
req.end();
}; };
\ No newline at end of file
...@@ -3,10 +3,28 @@ ...@@ -3,10 +3,28 @@
"description": "Wrapper for the challong api", "description": "Wrapper for the challong api",
"author": "Aaron Tiwell <aaron.tidwell@gmail.com>", "author": "Aaron Tiwell <aaron.tidwell@gmail.com>",
"main": "./lib/challonge.js", "main": "./lib/challonge.js",
"version": "1.0.0", "version": "1.0.1",
"dependencies": { "dependencies": {
"request": "^2.67.0"
}, },
"devDependencies": { "devDependencies": {
"jshint": "^2.8.0"
}, },
"engine": "node >= 0.10.x" "engine": "node >= 0.10.x",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "jshint --show-non-errors lib"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Tidwell/node-challonge.git"
},
"license": "ISC",
"bugs": {
"url": "https://github.com/Tidwell/node-challonge/issues"
},
"homepage": "https://github.com/Tidwell/node-challonge#readme"
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment