]>
git.r.bdr.sh - rbdr/dasein/blob - lib/twitter_helper.js
3ab51fa7bd516521b7d2dc4489d7bdb9caaf59ea
3 const Co
= require('co');
4 const OAuth
= require('oauth');
5 const Pify
= require('pify');
9 internals
.kRequestTokenUrl
= 'https://api.twitter.com/oauth/request_token';
10 internals
.kAccessTokenUrl
= 'https://api.twitter.com/oauth/access_token';
11 internals
.kVerifyCredentialsUrl
= 'https://api.twitter.com/1.1/account/verify_credentials.json';
12 internals
.kOauthVersion
= '1.0A';
13 internals
.kOauthSignatureMethod
= 'HMAC-SHA1';
15 module
.exports
= internals
.TwitterHelper
= class TwitterHelper
{
19 this._oAuth
= new OAuth
.OAuth(
20 internals
.kRequestTokenUrl
,
21 internals
.kAccessTokenUrl
,
23 config
.consumerSecret
,
24 internals
.kOauthVersion
,
26 internals
.kOauthSignatureMethod
34 return Co(function * () {
36 const getOAuthRequestToken
= Pify(self
._oAuth
.getOAuthRequestToken
.bind(self
._oAuth
), { multiArgs: true });
37 const [oAuthToken
, oAuthTokenSecret
] = yield getOAuthRequestToken();
46 getAccessToken(oAuthToken
, oAuthVerifier
) {
50 return Co(function * () {
52 const getOAuthAccessToken
= Pify(self
._oAuth
.getOAuthAccessToken
.bind(self
._oAuth
), { multiArgs: true });
53 const [oAuthAccessToken
, oAuthAccessTokenSecret
] = yield getOAuthAccessToken(oAuthToken
,
59 oAuthAccessTokenSecret
64 getUser(oAuthAccessToken
, oAuthAccessTokenSecret
) {
68 return Co(function * () {
70 const get = Pify(self
._oAuth
.get.bind(self
._oAuth
), { multiArgs: true });
71 const [userResponse
] = yield get(internals
.kVerifyCredentialsUrl
,
73 oAuthAccessTokenSecret
);
75 return JSON
.parse(userResponse
);