Update node-red-nodes social nodes to use strict and pass jshint scan

This commit is contained in:
Dave C-J 2014-06-28 23:34:59 +01:00
parent 9b487098ae
commit 62956b0bb8
6 changed files with 462 additions and 453 deletions

View File

@ -14,11 +14,12 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var nma = require('nma');
var util = require('util');
module.exports = function(RED) {
"use strict";
var nma = require('nma');
var util = require('util');
function NMANode(n) {
function NMANode(n) {
RED.nodes.createNode(this,n);
this.title = n.title;
var credentials = RED.nodes.getCredentials(n.id);
@ -42,27 +43,27 @@ function NMANode(n) {
node.warn("NMA credentials not set.");
}
});
}
}
RED.nodes.registerType("nma",NMANode);
RED.nodes.registerType("nma",NMANode);
var querystring = require('querystring');
var querystring = require('querystring');
RED.httpAdmin.get('/nma/:id',function(req,res) {
RED.httpAdmin.get('/nma/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!="")}));
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
} else {
res.send(JSON.stringify({}));
}
});
});
RED.httpAdmin.delete('/nma/:id',function(req,res) {
RED.httpAdmin.delete('/nma/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
});
RED.httpAdmin.post('/nma/:id',function(req,res) {
RED.httpAdmin.post('/nma/:id',function(req,res) {
var body = "";
req.on('data', function(chunk) {
body+=chunk;
@ -70,7 +71,7 @@ RED.httpAdmin.post('/nma/:id',function(req,res) {
req.on('end', function(){
var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.pushkey == "") {
if (newCreds.pushkey === "") {
delete credentials.pushkey;
} else {
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
@ -78,4 +79,5 @@ RED.httpAdmin.post('/nma/:id',function(req,res) {
RED.nodes.addCredentials(req.params.id,credentials);
res.send(200);
});
});
});
}

View File

@ -14,11 +14,12 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var growl = require('growl');
var imagefile = process.env.NODE_RED_HOME+"/public/node-red.png";
module.exports = function(RED) {
"use strict";
var growl = require('growl');
var imagefile = process.env.NODE_RED_HOME+"/public/node-red.png";
function NotifyNode(n) {
function NotifyNode(n) {
RED.nodes.createNode(this,n);
this.title = n.title;
var node = this;
@ -34,6 +35,7 @@ function NotifyNode(n) {
growl(msg.payload, { image: imagefile });
}
});
}
}
RED.nodes.registerType("notify",NotifyNode);
RED.nodes.registerType("notify",NotifyNode);
}

View File

@ -14,26 +14,27 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var Prowl = require('node-prowl');
var util = require('util');
module.exports = function(RED) {
"use strict";
var Prowl = require('node-prowl');
var util = require('util');
// Either add a line like this to settings.js
// prowl: {prowlkey:'My-API-KEY'},
// or create pushkey.js in dir ABOVE node-red, it just needs to be like
// module.exports = {prowlkey:'My-API-KEY'}
// Either add a line like this to settings.js
// prowl: {prowlkey:'My-API-KEY'},
// or create pushkey.js in dir ABOVE node-red, it just needs to be like
// module.exports = {prowlkey:'My-API-KEY'}
try {
try {
var pushkeys = RED.settings.prowl || require(process.env.NODE_RED_HOME+"/../pushkey.js");
}
catch(err) { }
}
catch(err) { }
function ProwlNode(n) {
function ProwlNode(n) {
RED.nodes.createNode(this,n);
this.title = n.title;
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 credentials = RED.nodes.getCredentials(n.id);
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
else {
@ -54,7 +55,7 @@ function ProwlNode(n) {
if (node.pushkey) {
try {
node.prowl.push(msg.payload, titl, { priority: pri }, function(err, remaining) {
if (err) node.error(err);
if (err) { node.error(err); }
node.log( remaining + ' calls to Prowl api during current hour.' );
});
}
@ -66,32 +67,32 @@ function ProwlNode(n) {
node.warn("Prowl credentials not set.");
}
});
}
RED.nodes.registerType("prowl",ProwlNode);
}
RED.nodes.registerType("prowl",ProwlNode);
var querystring = require('querystring');
var querystring = require('querystring');
RED.httpAdmin.get('/prowl/:id',function(req,res) {
RED.httpAdmin.get('/prowl/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!="")}));
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
}
else if (pushkeys && pushkeys.prowlkey) {
RED.nodes.addCredentials(req.params.id,{pushkey:pushkeys.prowlkey,global:true});
credentials = RED.nodes.getCredentials(req.params.id);
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!=""),global:credentials.global}));;
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!==""),global:credentials.global}));
}
else {
res.send(JSON.stringify({}));
}
});
});
RED.httpAdmin.delete('/prowl/:id',function(req,res) {
RED.httpAdmin.delete('/prowl/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
});
RED.httpAdmin.post('/prowl/:id',function(req,res) {
RED.httpAdmin.post('/prowl/:id',function(req,res) {
var body = "";
req.on('data', function(chunk) {
body+=chunk;
@ -99,7 +100,7 @@ RED.httpAdmin.post('/prowl/:id',function(req,res) {
req.on('end', function(){
var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.pushkey == "") {
if (newCreds.pushkey === "") {
delete credentials.pushkey;
} else {
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
@ -107,4 +108,5 @@ RED.httpAdmin.post('/prowl/:id',function(req,res) {
RED.nodes.addCredentials(req.params.id,credentials);
res.send(200);
});
});
});
}

View File

@ -14,22 +14,23 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var PushBullet = require('pushbullet');
var util = require('util');
module.exports = function(RED) {
"use strict";
var PushBullet = require('pushbullet');
var util = require('util');
// Either create pushkey.js in dir ABOVE node-red, it just needs to be like
// module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'}
// or set them per node in the edit dialog
// Either create pushkey.js in dir ABOVE node-red, it just needs to be like
// module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'}
// or set them per node in the edit dialog
try {
try {
var pushkeys = RED.settings.pushbullet || require(process.env.NODE_RED_HOME+"/../pushkey.js");
}
catch(err) {
}
catch(err) {
//util.log("[57-pushbullet.js] Warning: Failed to load global PushBullet credentials");
}
}
function PushbulletNode(n) {
function PushbulletNode(n) {
RED.nodes.createNode(this,n);
this.title = n.title;
var credentials = RED.nodes.getCredentials(n.id);
@ -57,7 +58,7 @@ function PushbulletNode(n) {
try {
if (!isNaN(dev)) { dev = Number(dev); }
node.pusher.note(dev, titl, msg.payload, function(err, response) {
if (err) node.error("Pushbullet error: "+err);
if (err) { node.error("Pushbullet error: "+err); }
//console.log(response);
});
}
@ -69,32 +70,32 @@ function PushbulletNode(n) {
node.warn("Pushbullet credentials not set/found. See node info.");
}
});
}
RED.nodes.registerType("pushbullet",PushbulletNode);
}
RED.nodes.registerType("pushbullet",PushbulletNode);
var querystring = require('querystring');
var querystring = require('querystring');
RED.httpAdmin.get('/pushbullet/:id',function(req,res) {
RED.httpAdmin.get('/pushbullet/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({deviceid:credentials.deviceid,hasPassword:(credentials.pushkey&&credentials.pushkey!="")}));
res.send(JSON.stringify({deviceid:credentials.deviceid,hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
}
else if (pushkeys && pushkeys.pushbullet && pushkeys.deviceid) {
RED.nodes.addCredentials(req.params.id,{pushkey:pushkeys.pushbullet,deviceid:pushkeys.deviceid,global:true});
credentials = RED.nodes.getCredentials(req.params.id);
res.send(JSON.stringify({deviceid:credentials.deviceid,global:credentials.global,hasPassword:(credentials.pushkey&&credentials.pushkey!="")}));;
res.send(JSON.stringify({deviceid:credentials.deviceid,global:credentials.global,hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
}
else {
res.send(JSON.stringify({}));
}
});
});
RED.httpAdmin.delete('/pushbullet/:id',function(req,res) {
RED.httpAdmin.delete('/pushbullet/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
});
RED.httpAdmin.post('/pushbullet/:id',function(req,res) {
RED.httpAdmin.post('/pushbullet/:id',function(req,res) {
var body = "";
req.on('data', function(chunk) {
body+=chunk;
@ -102,12 +103,12 @@ RED.httpAdmin.post('/pushbullet/:id',function(req,res) {
req.on('end', function(){
var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.deviceid == null || newCreds.deviceid == "") {
if (newCreds.deviceid === null || newCreds.deviceid === "") {
delete credentials.deviceid;
} else {
credentials.deviceid = newCreds.deviceid;
}
if (newCreds.pushkey == "") {
if (newCreds.pushkey === "") {
delete credentials.pushkey;
} else {
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
@ -115,4 +116,5 @@ RED.httpAdmin.post('/pushbullet/:id',function(req,res) {
RED.nodes.addCredentials(req.params.id,credentials);
res.send(200);
});
});
});
}

View File

@ -17,14 +17,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
module.exports = function(RED) {
"use strict";
var Pusher = require('pusher');
var PusherClient = require('pusher-client');
var Pusher = require('pusher');
var PusherClient = require('pusher-client');
// Require main module
var RED = require(process.env.NODE_RED_HOME+"/red/red");
//node for subscribing to an event/channel
//node for subscribing to an event/channel
function PusherNode(n) {
// Create a RED node
RED.nodes.createNode(this,n);
@ -54,10 +52,10 @@ var RED = require(process.env.NODE_RED_HOME+"/red/red");
this.on("close", function() {
socket.disconnect();
});
}
}
//Node for sending Pusher events
function PusherNodeSend(n) {
//Node for sending Pusher events
function PusherNodeSend(n) {
// Create a RED node
RED.nodes.createNode(this,n);
@ -93,34 +91,34 @@ function PusherNodeSend(n) {
}
//debugging on the output:
var displayResult = function(result) {
var displayResult = function(result) {
node.log(result);
};
};
var displayError = function(err) {
var displayError = function(err) {
node.log("Error: "+err);
};
};
RED.nodes.registerType("pusher in",PusherNode);
RED.nodes.registerType("pusher out",PusherNodeSend);
RED.nodes.registerType("pusher in",PusherNode);
RED.nodes.registerType("pusher out",PusherNodeSend);
var querystring = require('querystring');
var querystring = require('querystring');
RED.httpAdmin.get('/pusher/:id',function(req,res) {
RED.httpAdmin.get('/pusher/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({pusherappid:credentials.pusherappid,pusherappsecret:credentials.pusherappsecret, pusherappkey:credentials.pusherappkey, pusherappkey_sub:credentials.pusherappkey_sub}));
} else {
res.send(JSON.stringify({}));
}
});
});
RED.httpAdmin.delete('/pusher/:id',function(req,res) {
RED.httpAdmin.delete('/pusher/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
});
RED.httpAdmin.post('/pusher/:id',function(req,res) {
RED.httpAdmin.post('/pusher/:id',function(req,res) {
var body = "";
req.on('data', function(chunk) {
body+=chunk;
@ -129,24 +127,24 @@ RED.httpAdmin.post('/pusher/:id',function(req,res) {
var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.pusherappid == null || newCreds.pusherappid == "") {
if (newCreds.pusherappid === null || newCreds.pusherappid === "") {
delete credentials.pusherappid;
} else {
credentials.pusherappid = newCreds.pusherappid;
}
if (newCreds.pusherappkey == "") {
if (newCreds.pusherappkey === "") {
delete credentials.pusherappkey;
} else {
credentials.pusherappkey = newCreds.pusherappkey||credentials.pusherappkey;
}
if (newCreds.pusherappsecret == "") {
if (newCreds.pusherappsecret === "") {
delete credentials.pusherappsecret;
} else {
credentials.pusherappsecret = newCreds.pusherappsecret||credentials.pusherappsecret;
}
if (newCreds.pusherappkey_sub == "") {
if (newCreds.pusherappkey_sub === "") {
delete credentials.pusherappkey_sub;
} else {
credentials.pusherappkey_sub = newCreds.pusherappkey_sub||credentials.pusherappkey_sub;
@ -155,4 +153,5 @@ RED.httpAdmin.post('/pusher/:id',function(req,res) {
RED.nodes.addCredentials(req.params.id,credentials);
res.send(200);
});
});
});
}

View File

@ -14,11 +14,12 @@
* limitations under the License.
**/
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var PushOver = require('pushover-notifications');
var util = require('util');
module.exports = function(RED) {
"use strict";
var PushOver = require('pushover-notifications');
var util = require('util');
function PushoverNode(n) {
function PushoverNode(n) {
RED.nodes.createNode(this,n);
this.title = n.title;
this.priority = n.priority;
@ -59,7 +60,7 @@ function PushoverNode(n) {
};
//console.log("Sending",pushmsg);
pusher.send( pushmsg, function(err, response) {
if (err) node.error("Pushover Error: "+err);
if (err) { node.error("Pushover Error: "+err); }
//console.log(response);
});
}
@ -67,26 +68,26 @@ function PushoverNode(n) {
node.warn("Pushover credentials not set.");
}
});
}
RED.nodes.registerType("pushover",PushoverNode);
}
RED.nodes.registerType("pushover",PushoverNode);
var querystring = require('querystring');
var querystring = require('querystring');
RED.httpAdmin.get('/pushover/:id',function(req,res) {
RED.httpAdmin.get('/pushover/:id',function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) {
res.send(JSON.stringify({deviceid:credentials.deviceid,hasPassword:(credentials.pushkey&&credentials.pushkey!="")}));
res.send(JSON.stringify({deviceid:credentials.deviceid,hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
} else {
res.send(JSON.stringify({}));
}
});
});
RED.httpAdmin.delete('/pushover/:id',function(req,res) {
RED.httpAdmin.delete('/pushover/:id',function(req,res) {
RED.nodes.deleteCredentials(req.params.id);
res.send(200);
});
});
RED.httpAdmin.post('/pushover/:id',function(req,res) {
RED.httpAdmin.post('/pushover/:id',function(req,res) {
var body = "";
req.on('data', function(chunk) {
body+=chunk;
@ -94,12 +95,12 @@ RED.httpAdmin.post('/pushover/:id',function(req,res) {
req.on('end', function(){
var newCreds = querystring.parse(body);
var credentials = RED.nodes.getCredentials(req.params.id)||{};
if (newCreds.deviceid == null || newCreds.deviceid == "") {
if (newCreds.deviceid === null || newCreds.deviceid === "") {
delete credentials.deviceid;
} else {
credentials.deviceid = newCreds.deviceid;
}
if (newCreds.pushkey == "") {
if (newCreds.pushkey === "") {
delete credentials.pushkey;
} else {
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
@ -107,4 +108,5 @@ RED.httpAdmin.post('/pushover/:id',function(req,res) {
RED.nodes.addCredentials(req.params.id,credentials);
res.send(200);
});
});
});
}