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