<commit_before>var when = require("when");
var promisifier = require("promisifier");
var helpers = require("./lib/helpers");
var _ = require("underscore");

var createPromisedRequest = function (request) {

  var result = createMethodThatCallsRequestsMethod()

  result.get = createMethodThatCallsRequestsMethod("get")
  result.post = createMethodThatCallsRequestsMethod("post")

  return result;

  function createMethodThatCallsRequestsMethod(method) {
    return function() {
      var args = Array.prototype.slice.call(arguments)
      if (!method)
        return promisifier.asyncMethodToPromiseWithArrayAsArgs(request, args)

      return promisifier.asyncMethodToPromiseWithArrayAsArgs(request[method], args)
    }
  }
}

function doGet(options, request) {
  var args = Array.prototype.slice.call(arguments)
  return promisifier.asyncMethodToPromiseWithArrayAsArgs(args.pop().get, args)
}

function doPost(options, request) {
  var args = Array.prototype.slice.call(arguments)
  var method =args.pop().post

  return promisifier.asyncMethodToPromiseWithArrayAsArgs(method, args)
}

function doRequest(options, request) {
  var args = Array.prototype.slice.call(arguments)
  if (arguments.length < 2)
    throw new Error("ARGUMENTS_ARE_MISSING");

  return promisifier.asyncMethodToPromiseWithArrayAsArgs(args.pop(), args)
}

function doRequestWithUrlAndMethod(url, options, request, method) {
  var args = Array.prototype.slice.call(arguments)
  if (isUrlArgPresent(args)) {
    options.url = args.shift();
  } else {
    options = url;
  }

  options.method = args.pop();

  return doRequest.apply(this, args);

  function isUrlArgPresent(args) {
    return args.length == 4
  }
}

var PromisifiedRequestCommand = function () { helpers.AbstractDelayedCallCommand.constructor.apply(this, arguments)};
_.extend(PromisifiedRequestCommand.prototype, helpers.AbstractDelayedCallCommand, {
  get: function() { return this.saveCall("get"); },
  post: function() { return this.saveCall("post"); }
});

module.exports.create   = createPromisedRequest;
module.exports.get      = doGet;
module.exports.post     = doPost;
module.exports.request  = doRequest;

module.exports.PromisifiedRequestCommand = PromisifiedRequestCommand;<commit_msg>Refactored a little bit & Added some factories<commit_after>var when = require("when");
var promisifier = require("promisifier");
var helpers = require("./lib/helpers");
var _ = require("underscore");

var createPromisedRequest = function (request) {

  var result = createMethodThatCallsRequestsMethod()

  result.get = createMethodThatCallsRequestsMethod("get")
  result.post = createMethodThatCallsRequestsMethod("post")

  return result;

  function createMethodThatCallsRequestsMethod(method) {
    return function() {
      var args = Array.prototype.slice.call(arguments)
      if (!method)
        return promisifier.asyncMethodToPromiseWithArrayAsArgs(request, args)

      return promisifier.asyncMethodToPromiseWithArrayAsArgs(request[method], args)
    }
  }
}

function doGet(options, request) {
  var args = Array.prototype.slice.call(arguments)
  return promisifier.asyncMethodToPromiseWithArrayAsArgs(args.pop().get, args)
}

function doPost(options, request) {
  var args = Array.prototype.slice.call(arguments)
  var method =args.pop().post

  return promisifier.asyncMethodToPromiseWithArrayAsArgs(method, args)
}

function doRequest(options, request) {
  var args = Array.prototype.slice.call(arguments)
  if (arguments.length < 2)
    throw new Error("ARGUMENTS_ARE_MISSING");

  return promisifier.asyncMethodToPromiseWithArrayAsArgs(args.pop(), args)
}

function doRequestWithUrlAndMethod(url, options, request, method) {
  var args = Array.prototype.slice.call(arguments)
  if (isUrlArgPresent(args)) {
    options.url = args.shift();
  } else {
    options = url;
  }

  options.method = args.pop();

  return doRequest.apply(this, args);

  function isUrlArgPresent(args) {
    return args.length == 4
  }
}

var PromisifiedRequestCommand = function () { helpers.AbstractDelayedCallCommand.constructor.apply(this, arguments)};
_.extend(PromisifiedRequestCommand.prototype, helpers.AbstractDelayedCallCommand, {
  get: function () { this.saveCall.apply(this, this.combineMethodsIntoArguments("get", arguments)); return this; },
  post: function () { this.saveCall.apply(this, this.combineMethodsIntoArguments("post", arguments)); return this; }
});

module.exports.create   = createPromisedRequest;
module.exports.get      = doGet;
module.exports.post     = doPost;
module.exports.request  = doRequest;

module.exports.PromisifiedRequestCommand = PromisifiedRequestCommand;
{'fraction_non_alphanumeric': 0.11370010787486516, 'fraction_numerical': 0.0008629989212513484, 'mean_word_length': 5.264864864864865, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5794509', 'n_tokens_mistral': 1380, 'n_tokens_neox': 1358, 'n_words': 261}