mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Handle upgrade from old to new twitter node better
This commit is contained in:
parent
235831b464
commit
aaf93ab587
@ -5,6 +5,7 @@ module.exports = function(RED) {
|
|||||||
var OAuth= require('oauth').OAuth;
|
var OAuth= require('oauth').OAuth;
|
||||||
var request = require('request');
|
var request = require('request');
|
||||||
var twitterRateTimeout;
|
var twitterRateTimeout;
|
||||||
|
var retry = 60000; // 60 secs backoff for now
|
||||||
|
|
||||||
function TwitterCredentialsNode(n) {
|
function TwitterCredentialsNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
@ -57,7 +58,7 @@ module.exports = function(RED) {
|
|||||||
this.twitterConfig = RED.nodes.getNode(this.twitter);
|
this.twitterConfig = RED.nodes.getNode(this.twitter);
|
||||||
var credentials = RED.nodes.getCredentials(this.twitter);
|
var credentials = RED.nodes.getCredentials(this.twitter);
|
||||||
|
|
||||||
if (credentials) {
|
if (credentials && credentials.consumer_key && credentials.consumer_secret && credentials.access_token && credentials.access_token_secret) {
|
||||||
var twit = new Ntwitter({
|
var twit = new Ntwitter({
|
||||||
consumer_key: credentials.consumer_key,
|
consumer_key: credentials.consumer_key,
|
||||||
consumer_secret: credentials.consumer_secret,
|
consumer_secret: credentials.consumer_secret,
|
||||||
@ -248,7 +249,6 @@ module.exports = function(RED) {
|
|||||||
twit.stream(thing, st, function(stream) {
|
twit.stream(thing, st, function(stream) {
|
||||||
//console.log("ST",st);
|
//console.log("ST",st);
|
||||||
node.stream = stream;
|
node.stream = stream;
|
||||||
var retry = 60000; // 60 secs backoff for now
|
|
||||||
stream.on('data', function(tweet) {
|
stream.on('data', function(tweet) {
|
||||||
if (tweet.user !== undefined) {
|
if (tweet.user !== undefined) {
|
||||||
var where = tweet.user.location;
|
var where = tweet.user.location;
|
||||||
@ -358,25 +358,24 @@ module.exports = function(RED) {
|
|||||||
node.error(err);
|
node.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
this.on('close', function() {
|
||||||
else {
|
if (this.tout) { clearTimeout(this.tout); }
|
||||||
|
if (this.tout2) { clearTimeout(this.tout2); }
|
||||||
|
if (this.stream) {
|
||||||
|
this.restart = false;
|
||||||
|
this.stream.removeAllListeners();
|
||||||
|
this.stream.destroy();
|
||||||
|
}
|
||||||
|
if (this.poll_ids) {
|
||||||
|
for (var i=0; i<this.poll_ids.length; i++) {
|
||||||
|
clearInterval(this.poll_ids[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
this.error(RED._("twitter.errors.missingcredentials"));
|
this.error(RED._("twitter.errors.missingcredentials"));
|
||||||
}
|
}
|
||||||
|
|
||||||
this.on('close', function() {
|
|
||||||
if (this.tout) { clearTimeout(this.tout); }
|
|
||||||
if (this.tout2) { clearTimeout(this.tout2); }
|
|
||||||
if (this.stream) {
|
|
||||||
this.restart = false;
|
|
||||||
this.stream.removeAllListeners();
|
|
||||||
this.stream.destroy();
|
|
||||||
}
|
|
||||||
if (this.poll_ids) {
|
|
||||||
for (var i=0; i<this.poll_ids.length; i++) {
|
|
||||||
clearInterval(this.poll_ids[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("twitter in",TwitterInNode);
|
RED.nodes.registerType("twitter in",TwitterInNode);
|
||||||
|
|
||||||
@ -390,7 +389,7 @@ module.exports = function(RED) {
|
|||||||
var node = this;
|
var node = this;
|
||||||
var dm_user;
|
var dm_user;
|
||||||
|
|
||||||
if (credentials) {
|
if (credentials && credentials.consumer_key && credentials.consumer_secret && credentials.access_token && credentials.access_token_secret) {
|
||||||
var twit = new Ntwitter({
|
var twit = new Ntwitter({
|
||||||
consumer_key: credentials.consumer_key,
|
consumer_key: credentials.consumer_key,
|
||||||
consumer_secret: credentials.consumer_secret,
|
consumer_secret: credentials.consumer_secret,
|
||||||
@ -464,6 +463,8 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
else { node.warn(RED._("twitter.errors.nopayload")); }
|
else { node.warn(RED._("twitter.errors.nopayload")); }
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
this.error(RED._("twitter.errors.missingcredentials"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("twitter out",TwitterOutNode);
|
RED.nodes.registerType("twitter out",TwitterOutNode);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user