Skip to content

Instantly share code, notes, and snippets.

@jamescarr
Last active December 27, 2015 11:49
Show Gist options
  • Select an option

  • Save jamescarr/7321326 to your computer and use it in GitHub Desktop.

Select an option

Save jamescarr/7321326 to your computer and use it in GitHub Desktop.
function parseThatXML(content, rootElement) {
var result = {}, $el = $(content).find(rootElement);
$el.children().each(function() {
result[this.nodeName] = $(this).text();
});
return result;
}
var Zap = {
customers_post_poll:function(bundle, cb) {
var customers = $.parseXML(bundle.response.content).getElementsByTagName('Customer');
var lookupCustomers = _.map($(customers), function(element) {
var CustomerID = $(element).find('CustomerID').text();
var req = bundle.request;
req.url = req.url + '/'+ CustomerID
return function(next) {
z.request(req, function(err, response) {
var customer = parseThatXML($.parseXML(response.content), 'Customer')
next(err, customer);
});
}
});
async.parallel(lookupCustomers, function(err, results) {
cb(err, results);
})
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment