Skip to content

Commit

Permalink
bug fix for aggregating chunks
Browse files Browse the repository at this point in the history
  • Loading branch information
scriptnull committed Jun 24, 2015
1 parent 0169fcd commit a145298
Showing 1 changed file with 55 additions and 52 deletions.
107 changes: 55 additions & 52 deletions machines/submit.js
Expand Up @@ -11,40 +11,40 @@ module.exports = {


inputs: {
apiKey : {
example : 'AAAAAAAAAAAAAA' ,
description : 'Your HackerRank API Key' ,
required : true
} ,
source : {
example : 'using System;class MyClass{static void Main(string[] args) {System.Console.WriteLine(\"Hello World!\\n\");}}' ,
description : 'source code, which needs to be compiled and run against the provided test cases.' ,
required : true
} ,
language : {
example : 9 ,
description : 'The language key for the language, the submission is made in.Get lang key from http://api.hackerrank.com/checker/languages.json' ,
required : true
} ,
testcases : {
example : [],
description : 'A valid JSON, which on parse should result in a list of strings.' ,
required : true
} ,
wait : {
example : true ,
description : 'if true , response will be sent after compilation and run.' ,
required : false
} ,
callbackUrl : {
example : 'http://example.com/callback' ,
description : 'A callback url, on which the submission response will be posted as a JSON string under `data` parameter.',
required : false
} ,
format : {
example : 'json' ,
description : 'must be either json or xml.' ,
required : false
apiKey: {
example: 'AAAAAAAAAAAAAA',
description: 'Your HackerRank API Key',
required: true
},
source: {
example: 'using System;class MyClass{static void Main(string[] args) {System.Console.WriteLine(\"Hello World!\\n\");}}',
description: 'source code, which needs to be compiled and run against the provided test cases.',
required: true
},
language: {
example: 9,
description: 'The language key for the language, the submission is made in.Get lang key from http://api.hackerrank.com/checker/languages.json',
required: true
},
testcases: {
example: [],
description: 'A valid JSON, which on parse should result in a list of strings.',
required: true
},
wait: {
example: true,
description: 'if true , response will be sent after compilation and run.',
required: false
},
callbackUrl: {
example: 'http://example.com/callback',
description: 'A callback url, on which the submission response will be posted as a JSON string under `data` parameter.',
required: false
},
format: {
example: 'json',
description: 'must be either json or xml.',
required: false
}
},

Expand All @@ -60,23 +60,23 @@ module.exports = {

success: {
description: 'Done.'
}
}

},


fn: function (inputs,exits) {
fn: function (inputs, exits) {
var querystring = require('querystring');
var http = require('http');

var data = querystring.stringify({
api_key : inputs.apiKey ,
source : inputs.source ,
lang : inputs.language ,
testcases : JSON.stringify(inputs.testcases) ,
wait : inputs.wait ,
callback_url : inputs.callbackUrl ,
format : inputs.format
api_key: inputs.apiKey,
source: inputs.source,
lang: inputs.language,
testcases: JSON.stringify(inputs.testcases),
wait: inputs.wait,
callback_url: inputs.callbackUrl,
format: inputs.format
});

var options = {
Expand All @@ -87,18 +87,21 @@ module.exports = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': data.length
}
}
};

var req = http.request(options , function(res){
res.on('data' , function(chunk){
return exits.success(chunk.toString());
var response = '';
var req = http.request(options, function (res) {
res.on('data', function (chunk) {
response += chunk.toString();
});
res.on('end', function () {
return exits.success(response.toString());
});
res.on('error' , function(err){
return exits.error(err );
res.on('error', function (err) {
return exits.error(err);
});
});
req.on('error' , function(err){
req.on('error', function (err) {
return exists.error(err);
})
req.write(data);
Expand Down

0 comments on commit a145298

Please sign in to comment.