3
\$\begingroup\$

What are my options on how the loginToNetflix method is called? Is there a more clean and elegant way of accomplishing this?

loginToNetflix(credentials.username, credentials.password);
function loginToNetflix (username, password) {
casper.start('https://www.netflix.com/Login?locale=en-US', function() {
 this.echo('Attempting login to Netflix - filling and submitting login form');
 this.fill('form#login-form', {
 'email': username,
 'password': password,
 'RememberMe': true
 }, true);
});
casper.then(function() {
 this.echo('Login Complete - Please check the cookie as defined in command line');
 //save the cookie for use by netflix scraper api
 var cookies = JSON.stringify(phantom.cookies);
 fs.write("netflix-cookies.txt", cookies, 644);
});
casper.run(function () {
 this.echo('Done - Exiting!');
 casper.exit();
});
}
200_success
145k22 gold badges190 silver badges478 bronze badges
asked Mar 18, 2015 at 14:13
\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

Looks alright to me. A small personal nuisance for me, but a possible improvement would be to pass the credentials in an object

var credentials = {
 username: "xxx",
 password: "yyy"
};

That would make the signature of your function smaller, and after all, the 2 variables are tightly coupled, semantically speaking.

But as I say, peccata minuta. Looks good to me.

answered Mar 19, 2015 at 8:28
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.