-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
39 lines (39 loc) · 1.08 KB
/
index.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
(function() {
var request;
request = require('request');
module.exports = {
get: function() {
if (!process.argv[2]) {
return console.log('get [uri] - uri is required ex. http://twitter.com/search.json?q=nodejs');
}
if (!process.argv[2].match(/https?\:\/\/(.*)\.(.*)/)) {
return console.log('get [uri] - uri is not valid');
}
return request({
uri: process.argv[2],
json: true
}, function(err, resp, body) {
return console.log(body);
});
},
post: function() {
var json;
if (!process.argv[2]) {
return console.log('post [uri] [json] - required!');
}
if (!process.argv[3]) {
return console.log('post [*uri] [json] - required!');
}
json = JSON.stringify(JSON.parse(process.argv[3]));
if (json == null) {
return console.log('valid json required!');
}
return request.post({
uri: process.argv[2],
json: json
}, function(err, resp, body) {
return console.log(body);
});
}
};
}).call(this);