mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Update twitter node to new credential api
This commit is contained in:
parent
4302deb5a6
commit
9d481858a0
@ -20,6 +20,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
(function() {
|
||||||
var twitterConfigNodeId = null;
|
var twitterConfigNodeId = null;
|
||||||
var twitterConfigNodeIntervalId = null;
|
var twitterConfigNodeIntervalId = null;
|
||||||
|
|
||||||
@ -28,9 +29,9 @@
|
|||||||
if (pathname.slice(-1) != "/") {
|
if (pathname.slice(-1) != "/") {
|
||||||
pathname += "/";
|
pathname += "/";
|
||||||
}
|
}
|
||||||
var callback = encodeURIComponent(location.protocol+"//"+location.hostname+":"+location.port+pathname+"twitter/"+twitterConfigNodeId+"/auth/callback");
|
var callback = encodeURIComponent(location.protocol+"//"+location.hostname+":"+location.port+pathname+"twitter-credentials/"+twitterConfigNodeId+"/auth/callback");
|
||||||
|
|
||||||
$("#node-config-twitter-row").html('Click <a id="node-config-twitter-start" href="twitter/'+twitterConfigNodeId+'/auth?callback='+callback+'" target="_blank"><b>here</b></a> to authenticate with Twitter.');
|
$("#node-config-twitter-row").html('Click <a id="node-config-twitter-start" href="twitter-credentials/'+twitterConfigNodeId+'/auth?callback='+callback+'" target="_blank"><b>here</b></a> to authenticate with Twitter.');
|
||||||
$("#node-config-twitter-start").click(function() {
|
$("#node-config-twitter-start").click(function() {
|
||||||
twitterConfigNodeIntervalId = window.setTimeout(pollTwitterCredentials,2000);
|
twitterConfigNodeIntervalId = window.setTimeout(pollTwitterCredentials,2000);
|
||||||
});
|
});
|
||||||
@ -40,9 +41,9 @@
|
|||||||
$("#node-config-twitter-row").html('<label><i class="icon-user"></i> Twitter ID</label><span class="input-xlarge uneditable-input">'+sn+'</span>');
|
$("#node-config-twitter-row").html('<label><i class="icon-user"></i> Twitter ID</label><span class="input-xlarge uneditable-input">'+sn+'</span>');
|
||||||
}
|
}
|
||||||
function pollTwitterCredentials(e) {
|
function pollTwitterCredentials(e) {
|
||||||
$.getJSON('twitter/'+twitterConfigNodeId,function(data) {
|
$.getJSON('credentials/twitter-credentials/'+twitterConfigNodeId,function(data) {
|
||||||
if (data.sn) {
|
if (data.screen_name) {
|
||||||
updateTwitterScreenName(data.sn);
|
updateTwitterScreenName(data.screen_name);
|
||||||
twitterConfigNodeIntervalId = null;
|
twitterConfigNodeIntervalId = null;
|
||||||
} else {
|
} else {
|
||||||
twitterConfigNodeIntervalId = window.setTimeout(pollTwitterCredentials,2000);
|
twitterConfigNodeIntervalId = window.setTimeout(pollTwitterCredentials,2000);
|
||||||
@ -52,10 +53,14 @@
|
|||||||
RED.nodes.registerType('twitter-credentials',{
|
RED.nodes.registerType('twitter-credentials',{
|
||||||
category: 'config',
|
category: 'config',
|
||||||
defaults: {
|
defaults: {
|
||||||
screen_name: {value:""},
|
screen_name: {value:""}
|
||||||
access_token: {value: ""},
|
|
||||||
access_token_secret: {value:""}
|
|
||||||
},
|
},
|
||||||
|
credentials: {
|
||||||
|
screen_name: {type:"text"},
|
||||||
|
access_token: {type: "password"},
|
||||||
|
access_token_secret: {type:"password"}
|
||||||
|
},
|
||||||
|
|
||||||
label: function() {
|
label: function() {
|
||||||
return this.screen_name;
|
return this.screen_name;
|
||||||
},
|
},
|
||||||
@ -65,13 +70,11 @@
|
|||||||
if (!this.screen_name || this.screen_name == "") {
|
if (!this.screen_name || this.screen_name == "") {
|
||||||
showTwitterAuthStart();
|
showTwitterAuthStart();
|
||||||
} else {
|
} else {
|
||||||
$.getJSON('twitter/'+twitterConfigNodeId,function(data) {
|
if (this.credentials.screen_name) {
|
||||||
if (data.sn) {
|
updateTwitterScreenName(this.credentials.screen_name);
|
||||||
updateTwitterScreenName(data.sn);
|
} else {
|
||||||
} else {
|
showTwitterAuthStart();
|
||||||
showTwitterAuthStart();
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
oneditsave: function() {
|
oneditsave: function() {
|
||||||
@ -83,22 +86,9 @@
|
|||||||
if (twitterConfigNodeIntervalId) {
|
if (twitterConfigNodeIntervalId) {
|
||||||
window.clearTimeout(twitterConfigNodeIntervalId);
|
window.clearTimeout(twitterConfigNodeIntervalId);
|
||||||
}
|
}
|
||||||
if (adding) {
|
|
||||||
$.ajax({
|
|
||||||
url: 'twitter/'+this.id,
|
|
||||||
type: 'DELETE',
|
|
||||||
success: function(result) {}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
ondelete: function() {
|
|
||||||
$.ajax({
|
|
||||||
url: 'twitter/'+this.id,
|
|
||||||
type: 'DELETE',
|
|
||||||
success: function(result) {}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-template-name="twitter in">
|
<script type="text/x-red" data-template-name="twitter in">
|
||||||
|
@ -23,7 +23,13 @@ module.exports = function(RED) {
|
|||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.screen_name = n.screen_name;
|
this.screen_name = n.screen_name;
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("twitter-credentials",TwitterNode);
|
RED.nodes.registerType("twitter-credentials",TwitterNode,{
|
||||||
|
credentials: {
|
||||||
|
screen_name: {type:"text"},
|
||||||
|
access_token: {type: "password"},
|
||||||
|
access_token_secret: {type:"password"}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function TwitterInNode(n) {
|
function TwitterInNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
@ -266,23 +272,7 @@ module.exports = function(RED) {
|
|||||||
"HMAC-SHA1"
|
"HMAC-SHA1"
|
||||||
);
|
);
|
||||||
|
|
||||||
var credentials = {};
|
RED.httpAdmin.get('/twitter-credentials/:id/auth', function(req, res){
|
||||||
|
|
||||||
RED.httpAdmin.get('/twitter/:id', function(req,res) {
|
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
|
||||||
if (credentials) {
|
|
||||||
res.send(JSON.stringify({sn:credentials.screen_name}));
|
|
||||||
} else {
|
|
||||||
res.send(JSON.stringify({}));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
RED.httpAdmin.delete('/twitter/:id', function(req,res) {
|
|
||||||
RED.nodes.deleteCredentials(req.params.id);
|
|
||||||
res.send(200);
|
|
||||||
});
|
|
||||||
|
|
||||||
RED.httpAdmin.get('/twitter/:id/auth', function(req, res){
|
|
||||||
var credentials = {};
|
var credentials = {};
|
||||||
oa.getOAuthRequestToken({
|
oa.getOAuthRequestToken({
|
||||||
oauth_callback: req.query.callback
|
oauth_callback: req.query.callback
|
||||||
@ -302,7 +292,7 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
RED.httpAdmin.get('/twitter/:id/auth/callback', function(req, res, next){
|
RED.httpAdmin.get('/twitter-credentials/:id/auth/callback', function(req, res, next){
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||||
credentials.oauth_verifier = req.query.oauth_verifier;
|
credentials.oauth_verifier = req.query.oauth_verifier;
|
||||||
|
|
||||||
|
@ -377,7 +377,7 @@ RED.editor = function() {
|
|||||||
function updateNodeCredentials(node, credDefinition, prefix) {
|
function updateNodeCredentials(node, credDefinition, prefix) {
|
||||||
var changed = false;
|
var changed = false;
|
||||||
if(!node.credentials) {
|
if(!node.credentials) {
|
||||||
node.credentials = {};
|
node.credentials = {_:{}};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var cred in credDefinition) {
|
for (var cred in credDefinition) {
|
||||||
|
Loading…
Reference in New Issue
Block a user