<commit_before>var when           		= require('when');
var needle         		= require('needle');
var _              		= require('lodash');
var setParam       		= require('mout/queryString/setParam');
var guid           		= require('mout/random/guid');
var logger         		= require('../logger');
var globalize      	    = require('./globalize');
var validateInput      	= require('./validateRESTInput');

var validateExpects    	= require('./validateExpects');
var validateNotExpects	= require('./validateNotExpects');

//The format of the response should always be an object with headers and body
var formatResponse = require('./formatResponse');

var addMethodFunction	= require('./addMethodFunction');

module.exports = function (methodName, config, afterHeadersFunction) {

	var threadneedle = this;

	//If one-off SOAP mode, then perform addMethodSOAP instead
	if (config && config.soap) {
		config.globals = false;
		threadneedle[methodName] = require('./addMethodSOAP').call({ _globalOptions: {} }, methodName, config);
		return;
	}

	// All methods should default to no timeout, maximising the chance
	// of success.
	needle.defaults({
		open_timeout: 0,
		read_timeout: 0
	});

	// Validate the input. Errors will be `throw`n if there's anything
	// wrong. Throwing is usually bad - but this is declarative, so will happen
	// on app startup;
	validateInput.call(this, methodName, config);

	// Create the method<commit_msg>Added soap `type` check and soap flag deprecation to addMethodRest<commit_after>var when           		= require('when');
var needle         		= require('needle');
var _              		= require('lodash');
var setParam       		= require('mout/queryString/setParam');
var guid           		= require('mout/random/guid');
var logger         		= require('../logger');
var globalize      	    = require('./globalize');
var validateInput      	= require('./validateRESTInput');

var validateExpects    	= require('./validateExpects');
var validateNotExpects	= require('./validateNotExpects');

//The format of the response should always be an object with headers and body
var formatResponse = require('./formatResponse');

var addMethodFunction	= require('./addMethodFunction');

module.exports = function (methodName, config, afterHeadersFunction) {

	var threadneedle = this;

	//If one-off SOAP mode, then perform addMethodSOAP instead
	if (config && (config.type === 'soap' || config.soap)) {
		if (config.soap) {
			//eslint-disable-next-line no-console
			console.warn('`soap` flag has been deprecated. Use `type: \'SOAP\'` instead.');
		}
		config.globals = false;
		threadneedle[methodName] = require('./addMethodSOAP').call({ _globalOptions: {} }, methodName, config);
		return;
	}

	// All methods should default to no timeout, maximising the chance
	// of success.
	needle.defaults({
		open_timeout: 0,
		read_timeout: 0
	});

	// Validate the input. Errors will be `throw`n if there's anything
	// wrong. Throwing is usually bad - but this is declarative, so will happen
	// on app startup;
	validateInput.call(this, methodName, config);

	// Create the method
{'fraction_non_alphanumeric': 0.12717882504841835, 'fraction_numerical': 0.0012911555842479018, 'mean_word_length': 3.4654178674351583, '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': '2737605', 'n_tokens_mistral': 914, 'n_tokens_neox': 877, 'n_words': 271}