HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptMinor

Netflix Login script

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
scriptnetflixlogin

Problem

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();
});
}

Solution

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.

Code Snippets

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

Context

StackExchange Code Review Q#84360, answer score: 2

Revisions (0)

No revisions yet.