Skip to content

Instantly share code, notes, and snippets.

@bmuller
Last active July 9, 2017 15:57
Show Gist options
  • Save bmuller/29735cda5a043fabf63446f1bbf75d51 to your computer and use it in GitHub Desktop.
Save bmuller/29735cda5a043fabf63446f1bbf75d51 to your computer and use it in GitHub Desktop.
For lasership package notifications on lasership
var http = require('http');
module['exports'] = function myService (hook) {
http.get('http://www.lasership.com/track/' + hook.params.id + '/json', function(res) {
res.setEncoding('utf8');
let rawData = '';
res.on('data', function(chunk) { rawData += chunk; });
res.on('end', function() {
const json = JSON.parse(rawData);
feed = "<?xml version=\"1.0\"?><rss version=\"2.0\"><channel><title>LaserShip tracking for " + hook.params.id + "</title>";
feed += "<link>http://hook.io/bmuller/lasership</link><description></description>";
for(var i=0; i<json['Events'].length; i++) {
var event = json['Events'][i];
feed += "<item><title>" + event['EventLongText'] + " in " + event['City'] + ", " + event['State'] + "</title>";
feed += "<link>https://hook.io/bmuller/lasership/" + hook.params.id + "/" + event['DateTime'] + "</link>";
feed += "<guid>https://hook.io/bmuller/lasership/" + hook.params.id + "/" + event['DateTime'] + "</guid>";
feed += "<description>in " + event['City'] + ", " + event['State'] + "</description></item>";
}
feed += "</channel></rss>";
hook.res.writeHead(200, { 'Content-Type': 'application/rss+xml; charset=UTF-8'});
hook.res.end(feed);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment