From 5b28f06510d0f926612729f0ae11eaeb39b51b81 Mon Sep 17 00:00:00 2001 From: Dave C-J Date: Thu, 24 Apr 2014 10:04:29 +0100 Subject: [PATCH] Pushbullet changes to make it more obvious what it is now doing... (and fix a couple of things it wasn't) --- social/pushbullet/57-pushbullet.html | 11 +++++++---- social/pushbullet/57-pushbullet.js | 22 ++++++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/social/pushbullet/57-pushbullet.html b/social/pushbullet/57-pushbullet.html index d2f00a67..1689349f 100644 --- a/social/pushbullet/57-pushbullet.html +++ b/social/pushbullet/57-pushbullet.html @@ -32,13 +32,15 @@ +
Note: Using credentials from global pushkey.js file.
@@ -71,7 +73,8 @@ } else { $('#node-config-input-pushkey').val(''); } - + if (data.global) $('#node-tip').show(); + else $('#node-tip').hide(); }); }, oneditsave: function() { diff --git a/social/pushbullet/57-pushbullet.js b/social/pushbullet/57-pushbullet.js index 21a30f96..cf902349 100644 --- a/social/pushbullet/57-pushbullet.js +++ b/social/pushbullet/57-pushbullet.js @@ -36,30 +36,30 @@ function PushbulletNode(n) { if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; } else { if (pushkeys) { this.pushkey = pushkeys.pushbullet; } - else { this.error("No credentials set"); } + else { this.error("No Pushbullet API key set"); } } if ((credentials) && (credentials.hasOwnProperty("deviceid"))) { this.deviceid = credentials.deviceid; } else { if (pushkeys) { this.deviceid = pushkeys.deviceid; } - else { this.warn("No deviceId set"); } + else { this.warn("No deviceid set"); } } - //console.log("Cred:",n.id,this.deviceid,this.pushkey); this.pusher = new PushBullet(this.pushkey); var node = this; this.on("input",function(msg) { var titl = node.title||msg.topic||"Node-RED"; - var dev = msg.deviceID||node.deviceId; + var dev = msg.deviceid||node.deviceid; if (typeof(msg.payload) === 'object') { msg.payload = JSON.stringify(msg.payload); } else { msg.payload = msg.payload.toString(); } - if (node.pushkey && node.deviceid) { + if (node.pushkey && dev) { + console.log(node.pushkey,dev); try { - if (!isNaN(node.deviceId)) { node.deviceId = Number(node.deviceId); } + if (!isNaN(dev)) { dev = Number(dev); } node.pusher.note(dev, titl, msg.payload, function(err, response) { if (err) node.error("Pushbullet error: "+err); - //console.log(response); + console.log(response); }); } catch (err) { @@ -79,7 +79,13 @@ 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!="")})); - } else { + } + 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!="")}));; + } + else { res.send(JSON.stringify({})); } });