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

Refactor deviceId -> deviceIdent

Since the deviceId will be deprecated, better move to the deviceIdent
This commit is contained in:
Antoine Aflalo 2014-04-20 15:24:34 +03:00
parent 02d2b152e2
commit d4debc330d
2 changed files with 14 additions and 14 deletions

View File

@ -64,8 +64,8 @@
<input type="password" id="node-config-input-apikey" > <input type="password" id="node-config-input-apikey" >
</div> </div>
<div class="form-row"> <div class="form-row">
<label for="node-config-input-deviceid"><i class="icon-tasks"></i>Device Ident</label> <label for="node-config-input-deviceIdent"><i class="icon-tasks"></i>Device Ident</label>
<input type="text" id="node-config-input-deviceid" > <input type="text" id="node-config-input-deviceIdent" >
</div> </div>
<div class="form-tips">The API key can be found on the <a target="_blank" href="https://www.pushbullet.com/account">Account Settings</a></div> <div class="form-tips">The API key can be found on the <a target="_blank" href="https://www.pushbullet.com/account">Account Settings</a></div>
@ -87,15 +87,15 @@
defaults: { defaults: {
name: {value: "", required: true} name: {value: "", required: true}
//apikey: -> credentials //apikey: -> credentials
//deviceid -> credentials //deviceIdent -> credentials
}, },
label: function () { label: function () {
return this.name; return this.name;
}, },
oneditprepare: function () { oneditprepare: function () {
$.getJSON('pushbullet-api/' + this.id, function (data) { $.getJSON('pushbullet-api/' + this.id, function (data) {
if (data.deviceid) { if (data.deviceIdent) {
$('#node-config-input-deviceid').val(data.deviceid); $('#node-config-input-deviceIdent').val(data.deviceIdent);
} }
if (data.hasApiKey) { if (data.hasApiKey) {
$('#node-config-input-apikey').val('__PWRD__'); $('#node-config-input-apikey').val('__PWRD__');
@ -111,7 +111,7 @@
if (newApiKey != '__PWRD__') { if (newApiKey != '__PWRD__') {
credentials.apikey = newApiKey; credentials.apikey = newApiKey;
} }
credentials.deviceid = $('#node-config-input-deviceid').val(); credentials.deviceIdent = $('#node-config-input-deviceIdent').val();
$.ajax({ $.ajax({
url: 'pushbullet-api/' + this.id, url: 'pushbullet-api/' + this.id,
type: 'POST', type: 'POST',

View File

@ -33,7 +33,7 @@ RED.httpAdmin.get('/pushbullet-api/global', function (req, res) {
RED.httpAdmin.get('/pushbullet-api/:id', function (req, res) { RED.httpAdmin.get('/pushbullet-api/:id', function (req, res) {
var credentials = RED.nodes.getCredentials(req.params.id); var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) { if (credentials) {
res.send(JSON.stringify({hasApiKey: (credentials.apikey && credentials.apikey != ""), deviceid: credentials.deviceid})); res.send(JSON.stringify({hasApiKey: (credentials.apikey && credentials.apikey != ""), deviceIdent: credentials.deviceIdent}));
} else { } else {
res.send(JSON.stringify({})); res.send(JSON.stringify({}));
} }
@ -57,10 +57,10 @@ RED.httpAdmin.post('/pushbullet-api/:id', function (req, res) {
} else { } else {
credentials.apikey = newCreds.apikey || credentials.apikey; credentials.apikey = newCreds.apikey || credentials.apikey;
} }
if (newCreds.deviceid == "" || newCreds.deviceid == null) { if (newCreds.deviceIdent == "" || newCreds.deviceIdent == null) {
delete credentials.deviceid; delete credentials.deviceIdent;
} else { } else {
credentials.deviceid = newCreds.deviceid; credentials.deviceIdent = newCreds.deviceIdent;
} }
RED.nodes.addCredentials(req.params.id, credentials); RED.nodes.addCredentials(req.params.id, credentials);
res.send(200); res.send(200);
@ -73,7 +73,7 @@ function PushBulletDevice(n) {
var credentials = RED.nodes.getCredentials(n.id); var credentials = RED.nodes.getCredentials(n.id);
if (credentials) { if (credentials) {
this.apikey = credentials.apikey; this.apikey = credentials.apikey;
this.deviceid = credentials.deviceid; this.deviceIdent = credentials.deviceIdent;
} }
} }
RED.nodes.registerType("bullet-device", PushBulletDevice); RED.nodes.registerType("bullet-device", PushBulletDevice);
@ -86,10 +86,10 @@ function PushbulletNode(n) {
if (this.api) { if (this.api) {
this.pusher = new PushBullet(this.api.apikey); this.pusher = new PushBullet(this.api.apikey);
this.deviceId = this.api.deviceid; this.deviceIdent = this.api.deviceIdent;
} else if (pushkey) { } else if (pushkey) {
this.pusher = new PushBullet(pushkey.pushbullet); this.pusher = new PushBullet(pushkey.pushbullet);
this.deviceId = pushkey.deviceid; this.deviceIdent = pushkey.deviceid;
} else { } else {
this.error("missing pushbullet credentials"); this.error("missing pushbullet credentials");
return; return;
@ -105,7 +105,7 @@ function PushbulletNode(n) {
msg.payload = msg.payload.toString(); msg.payload = msg.payload.toString();
} }
try { try {
this.pusher.note(this.deviceId, titl, msg.payload, function (err, response) { this.pusher.note(this.deviceIdent, titl, msg.payload, function (err, response) {
if (err) node.error("Pushbullet error: " + err); if (err) node.error("Pushbullet error: " + err);
//console.log(response); //console.log(response);
}); });