Last active
July 9, 2017 15:57
-
-
Save bmuller/29735cda5a043fabf63446f1bbf75d51 to your computer and use it in GitHub Desktop.
For lasership package notifications on lasership
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 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