1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Forced payload to be strings for Prowl node

Fixes #26
This commit is contained in:
Dave C-J 2014-02-08 13:31:00 +00:00
parent b1f9a3ce5e
commit b1b230eb37

View File

@ -24,44 +24,45 @@ var util = require('util');
// module.exports = {prowlkey:'My-API-KEY'} // module.exports = {prowlkey:'My-API-KEY'}
try { try {
var pushkey = RED.settings.prowl || require(process.env.NODE_RED_HOME+"/../pushkey.js"); var pushkey = RED.settings.prowl || require(process.env.NODE_RED_HOME+"/../pushkey.js");
} }
catch(err) { catch(err) {
util.log("[57-prowl.js] Error: Failed to load Prowl credentials"); util.log("[57-prowl.js] Error: Failed to load Prowl credentials");
} }
if (pushkey) { if (pushkey) {
var prowl = new Prowl(pushkey.prowlkey); var prowl = new Prowl(pushkey.prowlkey);
} }
function ProwlNode(n) { function ProwlNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.title = n.title; this.title = n.title;
this.priority = parseInt(n.priority); this.priority = parseInt(n.priority);
if (this.priority > 2) this.priority = 2; if (this.priority > 2) this.priority = 2;
if (this.priority < -2) this.priority = -2; if (this.priority < -2) this.priority = -2;
var node = this; var node = this;
this.on("input",function(msg) { this.on("input",function(msg) {
var titl = this.title||msg.topic||"Node-RED"; var titl = this.title||msg.topic||"Node-RED";
var pri = msg.priority||this.priority; var pri = msg.priority||this.priority;
if (typeof(msg.payload) == 'object') { if (typeof(msg.payload) == 'object') {
msg.payload = JSON.stringify(msg.payload); msg.payload = JSON.stringify(msg.payload);
} }
if (pushkey) { else { msg.payload = msg.payload.toString(); }
try { if (pushkey) {
prowl.push(msg.payload, titl, { priority: pri }, function(err, remaining) { try {
if (err) node.error(err); prowl.push(msg.payload, titl, { priority: pri }, function(err, remaining) {
node.log( remaining + ' calls to Prowl api during current hour.' ); if (err) node.error(err);
}); node.log( remaining + ' calls to Prowl api during current hour.' );
} });
catch (err) { }
node.error(err); catch (err) {
} node.error(err);
} }
else { }
node.warn("Prowl credentials not set/found. See node info."); else {
} node.warn("Prowl credentials not set/found. See node info.");
}); }
});
} }
RED.nodes.registerType("prowl",ProwlNode); RED.nodes.registerType("prowl",ProwlNode);