mirror of
https://github.com/Hopiu/webapi-eca.git
synced 2026-03-17 06:20:23 +00:00
31 lines
898 B
JavaScript
31 lines
898 B
JavaScript
'use strict';
|
|
|
|
var needle = require('needle');
|
|
|
|
/**
|
|
* Call any arbitrary webAPI.
|
|
* @param {Object} args the required function arguments object
|
|
* @param {String} args.url the required webAPI url
|
|
* @param {Object} [args.data] the data to be posted
|
|
* @param {Object} [args.credentials] optional credentials
|
|
* @param {String} [args.credentials.username] optional username
|
|
* @param {String} [args.credentials.password] optional password
|
|
*/
|
|
function call(args) {
|
|
if(!args || !args.url) {
|
|
console.error('ERROR in WebAPI AM call: Too few arguments!');
|
|
return null;
|
|
}
|
|
needle.post(args.url,
|
|
args.data,
|
|
args.credentials,
|
|
function(error, response, body) {
|
|
if (!error) console.log('Successful webAPI AM call to ' + args.url);
|
|
else console.error('Error during webAPI AM call to ' + args.url
|
|
+ ': ' + error.message);
|
|
}
|
|
);
|
|
};
|
|
|
|
exports.call = call;
|
|
|