Last active
February 17, 2016 22:39
-
-
Save Mozu-CS/7b66f35ba07527e4442a to your computer and use it in GitHub Desktop.
Calling a third party from Arc.js
This file contains hidden or 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 serviceCall = require('../../util/needleRequest').makeSampleCall; | |
module.exports = function (context, callback) { | |
var sampleData = "<value>" + context.request.url + "</value>"; | |
serviceCall(sampleData) | |
.then(function (responseFromCall) { | |
console.log(responseFromCall); | |
callback(); | |
}) | |
.catch(function(err) { | |
console.error(err); | |
callback(); | |
}); | |
} |
This file contains hidden or 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 needle = require('needle'); | |
exports.makeSampleCall = function (bodyStr) { | |
var promise = new Promise(function (resolve, reject) { | |
try { | |
needle.post('https://a24e6628.ngrok.io/mozu.events', | |
{ | |
headers: { | |
'Content-Type': 'text/xml' | |
}, | |
body: bodyStr | |
}, function (error, response) { | |
if (!error && response.statusCode == 200) { | |
console.log('Inside needle request'); | |
resolve(response); | |
} else { | |
reject(response.statusCode); | |
} | |
}); | |
} catch (err) { | |
reject(console.error(err)); | |
} | |
}); | |
return promise; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment