<commit_before>'use strict';

const _ = require('lodash');
const qs = require('qs');
const server = require('../../index.js');
const formatResponseCallback = (response) => {
    response.body = response.result;
    return response;
};

const formatRequestHeaders = (headers) => {
    return headers.reduce((target, header) => {
        target[header.name] = header.value;
        return target;
    }, {});
};

/**
 * perform some intial formatting before allowing the API client to format
 * the response object. In this case, we need to append the query string params
 * to the uri
 * @param  {object} request request options, as formatted for node-request
 * @return {object}         request options to be used by auto-formatter
 */
const onPreFormatRequestOptions = (request) => {
    let queryString;
    if (request.qs) {
        queryString = qs.stringify(request.qs);
        if (queryString.length) {
            request.uri += '?' + queryString;
        }
    }

    return request;
};

/**
 * Initialize the API client for use with testing
 * designed to be called after allPluginsLoaded resolves
 * @return {object} the initialized API Client
 */
module.exports = function initApiClient() {
    const config = require('config');
    const PouchDB = require('pouchdb');
    const apiClientOptions = {
        requestFn: _.bind(server.injectThen, server),
        requestObjectMap: {
            uri: 'url',
            body: 'payload'
        },
        baseUrl: 'http://localhost:' + config.get('httpsPort'),
        pouchClient: new PouchDB('/tmp/pouchdb-coins-api-test'),
        formatResponseCallback: formatResponseCallback,
        formatRequestHeaders: formatRequestHeaders,
        onPreFormatRequestOptions: onPreFormatRequestOptions
    };
    return require('../sdk/index.js')(apiClientOptions);
};<commit_msg>init-api-client uses http port only<commit_after>'use strict';

const _ = require('lodash');
const qs = require('qs');
const server = require('../../index.js');
const formatResponseCallback = (response) => {
    response.body = response.result;
    return response;
};

const formatRequestHeaders = (headers) => {
    return headers.reduce((target, header) => {
        target[header.name] = header.value;
        return target;
    }, {});
};

/**
 * perform some intial formatting before allowing the API client to format
 * the response object. In this case, we need to append the query string params
 * to the uri
 * @param  {object} request request options, as formatted for node-request
 * @return {object}         request options to be used by auto-formatter
 */
const onPreFormatRequestOptions = (request) => {
    let queryString;
    if (request.qs) {
        queryString = qs.stringify(request.qs);
        if (queryString.length) {
            request.uri += '?' + queryString;
        }
    }

    return request;
};

/**
 * Initialize the API client for use with testing
 * designed to be called after allPluginsLoaded resolves
 * @return {object} the initialized API Client
 */
module.exports = function initApiClient() {
    const config = require('config');
    const PouchDB = require('pouchdb');
    const apiClientOptions = {
        requestFn: _.bind(server.injectThen, server),
        requestObjectMap: {
            uri: 'url',
            body: 'payload'
        },
        baseUrl: 'http://localhost:' + config.get('httpPort'),
        pouchClient: new PouchDB('/tmp/pouchdb-coins-api-test'),
        formatResponseCallback: formatResponseCallback,
        formatRequestHeaders: formatRequestHeaders,
        onPreFormatRequestOptions: onPreFormatRequestOptions
    };
    return require('../sdk/index.js')(apiClientOptions);
};
{'fraction_non_alphanumeric': 0.12096555465147817, 'fraction_numerical': 0.0, 'mean_word_length': 3.066152149944873, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5033451', 'n_tokens_mistral': 997, 'n_tokens_neox': 984, 'n_words': 288}