Merge pull request #1968 from KenanSulayman/patch-1

Refactors APIHandler:callAPI
pull/1952/merge
Marcel Klehr 2013-10-25 06:34:23 -07:00
commit f532c1c6fb
1 changed files with 4 additions and 6 deletions

View File

@ -346,11 +346,9 @@ exports.handle = function(apiVersion, functionName, fields, req, res)
function callAPI(apiVersion, functionName, fields, req, res) function callAPI(apiVersion, functionName, fields, req, res)
{ {
//put the function parameters in an array //put the function parameters in an array
var functionParams = []; var functionParams = version[apiVersion][functionName].map(function (field) {
for(var i=0;i<version[apiVersion][functionName].length;i++) return fields[field]
{ })
functionParams.push(fields[ version[apiVersion][functionName][i] ]);
}
//add a callback function to handle the response //add a callback function to handle the response
functionParams.push(function(err, data) functionParams.push(function(err, data)
@ -377,5 +375,5 @@ function callAPI(apiVersion, functionName, fields, req, res)
}); });
//call the api function //call the api function
api[functionName](functionParams[0],functionParams[1],functionParams[2],functionParams[3],functionParams[4]); api[functionName].apply(this, functionParams);
} }