<commit_before>
/**
 * Module dependencies
 */

var debug = require('debug')('wpcom:send-request');

/**
 * Request to WordPress REST API
 *
 * @param {String|Object} params
 * @param {Object} [query]
 * @param {Object} [body]
 * @param {Function} fn
 * @api private
 */

module.exports = function (params, query, body, fn) {
  // `params` can be just the path (String)  
  params = 'string' === typeof params ? { path : params } : params;

  debug('sendRequest(%o)', params.path);

  // set `method` request param
  params.method = (params.method || 'get').toUpperCase();

  // `query` is optional
  if ('function' === typeof query) {
    fn = query;
    query = {};
  }

  // `body` is optional
  if ('function' === typeof body) {
    fn = body;
    body = null;
  }

  // query could be `null`
  query = query || {};

  // pass `query` and/or `body` to request params
  params.query = query;

  // Handle special query parameters
  // - `apiVersion`
  if (query.apiVersion) {
    params.apiVersion = query.apiVersion;
    delete query.apiVersion;
  } else {
    params.apiVersion = this.apiVersion;
  }

  if (body) {
    params.body = body;
  }

  // callback `fn` function is optional
  if (!fn) {
    fn = function (err) { if (err) { throw err; } };
  }

  debug('params: %o', params);
  // request method
  return this.request(params, fn);
};<commit_msg>send-response: print res with a new debug instance<commit_after>
/**
 * Module dependencies
 */

var debug = require('debug')('wpcom:send-request');
var debug_res = require('debug')('wpcom:send-request:res');

/**
 * Request to WordPress REST API
 *
 * @param {String|Object} params
 * @param {Object} [query]
 * @param {Object} [body]
 * @param {Function} fn
 * @api private
 */

module.exports = function (params, query, body, fn) {
  // `params` can be just the path (String)  
  params = 'string' === typeof params ? { path : params } : params;

  debug('sendRequest(%o)', params.path);

  // set `method` request param
  params.method = (params.method || 'get').toUpperCase();

  // `query` is optional
  if ('function' === typeof query) {
    fn = query;
    query = {};
  }

  // `body` is optional
  if ('function' === typeof body) {
    fn = body;
    body = null;
  }

  // query could be `null`
  query = query || {};

  // pass `query` and/or `body` to request params
  params.query = query;

  // Handle special query parameters
  // - `apiVersion`
  if (query.apiVersion) {
    params.apiVersion = query.apiVersion;
    delete query.apiVersion;
  } else {
    params.apiVersion = this.apiVersion;
  }

  if (body) {
    params.body = body;
  }

  // callback `fn` function is optional
  if (!fn) {
    fn = function (err) { if (err) { throw err; } };
  }

  debug('params: %o', params);
  // request method
  return this.request(params, function(err, res) {
    debug_res(res);
    fn(err, res);
  });
};
{'fraction_non_alphanumeric': 0.16776658562000696, 'fraction_numerical': 0.0, 'mean_word_length': 2.902439024390244, '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': '5252581', 'n_tokens_mistral': 955, 'n_tokens_neox': 932, 'n_words': 274}