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 type="text/javascript">
|
||||
(function() {
|
||||
var twitterConfigNodeId = null;
|
||||
var twitterConfigNodeIntervalId = null;
|
||||
|
||||
@ -28,9 +29,9 @@
|
||||
if (pathname.slice(-1) != "/") {
|
||||
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() {
|
||||
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>');
|
||||
}
|
||||
function pollTwitterCredentials(e) {
|
||||
$.getJSON('twitter/'+twitterConfigNodeId,function(data) {
|
||||
if (data.sn) {
|
||||
updateTwitterScreenName(data.sn);
|
||||
$.getJSON('credentials/twitter-credentials/'+twitterConfigNodeId,function(data) {
|
||||
if (data.screen_name) {
|
||||
updateTwitterScreenName(data.screen_name);
|
||||
twitterConfigNodeIntervalId = null;
|
||||
} else {
|
||||
twitterConfigNodeIntervalId = window.setTimeout(pollTwitterCredentials,2000);
|
||||
@ -52,10 +53,14 @@
|
||||
RED.nodes.registerType('twitter-credentials',{
|
||||
category: 'config',
|
||||
defaults: {
|
||||
screen_name: {value:""},
|
||||
access_token: {value: ""},
|
||||
access_token_secret: {value:""}
|
||||
screen_name: {value:""}
|
||||
},
|
||||
credentials: {
|
||||
screen_name: {type:"text"},
|
||||
access_token: {type: "password"},
|
||||
access_token_secret: {type:"password"}
|
||||
},
|
||||
|
||||
label: function() {
|
||||
return this.screen_name;
|
||||
},
|
||||
@ -65,13 +70,11 @@
|
||||
if (!this.screen_name || this.screen_name == "") {
|
||||
showTwitterAuthStart();
|
||||
} else {
|
||||
$.getJSON('twitter/'+twitterConfigNodeId,function(data) {
|
||||
if (data.sn) {
|
||||
updateTwitterScreenName(data.sn);
|
||||
if (this.credentials.screen_name) {
|
||||
updateTwitterScreenName(this.credentials.screen_name);
|
||||
} else {
|
||||
showTwitterAuthStart();
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
oneditsave: function() {
|
||||
@ -83,22 +86,9 @@
|
||||
if (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 type="text/x-red" data-template-name="twitter in">
|
||||
|
@ -23,7 +23,13 @@ module.exports = function(RED) {
|
||||
RED.nodes.createNode(this,n);
|
||||
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) {
|
||||
RED.nodes.createNode(this,n);
|
||||
@ -266,23 +272,7 @@ module.exports = function(RED) {
|
||||
"HMAC-SHA1"
|
||||
);
|
||||
|
||||
var credentials = {};
|
||||
|
||||
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){
|
||||
RED.httpAdmin.get('/twitter-credentials/:id/auth', function(req, res){
|
||||
var credentials = {};
|
||||
oa.getOAuthRequestToken({
|
||||
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);
|
||||
credentials.oauth_verifier = req.query.oauth_verifier;
|
||||
|
||||
|
@ -377,7 +377,7 @@ RED.editor = function() {
|
||||
function updateNodeCredentials(node, credDefinition, prefix) {
|
||||
var changed = false;
|
||||
if(!node.credentials) {
|
||||
node.credentials = {};
|
||||
node.credentials = {_:{}};
|
||||
}
|
||||
|
||||
for (var cred in credDefinition) {
|
||||
|
Loading…
Reference in New Issue
Block a user