Last active
April 5, 2016 13:28
-
-
Save zubairov/e72860e674260ee680b1cdbba8e83083 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Q = require('q'); | |
var elasticio = require('elasticio-node'); | |
var messages = elasticio.messages; | |
var soap = require('soap'); | |
exports.process = processTrigger; | |
function processTrigger(msg, cfg) { | |
var self = this; | |
var username = cfg.username; | |
var password = cfg.password; | |
var url = cfg.url; | |
var args = {parameters: {}}; | |
/* | |
function emitData() { | |
var body = { | |
greeting: 'Kuk ' | |
}; | |
var data = messages.newMessageWithBody(body); | |
console.log('Emitting data'); | |
self.emit('data', data); | |
} | |
*/ | |
function emitError(e) { | |
console.log('Oops! Error occurred', e); | |
self.emit('error', e); | |
} | |
function emitEnd() { | |
console.log('Finished execution'); | |
self.emit('end'); | |
} | |
var soapCall = function (args) { | |
var deferred = Q.defer(); | |
console.log('Invoking promise'); | |
soap.createClient('http://www.webservicex.com/globalweather.asmx?wsdl', function (err, client) { | |
console.log('Invoked soap.createClient '); | |
if (err) | |
deferred.reject(new Error(err)); | |
//client.setSecurity(new soap.BasicAuthSecurity('soapipbx', 'foo')); | |
client.GetWeather({ | |
CityName: 'Berlin', | |
CountryName: 'Germany' | |
}, function (err, result) { | |
if (err) | |
deferred.reject(new Error(err)); | |
else | |
deferred.resolve(result); | |
}); | |
}); | |
return deferred.promise; | |
}; | |
console.log('--- promise based sample ---'); | |
soapCall(args).then( | |
function (result) { | |
console.log(JSON.stringify(result, null, 2)); | |
var body = { | |
greeting: 'Kuk ' | |
}; | |
var data = messages.newMessageWithBody(body); | |
console.log('Emitting data=%j', data); | |
//self.emit('data', data); | |
} | |
).fail(emitError).done(emitEnd); | |
//Q().then(emitData).fail(emitError).done(emitEnd); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment