-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.js
More file actions
36 lines (34 loc) · 930 Bytes
/
input.js
File metadata and controls
36 lines (34 loc) · 930 Bytes
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
var readline = require('readline');
var google = require('googleapis');
var googl = require('goo.gl');
var urlshortener = google.urlshortener('v1');
var http = require('http');
googl.setKey('AIzaSyCZdy7xfot1zDIQ161EGYWSQOJT17Fcwb0');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question('Type in a url to shorten ', function(ans){
var more = ans.split(" ");
if(more[1] === "-s"){
googl.shorten(more[0])
.then(function (shortUrl) {
console.log(shortUrl);
})
.catch(function (err) {
console.error(err.message);
});
rl.close();
}else if(more[1] === '-l'){
googl.expand(more[0])
.then(function (longUrl) {
console.log(longUrl);
})
.catch(function (err) {
console.error(err.message);
});
rl.close();
}else{
console.log("return a valid argument e.g http://google.com -s or -l");
}
});