<commit_before>/**
 * Service to get and validate Splash key.
 *
 */

'use strict';

var request = require('request');
request.debug = true;


// rest endpoint
const SPLASH_REST = 'http://splash.fiehnlab.ucdavis.edu/splash/it';
const SPLASH_VALIDATE = 'http://splash.fiehnlab.ucdavis.edu/splash/validate';

// export our NPM module
module.exports = {
    loadSplash: loadSplash,
    validateSplash: validateSplash,
    formatData: formatData,
    SPLASH_REST: SPLASH_REST,
    SPLASH_VALIDATE: SPLASH_VALIDATE
};

function formatData(spectra) {

    if (typeof spectra === 'object') {
        return spectra;
    }
    else if (typeof spectra === 'string') {
        return JSON.parse(spectra);
    }
    else if (Array.isArray(spectra)) {
        return spectra.serializeArray();
    }
    else {
        console.log('Spectra must be an Object, String, or Array');
        return 'undefined';
    }
}

/**
 * loads spectra to REST service and retrieve the splash key.
 * @param spectra
 * @return splashKey
 */
function loadSplash(spectra) {

    var splashKey = '';

    // verify spectra object
    var serializeSpectra = formatData(spectra);

    // make http rest call
    if (serializeSpectra !== 'undefined') {

        var options = {
            uri: SPLASH_REST,
            method: 'POST',
            json: spectra
        };

        var callback = function (error, res, body) {
            console.log('test');
        };

        //console.log(request(options,function(){}));
        request(options,callback);

        //var data = queryString.stringify({
        //    'compilation_level': 'ADVANCED_OPTIMIZATIONS',
        //    'output_format': 'json',
        //    'output_info': 'compiled_code',
        //    'warning_level': 'QUIET',
        //    'js_code': spectra
        //});
        //
        //var options = {
        //    host: SPLASH_REST,
        //    method: 'POST',
        //    headers: {
        //        'Content-Type': 'application/json',
        //        'Content-Length': Buffer.byteLength(data)
        //    }
        //};<commit_msg>saving work on debugging http request<commit_after>/**
 * Service to get and validate Splash key.
 *
 */

'use strict';

var request = require('request');
require('request-debug')(request);
request.debug = true;


// rest endpoint
const SPLASH_REST = 'http://splash.fiehnlab.ucdavis.edu/splash/it';
const SPLASH_VALIDATE = 'http://splash.fiehnlab.ucdavis.edu/splash/validate';

// export our NPM module
module.exports = {
    loadSplash: loadSplash,
    validateSplash: validateSplash,
    formatData: formatData,
    SPLASH_REST: SPLASH_REST,
    SPLASH_VALIDATE: SPLASH_VALIDATE
};

function formatData(spectra) {

    if (typeof spectra === 'object') {
        return spectra;
    }
    else if (typeof spectra === 'string') {
        return JSON.parse(spectra);
    }
    else if (Array.isArray(spectra)) {
        return spectra.serializeArray();
    }
    else {
        console.log('Spectra must be an Object, String, or Array');
        return 'undefined';
    }
}

/**
 * loads spectra to REST service and retrieve the splash key.
 * @param spectra
 * @return splashKey
 */
function loadSplash(spectra) {

    var splashKey = '';

    // verify spectra object
    var serializeSpectra = formatData(spectra);

    // make http rest call
    if (serializeSpectra !== 'undefined') {

        var options = {
            url: SPLASH_REST,
            method: 'POST',
            json: spectra
        };

        var callback = function (error, res, body) {
            console.log(' RESULTS: ', error, res.statusCode, body);
        };

        //console.log(request(options,function(){}));
        //request(options, callback);

        request.get('http://www.google.com', function (error, response, body) {
                console.log(error);
                console.log(body);
                console.log(response.statusCode);// Show the HTML for the Modulus homepage.

        });

        //var data = queryString.stringify({
        //    'compilation_level': 'ADVANCED_OPTIMIZATIONS',
        //    'output_format': 'json',
        //    'output_info': 'compiled_code',
        //    'warning_level': 'QUIET',
        //    'js_code': spectra
        //});
        //
        //var options = {
        //    host: SPLASH_REST,
        //    method: 'POST',
        //    headers: {
        //        'Content-Type': 'application/json',
        //        'Content-Length': Buffer.byteLength(data)
        //    }
        //};
{'fraction_non_alphanumeric': 0.13732861565678903, 'fraction_numerical': 0.0, 'mean_word_length': 2.0894808743169397, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '1637791', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1338, 'n_words': 308}