Last active
May 28, 2020 09:11
-
-
Save aakashlpin/408ddaed59072531e3a806e00930e6eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var inquirer = require('inquirer'); | |
var fetch = require('isomorphic-unfetch'); | |
var EMAILAPI_HOST = "https://emailapi.io"; | |
console.log('ππ½ Enter your details below to get details on Saturday Noon Livestream with Aakash.'); | |
inquirer | |
.prompt([ | |
{ | |
type: 'input', | |
name: 'name', | |
message: 'Hey there! Enter your name:', | |
default: 'John Doe' | |
}, | |
{ | |
type: 'input', | |
name: 'email', | |
message: 'And now your Email id:', | |
default: '[email protected]' | |
}, | |
]) | |
.then(answers => { | |
fetch(`${EMAILAPI_HOST}/api/saturday-hacks/register`, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify(answers) | |
}).then(async r => { | |
return { | |
answers, | |
response: await r.json() | |
}; | |
}).then(({answers, response}) => { | |
console.log(`\nYour registration is still pending. Check your mailbox for an email from us. \nIn the email, you'll find instructions on what to do next.\n\n`); | |
let attempt = 0; | |
const timer = setInterval(() => { | |
attempt = attempt + 1; | |
console.log(`[Attempt #${attempt}] waiting for your action..`); | |
fetch(`${EMAILAPI_HOST}/api/saturday-hacks/verify-email`, { | |
method: 'POST', | |
headers: { | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify({ | |
email: answers.email, | |
}) | |
}).then(async r => { | |
const data = await r.json(); | |
if (data.status_code === 'RECEIVED') { | |
clearInterval(timer); | |
console.log('β Email received!\n\n') | |
console.log(`Hi ${answers.name},\n\nThank you for verifying your email id! You've now successfully registered for Saturday Noon Livestream! π \n\nYou'll receive details about the live-stream by Friday each week. See you soon.\n\nCheers!\n- Aakash`); | |
} | |
}).catch(e => { | |
console.log(e); | |
}) | |
}, 7000); | |
}) | |
}) | |
.catch(error => { | |
if(error.isTtyError) { | |
// Prompt couldn't be rendered in the current environment | |
} else { | |
// Something else when wrong | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "snl", | |
"version": "0.0.2", | |
"bin": "./index.js", | |
"dependencies": { | |
"inquirer": "^7.1.0", | |
"isomorphic-unfetch": "^3.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment