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
\ No newline at end of file
key.js
node_modules
'use strict';
var qs = require('querystring');
var https = require('https');
var request = require('request');
var errorHandler = require('./error-handler');
/*
......@@ -127,41 +127,37 @@ Client.prototype.makeRequest = function(obj) {
var versionPaths = {
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
var options = {
hostname: 'api.challonge.com',
path: path,
baseUrl: 'https://api.challonge.com',
url: path,
qs: obj,
method: method,
headers: {
'Content-Length': 0 // server throws nginx error without a content-length
}
};
var req = https.request(options, function(res) {
// store the chunked data as it comes back
var resData = '';
res.on('data', function(chunk) {
resData += chunk;
});
res.on('end', function() {
// error
if (res.statusCode !== 200) {
errorHandler.handle(res, resData, callback, self.options.get('format'));
request.get(options, function (error, response, body) {
if(error) {
return;
}
if(response.statusCode !== 200){
errorHandler.handle(response, body, callback, self.options.get('format'));
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') {
resData = JSON.parse(resData);
if (self.options.get('massageProperties')) {
resData = convertProperties(resData,UnderscoreToCamel);
}
}
callback(null, resData); //no error, so no err object
});
}
callback(null, resData); //no error, so no err object
});
req.end();
};
\ No newline at end of file
......@@ -3,10 +3,28 @@
"description": "Wrapper for the challong api",
"author": "Aaron Tiwell <aaron.tidwell@gmail.com>",
"main": "./lib/challonge.js",
"version": "1.0.0",
"version": "1.0.1",
"dependencies": {
"request": "^2.67.0"
},
"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