forked from jsha/blocktogether
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jwurl.js
42 lines (39 loc) · 1.12 KB
/
jwurl.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
'use strict';
(function() {
/**
* Similar to twurl (https://github.com/twitter/twurl), fetch a given Twitter
* API URL using appropriate credentials. In this case, credentials are pulled
* from the DB based on a username, and the response is output to stdout.
*/
var twitterAPI = require('node-twitter-api'),
setup = require('./setup');
var twitter = setup.twitter,
BtUser = setup.BtUser;
if (process.argv.length < 4) {
process.stderr.write('Usage: js screen_name /api/path');
process.exit(1);
}
BtUser
.find({
where: {
screen_name: process.argv[2]
}
}).then(function(user) {
if (!user) {
process.stderr.write('No user', process.argv[2]);
process.exit(1);
}
twitter.oa.get("https://api.twitter.com/1.1" + process.argv[3],
user.access_token, user.access_token_secret,
function(err, data, response) {
if (err) {
process.stderr.write(err);
} else {
process.stdout.write(JSON.stringify(JSON.parse(data), null, '\t'));
process.stdout.write('\n');
}
});
}).catch(function(err) {
process.stderr.write(err);
});
})();