I'm currently trying to use some code from a fellow user on GitHub. It's goal is to wrap around the API of a specific website.
Right now the code does this:
const rp = require('requests-promise');
function login(user, pass) {
var hash = md5(`${user}-${md5(pass)}`);
var options = {
method: 'POST',
uri: opts.url + 'Login.json',
form: {
Username: user,
Hash: hash
},
json: true // Automatically stringifies the body to JSON
};
return rp(options).then(j => {
if (j.Status) {
self.loginData = j;
if (j.Notifications.length > 0) {
console.log("User has a new notifications: " + j.Notifications.join(", "));
}
delete(self.loginData.Status);
delete(self.loginData.Notifications);
} else {
throw new Error("Bad login.");
}
return Boolean(j.Status)); // fail-sucess
})
})
}
How do I get the return from the promise to be the return value of the login function? Currently it just returns the promise object instead of the intended value which is a Boolean to correspond to the login state.