<commit_before>
const WPAPI = require( 'wpapi' );

module.exports = new Importer();

/**
 * @constructor
 */
function Importer() {
    this.wp = null;
}

/**
 * @param url
 * @param username
 * @param password
 */
Importer.prototype.run = function (url, username, password) {
    console.log('import start');
    authenticate(url, username, password);
    test();
};

/**
 * @param url
 * @param username
 * @param password
 */
function authenticate(url, username, password) {
    this.wp = new WPAPI({
        endpoint: url,
        username: username,
        password: password,
        auth: true,
        transport: {
            // Only override the transport for the GET method, in this example
            // Transport methods should take a wpreq object and a callback:
            get: function( wpreq, cb ) {
                let result = cache[ wpreq ];
                // If a cache hit is found, return it via the same callback/promise
                // signature as the default transport method:
                if ( result ) {
                    if ( cb && typeof cb === 'function' ) {
                        // Invoke the callback function, if one was provided
                        cb( null, result );
                    }
                    // Return the data as a promise
                    return Promise.resolve( result );
                }

                // Delegate to default transport if no cached data was found
                return WPAPI.transport.get( wpreq, cb ).then(function( result ) {
                    cache[ wpreq ] = result;
                    return result;
                });
            }
        }
    });<commit_msg>[master] Working WP api client<commit_after>
const WPAPI = require( 'wpapi' );

module.exports = new Importer();

/**
 * @constructor
 */
function Importer() {
    this.wp = null;
    this.cache = [];
}

/**
 * @param url
 * @param username
 * @param password
 */
Importer.prototype.run = function (url, username, password) {
    console.log('import start');
    authenticate.call(this, url, username, password);
    test.call(this);
};

/**
 * @param url
 * @param username
 * @param password
 */
function authenticate(url, username, password) {

    const _this = this;

    this.wp = new WPAPI({
        endpoint: url,
        username: username,
        password: password,
        auth: true,
        transport: {
            // Only override the transport for the GET method, in this example
            // Transport methods should take a wpreq object and a callback:
            get: function( wpreq, cb ) {
                let result = _this.cache[ wpreq ];
                // If a cache hit is found, return it via the same callback/promise
                // signature as the default transport method:
                if ( result ) {
                    if ( cb && typeof cb === 'function' ) {
                        // Invoke the callback function, if one was provided
                        cb( null, result );
                    }
                    // Return the data as a promise
                    return Promise.resolve( result );
                }

                // Delegate to default transport if no cached data was found
                return WPAPI.transport.get( wpreq, cb ).then(function( result ) {
                    _this.cache[ wpreq ] = result;
                    return result;
                });
            }
        }
    });
{'fraction_non_alphanumeric': 0.10174418604651163, 'fraction_numerical': 0.0, 'mean_word_length': 1.5376106194690264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '6402766', 'n_tokens_mistral': 886, 'n_tokens_neox': 842, 'n_words': 303}