<commit_before>'use strict';

var querystring = require('querystring');
var request = require('request');
var Route = require('route-parser');

module.exports = function init(client, baseUri) {
	if (!client) {
		throw new Error('client is required');
	}

	if (!baseUri) {
		throw new Error('baseUri is required');
	}

	return function generateHandler(method, path, availableHeaders) {
		if (!method) {
			throw new Error('method is required');
		}

		if (!path) {
			throw new Error('path is required');
		}

		var route = new Route(path);
		availableHeaders = availableHeaders || [];

		if (['POST', 'PUT', 'PATCH'].indexOf(method.toUpperCase()) >= 0) {
			return function handler(params, payload, callback) {
				params = params || {};

				if (arguments.length < 3) {
					callback = payload;
					payload = params;
					params = {};
				}

				var req = generateRequest(params, payload); console.log(req);
				performRequest(req, callback);
			};
		}

		return function handler(params, callback) {
			if (arguments.length < 2) {
				callback = params;
				params = {};
			}

			var req = generateRequest(params || {}); console.log(req);
			performRequest(req, callback);
		};

		function generateRequest(params, payload) {
			var requiredRouteParams = route.match(path);
			var headers = client.generateHeaders();
			var routeParams = {};
			var queryParams = {};
			var key;

			// assign params to route and headers and the rest to the query string
			for (key in requiredRouteParams) {
				if (!params[key]) {
					throw new Error('"' + key + '" param is required');
				}

				routeParams[key] = params[key];
			}<commit_msg>removed console.log<commit_after>'use strict';

var querystring = require('querystring');
var request = require('request');
var Route = require('route-parser');

module.exports = function init(client, baseUri) {
	if (!client) {
		throw new Error('client is required');
	}

	if (!baseUri) {
		throw new Error('baseUri is required');
	}

	return function generateHandler(method, path, availableHeaders) {
		if (!method) {
			throw new Error('method is required');
		}

		if (!path) {
			throw new Error('path is required');
		}

		var route = new Route(path);
		availableHeaders = availableHeaders || [];

		if (['POST', 'PUT', 'PATCH'].indexOf(method.toUpperCase()) >= 0) {
			return function handler(params, payload, callback) {
				params = params || {};

				if (arguments.length < 3) {
					callback = payload;
					payload = params;
					params = {};
				}

				var req = generateRequest(params, payload);
				performRequest(req, callback);
			};
		}

		return function handler(params, callback) {
			if (arguments.length < 2) {
				callback = params;
				params = {};
			}

			var req = generateRequest(params || {});
			performRequest(req, callback);
		};

		function generateRequest(params, payload) {
			var requiredRouteParams = route.match(path);
			var headers = client.generateHeaders();
			var routeParams = {};
			var queryParams = {};
			var key;

			// assign params to route and headers and the rest to the query string
			for (key in requiredRouteParams) {
				if (!params[key]) {
					throw new Error('"' + key + '" param is required');
				}

				routeParams[key] = params[key];
			}
{'fraction_non_alphanumeric': 0.1430778739184178, 'fraction_numerical': 0.001854140914709518, 'mean_word_length': 3.4403292181069958, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '5807665', 'n_tokens_mistral': 1148, 'n_tokens_neox': 929, 'n_words': 279}