-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwitter.js
More file actions
47 lines (44 loc) · 1.66 KB
/
Twitter.js
File metadata and controls
47 lines (44 loc) · 1.66 KB
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
var _ = require('underscore');
var Twitter = require('twitter');
module.exports = function (twitterIntegrationProvider, integrationService, Q) {
return {
api: function () {
var args = arguments;
return integrationService.integrationsForAppId('twitter').then(function (integrations) {
if (!integrations[0]) {
throw new Error("There are no twitter integrations");
}
return new Twitter({
consumer_key: twitterIntegrationProvider.twitterAppId,
consumer_secret: twitterIntegrationProvider.twitterSecret,
access_token_key: integrations[0].accessToken.split(':')[0],
access_token_secret: integrations[0].accessToken.split(':')[1]
});
});
},
get: function (path, params) {
return this.api().then(function (client) {
return Q.nfbind(client.get.bind(client))(path, params);
})
},
post: function (path, params) {
return this.api().then(function (client) {
return Q.nfbind(client.post.bind(client))(path, params);
})
},
stream: function (url, opts, actionCallback) {
return this.api().then(function (client) {
client.stream(url, opts, function(stream) {
stream.on('data', function(tweet) {
Q(actionCallback(tweet)).catch(function (err) {
console.error(err); //TODO
});
});
stream.on('error', function(error) {
console.error(error); //TODO
});
});
})
}
}
};