-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwitter.js
37 lines (33 loc) · 1.03 KB
/
twitter.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
// imports
var Twitter = require('twitter');
// static class definition
var twitterService = {
getClient: new Promise(function (resolve) {
resolve(new Twitter({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token_key: '',
access_token_secret: ''
}));
}),
getTweets: function (q, max_id, since_id) {
return twitterService.getClient.then(function (client) {
return new Promise(function (res, rej) {
client.get('search/tweets', {
max_id: max_id,
since_id: since_id,
q: q,
count: 100,
result_type: 'recent'
}, function (error, tweets) {
if (error) {
rej(error);
}
res(tweets);
});
});
});
}
};
// export
module.exports = twitterService;