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

Patch to Support use strict

Fixes Issue #206
(manual merge due ot other changes)
This commit is contained in:
Dave C-J 2014-05-14 11:43:51 +01:00
parent 7e4fa5fa45
commit 55245610dd

View File

@ -15,15 +15,16 @@
**/ **/
module.exports = function(RED) { module.exports = function(RED) {
"use strict";
var ntwitter = require('twitter-ng'); var ntwitter = require('twitter-ng');
var OAuth= require('oauth').OAuth; var OAuth= require('oauth').OAuth;
function TwitterNode(n) { function TwitterNode(n) {
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);
function TwitterInNode(n) { function TwitterInNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.active = true; this.active = true;
@ -34,7 +35,7 @@ module.exports = function(RED) {
this.topic = n.topic||"tweets"; this.topic = n.topic||"tweets";
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 && credentials.screen_name == this.twitterConfig.screen_name) { if (credentials && credentials.screen_name == this.twitterConfig.screen_name) {
var twit = new ntwitter({ var twit = new ntwitter({
consumer_key: "OKjYEd1ef2bfFolV25G5nQ", consumer_key: "OKjYEd1ef2bfFolV25G5nQ",
@ -42,15 +43,15 @@ module.exports = function(RED) {
access_token_key: credentials.access_token, access_token_key: credentials.access_token,
access_token_secret: credentials.access_token_secret access_token_secret: credentials.access_token_secret
}); });
//setInterval(function() { //setInterval(function() {
// twit.get("/application/rate_limit_status.json",null,function(err,cb) { // twit.get("/application/rate_limit_status.json",null,function(err,cb) {
// console.log("direct_messages:",cb["resources"]["direct_messages"]); // console.log("direct_messages:",cb["resources"]["direct_messages"]);
// }); // });
// //
//},10000); //},10000);
var node = this; var node = this;
if (this.user === "user") { if (this.user === "user") {
node.poll_ids = []; node.poll_ids = [];
@ -62,7 +63,7 @@ module.exports = function(RED) {
screen_name:user, screen_name:user,
trim_user:0, trim_user:0,
count:1 count:1
},function() { },function() {
var u = user+""; var u = user+"";
return function(err,cb) { return function(err,cb) {
if (err) { if (err) {
@ -139,7 +140,7 @@ module.exports = function(RED) {
}); });
},120000)); },120000));
}); });
} else if (this.tags !== "") { } else if (this.tags !== "") {
try { try {
var thing = 'statuses/filter'; var thing = 'statuses/filter';
@ -154,8 +155,8 @@ module.exports = function(RED) {
node.warn("twitter: possible bad geo area format. Should be lower-left lon,lat, upper-right lon,lat"); node.warn("twitter: possible bad geo area format. Should be lower-left lon,lat, upper-right lon,lat");
} }
} }
function setupStream() { var setupStream = function() {
if (node.active) { if (node.active) {
twit.stream(thing, st, function(stream) { twit.stream(thing, st, function(stream) {
//console.log(st); //console.log(st);
@ -204,7 +205,7 @@ module.exports = function(RED) {
} else { } else {
this.error("missing twitter credentials"); this.error("missing twitter credentials");
} }
this.on('close', function() { this.on('close', function() {
if (this.stream) { if (this.stream) {
this.active = false; this.active = false;
@ -218,8 +219,8 @@ module.exports = function(RED) {
}); });
} }
RED.nodes.registerType("twitter in",TwitterInNode); RED.nodes.registerType("twitter in",TwitterInNode);
function TwitterOutNode(n) { function TwitterOutNode(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.topic = n.topic; this.topic = n.topic;
@ -227,7 +228,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);
var node = this; var node = this;
if (credentials && credentials.screen_name == this.twitterConfig.screen_name) { if (credentials && credentials.screen_name == this.twitterConfig.screen_name) {
var twit = new ntwitter({ var twit = new ntwitter({
consumer_key: "OKjYEd1ef2bfFolV25G5nQ", consumer_key: "OKjYEd1ef2bfFolV25G5nQ",
@ -254,7 +255,7 @@ module.exports = function(RED) {
} }
} }
RED.nodes.registerType("twitter out",TwitterOutNode); RED.nodes.registerType("twitter out",TwitterOutNode);
var oa = new OAuth( var oa = new OAuth(
"https://api.twitter.com/oauth/request_token", "https://api.twitter.com/oauth/request_token",
"https://api.twitter.com/oauth/access_token", "https://api.twitter.com/oauth/access_token",
@ -264,9 +265,9 @@ module.exports = function(RED) {
null, null,
"HMAC-SHA1" "HMAC-SHA1"
); );
var credentials = {}; var credentials = {};
RED.httpAdmin.get('/twitter/:id', function(req,res) { RED.httpAdmin.get('/twitter/:id', function(req,res) {
var credentials = RED.nodes.getCredentials(req.params.id); var credentials = RED.nodes.getCredentials(req.params.id);
if (credentials) { if (credentials) {
@ -275,12 +276,12 @@ module.exports = function(RED) {
res.send(JSON.stringify({})); res.send(JSON.stringify({}));
} }
}); });
RED.httpAdmin.delete('/twitter/:id', function(req,res) { RED.httpAdmin.delete('/twitter/:id', function(req,res) {
RED.nodes.deleteCredentials(req.params.id); RED.nodes.deleteCredentials(req.params.id);
res.send(200); res.send(200);
}); });
RED.httpAdmin.get('/twitter/:id/auth', function(req, res){ RED.httpAdmin.get('/twitter/:id/auth', function(req, res){
var credentials = {}; var credentials = {};
oa.getOAuthRequestToken({ oa.getOAuthRequestToken({
@ -300,11 +301,11 @@ module.exports = function(RED) {
} }
}); });
}); });
RED.httpAdmin.get('/twitter/:id/auth/callback', function(req, res, next){ RED.httpAdmin.get('/twitter/: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;
oa.getOAuthAccessToken( oa.getOAuthAccessToken(
credentials.oauth_token, credentials.oauth_token,
credentials.token_secret, credentials.token_secret,