Commit b5b6ccdf authored by Aaron Tidwell's avatar Aaron Tidwell

fixed randomize

parent b8d75723
...@@ -66,7 +66,7 @@ Client.prototype.makeRequest = function(obj) { ...@@ -66,7 +66,7 @@ Client.prototype.makeRequest = function(obj) {
} }
}; };
console.log('making request to ', path, options); console.log('making request to ', options);
var req = https.request(options, function(res) { var req = https.request(options, function(res) {
// store the chunked data as it comes back // store the chunked data as it comes back
......
...@@ -59,19 +59,8 @@ Participants.prototype.destroy = function(obj) { ...@@ -59,19 +59,8 @@ Participants.prototype.destroy = function(obj) {
}; };
Participants.prototype.randomize = function(obj) { Participants.prototype.randomize = function(obj) {
//workaround to exec CURL, not the best obj.path = '/v1/tournaments/'+obj.id+'/participants/randomize';
var cmd = 'curl -d "" https://'+this.options.get('username')+':'+this.options.get('apiKey')+'@api.challonge.com/v1/tournaments/'+obj.id+'/participants/randomize.'+this.options.get('format'); delete obj.id;
function process(error, stdout, stderr) { obj.method = 'POST';
var data = JSON.parse(stdout); this.makeRequest(obj);
obj.callback(null, data);
}
exec(cmd, process);
/***********BUSTED*********/
// [Error: Parse Error] bytesParsed: 0, code: 'HPE_INVALID_CONSTANT'
// obj.path = 'v1/tournaments/'+obj.id+'/participants/randomize';
// delete obj.id;
// obj.method = 'PUT';
// this.makeRequest(obj);
} }
\ No newline at end of file
...@@ -50,26 +50,11 @@ client.tournaments.create({ ...@@ -50,26 +50,11 @@ client.tournaments.create({
--- ---
###Challonge docs: http://api.challonge.com/v1 ###Challonge docs: http://api.challonge.com/v1
----
##Comments
Server throws nginx error without a content-length in header.
All methods are qs based, so I would assume nginx would ignore content-length for api requests (it is optional in the spec). I lost about 20 mins to this one because node doesn't auto-calculate content-length in the core https lib.
---
##Etc
The other language wrappers are AWESOME. I consulted their sources often when trying to figure out WTF the API actually wanted. One of the most important examples was from the python lib's api.py - it confirmed I wasn't insane about how to construct the querystring. Ruby and PHP provide native ways to stringify objects in ```object[property]=value``` syntax, but python and node don't.
---
##TODO ##TODO
* move /v1/tournaments to config * move /v1/tournaments to config
* abstract path suffix for partcipants, matches * abstract path suffix for partcipants, matches
* abstract destroy of qs params * abstract destroy of qs params
1. fix randomize
2. support camelCase -> under_score params 2. support camelCase -> under_score params
3. validate required params 3. validate required params
4. docs 4. docs
...@@ -86,15 +71,6 @@ http://api.challonge.com/v1/documents/participants/create shows participant_id a ...@@ -86,15 +71,6 @@ http://api.challonge.com/v1/documents/participants/create shows participant_id a
http://api.challonge.com/v1/documents/participants/randomize shows participant_id as a required field when the server does not respect passing it, and is not required. http://api.challonge.com/v1/documents/participants/randomize shows participant_id as a required field when the server does not respect passing it, and is not required.
Also, I think the server might be sending an invalid content-length header on randomize somehow. Node doesn't handle invalid headers well, will look into the causes for:
```
[Error: Parse Error] bytesParsed: 0, code: 'HPE_INVALID_CONSTANT' in node.
```
hrm, works via curl:
curl -d '' https://tidwell:key@api.challonge.com/v1/tournaments/sometesttourney1/participants/randomize.json
--- ---
####The structure of this api wrapper is ripped off from https://github.com/nodejitsu/nodejitsu-api ####The structure of this api wrapper is ripped off from https://github.com/nodejitsu/nodejitsu-api
\ No newline at end of file
var challonge = require('./../'); var challonge = require('./../');
var client = challonge.createClient({ var client = challonge.createClient({
username: 'tidwell',
apiKey: require('./../key.js'), apiKey: require('./../key.js'),
format: 'json' format: 'json'
}); });
......
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