var devRant = require('rantscript');
const request = require('request');
const options = {
url: 'https://www.icanhazdadjoke.com/',
method: 'GET',
headers: {
'Accept': 'application/json',
'Accept-Charset': 'utf-8'
}};
request(options, function(err, res, body) {
let json = JSON.parse(body);
//Get authentication token from devRant API
devRant
.login('Karlson', process.env.KARLSON)
.then((response)=>{
//Then post a rant to devRant with token gotten from previus request.
devRant.postRant(
json['joke'],
"joke/meme, Karlson",
response["auth_token"]["id"],
response["auth_token"]["key"],
response["auth_token"]["user_id"]
).then((resp)=>{
//Then console.log the rant data.
console.log(resp);
})
})
});