<commit_before>// need pluralize to turn types into plural versions for API pages
var pluralize = require('pluralize');

// our default user-agent
var useragent = "Mozilla/5.0 (Linux; U; Android 4.3; en-GB; C6502 Build/10.4.1.B.0.101) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30";

function DisneyAPI(options)
{
    // keep session data about
    var session = {
        access_token: false,
        expire_time: 0
    };

    // load request library
    var request = require('request').defaults({
        // use a cookie jar for logging in page
        jar: true
    });

    // get fresh access token from Disney API
    function GetAccessToken(cb)
    {
        request(
        {
            url: "https://authorization.go.com/token",
            method: "POST",
            body: "assertion_type=public&client_id=WDPRO-MOBILE.CLIENT-PROD&grant_type=assertion"

        },
        function(err, resp, body)
        {
            if (resp.statusCode == 200)
            {
                var data = JSON.parse(body);
                if (data && data.access_token && data.expires_in)
                {
                    session.access_token = data.access_token;
                    session.expire_time = (new Date().getTime()) + ((data.expires_in - 30) * 1000);

                    if (cb) cb();
                }
                else
                {
                    if (cb) cb("GetAccessToken: Invalid data body returned");
                }
            }
            else
            {
                if (cb) cb("GetAccessToken: Unexpected status code: " + resp.statusCode);
                return;
            }
        }
        );
    }

    function CheckAccessToken(cb)
    {
        // check if we have an access token or our access token has expired
        if (!session.access_token || session.expire_time <= new Date().getTime())
        {
            GetAccessToken(function(error) {
                if (error)
                {
                    if (cb) cb(error);
                    return;
                }
                if (cb) cb();
            });
        }
        else
        {
            if (cb) cb();
        }
    };

    function MakeGet(url, data, cb)
    {
        CheckAccessToken(function(error) {
            if (error)
            {
                if (cb) cb(error);
                return;
            }

            request({
                url: url,
                method: "GET",
                headers: {
                    'Authorization': "BEARER " + session.access_token,
                    'Accept': 'application/json;apiversion=1',
                    'X-Conversation-Id': '~WDPRO-MOBILE.CLIENT-PROD'
                },
                qs: data
            }, function(error, resp, body) {
                if (error)
                {
                    if (cb) cb(error);
                    return;
                }

                try {
                    var JSONData = JSON.parse(body);

                    // do some extra data parsing for neatness
                    if (JSONData)
                    {<commit_msg>Store load balancer instance ID to use for future requests<commit_after>// need pluralize to turn types into plural versions for API pages
var pluralize = require('pluralize');

// our default user-agent
var useragent = "Mozilla/5.0 (Linux; U; Android 4.3; en-GB; C6502 Build/10.4.1.B.0.101) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30";

function DisneyAPI(options)
{
    // keep session data about
    var session = {
        access_token: false,
        expire_time: 0
    };

    // load request library
    var request = require('request').defaults({
        // use a cookie jar for logging in page
        jar: true
    });

    // get fresh access token from Disney API
    function GetAccessToken(cb)
    {
        request(
        {
            url: "https://authorization.go.com/token",
            method: "POST",
            body: "assertion_type=public&client_id=WDPRO-MOBILE.CLIENT-PROD&grant_type=assertion"

        },
        function(err, resp, body)
        {
            if (resp.statusCode == 200)
            {
                var data = JSON.parse(body);
                if (data && data.access_token && data.expires_in)
                {
                    session.access_token = data.access_token;
                    session.expire_time = (new Date().getTime()) + ((data.expires_in - 30) * 1000);

                    if (cb) cb();
                }
                else
                {
                    if (cb) cb("GetAccessToken: Invalid data body returned");
                }
            }
            else
            {
                if (cb) cb("GetAccessToken: Unexpected status code: " + resp.statusCode);
                return;
            }
        }
        );
    }

    function CheckAccessToken(cb)
    {
        // check if we have an access token or our access token has expired
        if (!session.access_token || session.expire_time <= new Date().getTime())
        {
            GetAccessToken(function(error) {
                if (error)
                {
                    if (cb) cb(error);
                    return;
                }
                if (cb) cb();
            });
        }
        else
        {
            if (cb) cb();
        }
    };

    function MakeGet(url, data, cb)
    {
        CheckAccessToken(function(error) {
            if (error)
            {
                if (cb) cb(error);
                return;
            }

            var headers = {
                'Authorization': "BEARER " + session.access_token,
                'Accept': 'application/json;apiversion=1',
                'X-Conversation-Id': '~WDPRO-MOBILE.CLIENT-PROD'
            };

            // add stored load balancer instance if we have one
            if (session.correlation)
            {
                headers["X-Correlation-Id"] = session.correlation;
            }

            request({
                url: url,
                method: "GET",
                headers: headers,
                qs: data
            }, function(error, resp, body) {
                // if we get an instance ID from the load balancer, store it
                if (resp && resp.headers && resp.headers["x-correlation-id"])
                {
                    session.correlation = resp.headers["x-correlation-id"];
                }

                if (error)
                {
                    if (cb) cb(error);
                    return;
                }

                try {
                    var JSONData = JSON.parse(body);

                    // do some extra data parsing for neatness
                    if (JSONData)
                    {
{'fraction_non_alphanumeric': 0.10351447135262846, 'fraction_numerical': 0.01151801535735381, 'mean_word_length': 1.1806181584030908, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2292457', 'n_tokens_mistral': 1903, 'n_tokens_neox': 1741, 'n_words': 447}