Skip to content

Commit

Permalink
Update pushbullet to use latest 0.4 npm and allow iden as well as id
Browse files Browse the repository at this point in the history
  • Loading branch information
dceejay committed Feb 14, 2014
1 parent 66598a6 commit 4a53c20
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 33 deletions.
13 changes: 7 additions & 6 deletions social/pushbullet/57-pushbullet.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
</script>

<script type="text/x-red" data-help-name="pushbullet">
<p>Uses PushBullet to push the <b>msg.payload</b> to an Android device that has PushBullet app installed.</p>
<p>Optionally uses <b>msg.topic</b> to set the title, if not already set in the properties.</p>
<p>You MUST configure both your API key and the target device ID. Either into settings.js like this</p>
<p><pre>pushbullet: { pushbullet:'My-API-KEY', deviceid:'12345' },</pre></p>
<p>Or as a pushkey.js file in the directory <b>above</b> node-red.<p>
<p><pre>module.exports = { pushbullet:'My-API-KEY', deviceid:'12345' }</pre></p>
<p>Uses PushBullet to push the <b>msg.payload</b> to an Android device that has PushBullet app installed.</p>
<p>Optionally uses <b>msg.topic</b> to set the title, if not already set in the properties.</p>
<p>You MUST configure both your API key and the target device ID. Either into settings.js like this</p>
<p><pre>pushbullet: { pushbullet:'My-API-KEY', deviceid:'xyzzyWabc' },</pre></p>
<p>Or as a pushkey.js file in the directory <b>above</b> node-red.<p>
<p><pre>module.exports = { pushbullet:'My-API-KEY', deviceid:'xyzzyWabc' }</pre></p>
<p>The deviceid can be found by hovering over you required device on the <a href="https://www.pushbullet.com/">PushBullet website</a>.</p>
</script>

<script type="text/javascript">
Expand Down
55 changes: 28 additions & 27 deletions social/pushbullet/57-pushbullet.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,42 @@ var util = require('util');
// module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'}

try {
var pushkey = RED.settings.pushbullet || require(process.env.NODE_RED_HOME+"/../pushkey.js");
var pushkey = RED.settings.pushbullet || require(process.env.NODE_RED_HOME+"/../pushkey.js");
}
catch(err) {
util.log("[57-pushbullet.js] Error: Failed to load PushBullet credentials");
util.log("[57-pushbullet.js] Error: Failed to load PushBullet credentials");
}

if (pushkey) {
var pusher = new PushBullet(pushkey.pushbullet);
var deviceId = pushkey.deviceid;
var pusher = new PushBullet(pushkey.pushbullet);
var deviceId = pushkey.deviceid;
}

function PushbulletNode(n) {
RED.nodes.createNode(this,n);
this.title = n.title;
var node = this;
this.on("input",function(msg) {
var titl = this.title||msg.topic||"Node-RED";
if (typeof(msg.payload) == 'object') {
msg.payload = JSON.stringify(msg.payload);
}
if (pushkey) {
try {
pusher.note(deviceId, titl, msg.payload, function(err, response) {
if (err) node.error(err);
console.log(response);
});
}
catch (err) {
node.error(err);
}
}
else {
node.warn("Pushbullet credentials not set/found. See node info.");
}
});
RED.nodes.createNode(this,n);
this.title = n.title;
var node = this;
this.on("input",function(msg) {
var titl = this.title||msg.topic||"Node-RED";
if (typeof(msg.payload) == 'object') {
msg.payload = JSON.stringify(msg.payload);
}
if (pushkey.pushbullet && pushkey.deviceid) {
try {
if (!isNaN(deviceId)) { deviceId = Number(deviceId); }
pusher.note(deviceId, titl, msg.payload, function(err, response) {
if (err) node.error(err);
console.log(response);
});
}
catch (err) {
node.error(err);
}
}
else {
node.warn("Pushbullet credentials not set/found. See node info.");
}
});
}

RED.nodes.registerType("pushbullet",PushbulletNode);

0 comments on commit 4a53c20

Please sign in to comment.