Commit 8ef206b4 authored by Killian Kemps's avatar Killian Kemps
Browse files

Allow to use environment variables for Twitter configuration

parent c6f97e71
var passport = require('passport')
, TwitterStrategy = require('passport-twitter').Strategy;
var configTwitter = require('../config/twitter');
try {
var configTwitter = require('../config/twitter');
} catch (error) {
console.log('Warning: There is no configuration file for twitter!');
}
var users = require('./users');
......@@ -24,9 +28,9 @@ function passportAuthentication (app){
});
passport.use(new TwitterStrategy({
consumerKey: configTwitter.consumerKey,
consumerSecret: configTwitter.consumerSecret,
callbackURL: configTwitter.callbackURL
consumerKey: configTwitter ? configTwitter.consumerKey : process.env.QOWALA_TWITTER_KEY,
consumerSecret: configTwitter ? configTwitter.consumerSecret : process.env.QOWALA_TWITTER_SECRET,
callbackURL: configTwitter ? configTwitter.callbackURL : process.env.QOWALA_TWITTER_CALLBACK
},
function(token, tokenSecret, profile, done) {
users.setInformations(profile.id, token, tokenSecret, profile.displayName, profile.username, profile._json.profile_image_url, function(){
......
var usersModel = require('../model/usersModel');
var configTwitter = require('../config/twitter');
var Twit = require('twit');
try {
var configTwitter = require('../config/twitter');
} catch (error) {
console.log('Warning: There is no configuration file for twitter!');
}
// Declare here the stream to be used as global variable
var streamUser = [];
var streamTracking = [];
......@@ -23,8 +28,8 @@ var twitterAgent = {
getUserLists: function(userId, token, tokenSecret, cb){
var users = require('./users');
var T = new Twit({
consumer_key: configTwitter.consumerKey,
consumer_secret: configTwitter.consumerSecret,
consumer_key: configTwitter ? configTwitter.consumerKey : process.env.QOWALA_TWITTER_KEY,
consumer_secret: configTwitter ? configTwitter.consumerSecret : process.env.QOWALA_TWITTER_SECRET,
access_token: token,
access_token_secret: tokenSecret
});
......@@ -45,8 +50,8 @@ var twitterAgent = {
getUserHomeTimeline: function(userId, token, tokenSecret, cb){
var users = require('./users');
var T = new Twit({
consumer_key: configTwitter.consumerKey,
consumer_secret: configTwitter.consumerSecret,
consumer_key: configTwitter ? configTwitter.consumerKey : process.env.QOWALA_TWITTER_KEY,
consumer_secret: configTwitter ? configTwitter.consumerSecret : process.env.QOWALA_TWITTER_SECRET,
access_token: token,
access_token_secret: tokenSecret
});
......@@ -66,10 +71,10 @@ var twitterAgent = {
*/
getUserFriends: function(userId, token, tokenSecret, cb){
var T = new Twit({
consumer_key: configTwitter.consumerKey,
consumer_secret: configTwitter.consumerSecret,
access_token: token,
access_token_secret: tokenSecret
consumer_key: configTwitter ? configTwitter.consumerKey : process.env.QOWALA_TWITTER_KEY,
consumer_secret: configTwitter ? configTwitter.consumerSecret : process.env.QOWALA_TWITTER_SECRET,
access_token: token,
access_token_secret: tokenSecret
});
T.get('friends/list', {count: 200}, function (err, data, response) {
var users = require('./users');
......@@ -90,8 +95,8 @@ var twitterAgent = {
*/
sendRetweet: function(token, tokenSecret, tweetId, cb){
var T = new Twit({
consumer_key: configTwitter.consumerKey,
consumer_secret: configTwitter.consumerSecret,
consumer_key: configTwitter ? configTwitter.consumerKey : process.env.QOWALA_TWITTER_KEY,
consumer_secret: configTwitter ? configTwitter.consumerSecret : process.env.QOWALA_TWITTER_SECRET,
access_token: token,
access_token_secret: tokenSecret
});
......@@ -113,8 +118,8 @@ var twitterAgent = {
*/
sendTweet: function(token, tokenSecret, tweet, cb){
var T = new Twit({
consumer_key: configTwitter.consumerKey,
consumer_secret: configTwitter.consumerSecret,
consumer_key: configTwitter ? configTwitter.consumerKey : process.env.QOWALA_TWITTER_KEY,
consumer_secret: configTwitter ? configTwitter.consumerSecret : process.env.QOWALA_TWITTER_SECRET,
access_token: token,
access_token_secret: tokenSecret
});
......@@ -135,8 +140,8 @@ var twitterAgent = {
*/
deleteTweet: function(token, tokenSecret, tweetId, cb){
var T = new Twit({
consumer_key: configTwitter.consumerKey,
consumer_secret: configTwitter.consumerSecret,
consumer_key: configTwitter ? configTwitter.consumerKey : process.env.QOWALA_TWITTER_KEY,
consumer_secret: configTwitter ? configTwitter.consumerSecret : process.env.QOWALA_TWITTER_SECRET,
access_token: token,
access_token_secret: tokenSecret
});
......@@ -154,8 +159,8 @@ var twitterAgent = {
*/
showTweet: function(token, tokenSecret, tweetId, cb){
var T = new Twit({
consumer_key: configTwitter.consumerKey,
consumer_secret: configTwitter.consumerSecret,
consumer_key: configTwitter ? configTwitter.consumerKey : process.env.QOWALA_TWITTER_KEY,
consumer_secret: configTwitter ? configTwitter.consumerSecret : process.env.QOWALA_TWITTER_SECRET,
access_token: token,
access_token_secret: tokenSecret
});
......@@ -174,8 +179,8 @@ var twitterAgent = {
*/
searchTweet: function(token, tokenSecret, keyword, cb){
var T = new Twit({
consumer_key: configTwitter.consumerKey,
consumer_secret: configTwitter.consumerSecret,
consumer_key: configTwitter ? configTwitter.consumerKey : process.env.QOWALA_TWITTER_KEY,
consumer_secret: configTwitter ? configTwitter.consumerSecret : process.env.QOWALA_TWITTER_SECRET,
access_token: token,
access_token_secret: tokenSecret
});
......@@ -190,10 +195,10 @@ var twitterAgent = {
*/
followUser: function(userId, targetUserId, token, tokenSecret) {
var T = new Twit({
consumer_key: configTwitter.consumerKey,
consumer_secret: configTwitter.consumerSecret,
access_token: token,
access_token_secret: tokenSecret
consumer_key: configTwitter ? configTwitter.consumerKey : process.env.QOWALA_TWITTER_KEY,
consumer_secret: configTwitter ? configTwitter.consumerSecret : process.env.QOWALA_TWITTER_SECRET,
access_token: token,
access_token_secret: tokenSecret
});
T.post('friendships/create', {user_id:targetUserId}, function (err, data, response) {
if(err){
......@@ -207,10 +212,10 @@ var twitterAgent = {
*/
unfollowUser: function(userId, targetUserId, token, tokenSecret) {
var T = new Twit({
consumer_key: configTwitter.consumerKey,
consumer_secret: configTwitter.consumerSecret,
access_token: token,
access_token_secret: tokenSecret
consumer_key: configTwitter ? configTwitter.consumerKey : process.env.QOWALA_TWITTER_KEY,
consumer_secret: configTwitter ? configTwitter.consumerSecret : process.env.QOWALA_TWITTER_SECRET,
access_token: token,
access_token_secret: tokenSecret
});
T.post('friendships/destroy', {user_id:targetUserId}, function (err, data, response) {
if(err){
......@@ -224,10 +229,10 @@ var twitterAgent = {
*/
getFollowedBy: function(userId, targetUserId, token, tokenSecret, cb) {
var T = new Twit({
consumer_key: configTwitter.consumerKey,
consumer_secret: configTwitter.consumerSecret,
access_token: token,
access_token_secret: tokenSecret
consumer_key: configTwitter ? configTwitter.consumerKey : process.env.QOWALA_TWITTER_KEY,
consumer_secret: configTwitter ? configTwitter.consumerSecret : process.env.QOWALA_TWITTER_SECRET,
access_token: token,
access_token_secret: tokenSecret
});
T.get('followers/list', {user_id:targetUserId,count:50}, function (errOther, dataTarget, responseOther) {
if(errOther){
......@@ -272,8 +277,8 @@ var twitterAgent = {
initListsStream: function(userId, token, tokenSecret, lists){
var users = require('./users');
var T = new Twit({
consumer_key: configTwitter.consumerKey,
consumer_secret: configTwitter.consumerSecret,
consumer_key: configTwitter ? configTwitter.consumerKey : process.env.QOWALA_TWITTER_KEY,
consumer_secret: configTwitter ? configTwitter.consumerSecret : process.env.QOWALA_TWITTER_SECRET,
access_token: token,
access_token_secret: tokenSecret
});
......@@ -380,8 +385,8 @@ var twitterAgent = {
initStream: function(userId, username, token, tokenSecret){
var users = require('./users');
var T = new Twit({
consumer_key: configTwitter.consumerKey,
consumer_secret: configTwitter.consumerSecret,
consumer_key: configTwitter ? configTwitter.consumerKey : process.env.QOWALA_TWITTER_KEY,
consumer_secret: configTwitter ? configTwitter.consumerSecret : process.env.QOWALA_TWITTER_SECRET,
access_token: token,
access_token_secret: tokenSecret
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment