33 lines
901 B
JavaScript
33 lines
901 B
JavaScript
|
var Promise = require('promise');
|
||
|
var Twitter = require('twitter');
|
||
|
|
||
|
module.exports = function(config) {
|
||
|
|
||
|
var client = new Twitter({
|
||
|
consumer_key: config.keys.twitter.consumerKey,
|
||
|
consumer_secret: config.keys.twitter.consumerSecret,
|
||
|
access_token_key: '',
|
||
|
access_token_secret: ''
|
||
|
});
|
||
|
|
||
|
var getTweet = function(statusId) {
|
||
|
var promise = new Promise(function(resolve, reject) {
|
||
|
client.get('statuses/show/' + statusId, function(error, tweet, response) {
|
||
|
if(!error) {
|
||
|
var user = tweet.user.screen_name;
|
||
|
var time = tweet.created_at;
|
||
|
var dateTime = new Date(time);
|
||
|
var dateTimeLocale = dateTime.toLocaleDateString('fi-FI') + ' ' + dateTime.getHours() + '.' + dateTime.getMinutes();
|
||
|
var str = '@' + user + ': "' + tweet.text + '" ('+ dateTimeLocale +')';
|
||
|
resolve(str);
|
||
|
} else {
|
||
|
reject();
|
||
|
}
|
||
|
});
|
||
|
|
||
|
});
|
||
|
return promise;
|
||
|
};
|
||
|
|
||
|
return getTweet;
|
||
|
};
|