-
Notifications
You must be signed in to change notification settings - Fork 8
/
twttr_actions.js
70 lines (66 loc) · 2.15 KB
/
twttr_actions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var util = require("util"),
twitter = require("twitter"),
loggr = require('./logger.js');
function twttr_actions(config){
var logger = new loggr(config);
var twttr = new twitter({
consumer_key: config.twitter.consumer_key,
consumer_secret: config.twitter.consumer_secret,
access_token_key: config.twitter.oauth_token,
access_token_secret: config.twitter.oauth_secret,
rest_base: "https://api.twitter.com/1.1"
});
this.dm = function(user_id, text) {
twttr.newDirectMessage({user_id: user_id}, text, function (data) {
if (data.recipient) {
logger.log(logger.timestamp() + " DM sent to @" + data.recipient.screen_name + ": " + data.text);
} else if (data.statusCode) {
logger.log(logger.timestamp() + " DM error: " + data.statusCode + ": " + data.message);
logger.log(util.inspect(data, {depth:null}));
logger.log(JSON.parse(data.data));
}
})
},
this.tweet = function(status, callback) {
twttr.updateStatus(status,
function (data) {
if (data.id_str) {
callback(data, null);
} else if (data.statusCode) {
logger.log(logger.timestamp() + " Tweet error: " + data.statusCode + ": " + data.message);
logger.log(util.inspect(data, {depth:null}));
callback(null, JSON.parse(data.data).errors);
}
}
)
},
this.delete = function(statusid, callback) {
twttr.destroyStatus(statusid,
function (data) {
if (data.id_str) {
callback(data.id_str, data.text);
} else if (data.statusCode) {
logger.log(logger.timestamp() + " Tweet delete error: " + data.statusCode + ": " + data.message);
logger.log(util.inspect(data, {depth:null}));
logger.log(JSON.parse(data.data));
}
}
)
},
this.verify = function(callback) {
twttr.verifyCredentials(function(data) {
callback(data);
});
},
this.getUserTimeline = function(params, callback) {
twttr.getUserTimeline(params, function(data) {
callback(data);
});
},
this.rateLimitStatus = function(params, callback) {
twttr.rateLimitStatus(params, function(data) {
callback(data);
});
}
}
module.exports = twttr_actions;