<commit_before>/*
 * The Http requester
 */
import { Store } from '../Store';

// callback: function (err, response)
//	where response is an object if JSON.parseable or is the responseText
function request(method, url, data, callback) {
	if (data === null || data === undefined) {
		data = undefined;
	} else if (typeof data === 'object') {
		data = JSON.stringify(data);
	}
	const request = new XMLHttpRequest();
	request.open(method.toUpperCase(), url, true);
	request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');

	request.onload = function() {
		if (request.status >= 200 && request.status < 400) {
			try {
				callback(null, JSON.parse(request.responseText));
			} catch (e) {
				callback(null, request.responseText);
			}
		} else {
			callback(request.responseText);
		}
	};

	request.onerror = function() {
		callback('Failed to contact remote server');
	};

	if (data) {
		request.send(data);
	} else {
		request.send();
	}
}


export const Http = {
	// key: The key of the store item to set with the response data
	// 	If key is set then the matching store item will be set
	// url: The url
	// callback: void function (err, responseData)
	get(key, url, callback) {
		request('GET', null, (err, value) => {
			if (err) {
				callback(err);
				return;
			}
			if (key) {
				Store.setItem(key, value);
			}
			callback(null, value);
		});
	},

	// key: The key of the store item to set with the response data
	// 	If key is set then the matching store item will be set
	// url: The url
	// data: The data to post
	// callback: void function (err, responseData)
	post(key, url, data, callback) {
		request('POST', data, (err, value) => {
			if (err) {
				callback(err);
				return;
			}
			if (key) {
				Store.setItem(key, value);
			}
			callback(null, value);
		});
	},

	// key: The key of the store item to set with the response data
	// 	If key is set then the matching store item will be set
	// url: The url
	// data: The data to put
	// callback: void function (err, responseData)
	put(key, url, data, callback) {
		request('PUT', data, (err, value) => {
			if (err) {
				callback(err);
				return;
			}
			if (key) {
				Store.setItem(key, value);
			}
			callback(null, value);
		});
	},

	// key: The key of the store item to set with the response data
	// 	If key is set then the matching store item will be set
	// url: The url
	// callback: void function (err, responseData)
	delete(key, url, callback) {
		request('DELETE', null, (err, value) => {
			if (err) {
				callback(err);
				return;
			}
			if (key) {
				Store.setItem(key, value);
			}
			callback(null, value);
		});
	},

	// key: The key of the store item to set with the response data
	// 	If key is set then the matching store item will be set
	// url: The url
	// data: The data to patch
	// callback: void function (err, responseData)
	patch(key, url, data, callback) {
		request('PATCH', data, (err, value) => {
			if (err) {
				callback(err);
				return;
			}
			if (key) {
				Store.setItem(key, value);
			}
			callback(null, value);
		});
	}
};<commit_msg>Added the missing url arg to the request invocations<commit_after>/*
 * The Http requester
 */
import { Store } from '../Store';

// callback: function (err, response)
//	where response is an object if JSON.parseable or is the responseText
function request(method, url, data, callback) {
	if (data === null || data === undefined) {
		data = undefined;
	} else if (typeof data === 'object') {
		data = JSON.stringify(data);
	}
	const request = new XMLHttpRequest();
	request.open(method.toUpperCase(), url, true);
	request.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');

	request.onload = function() {
		if (request.status >= 200 && request.status < 400) {
			try {
				callback(null, JSON.parse(request.responseText));
			} catch (e) {
				callback(null, request.responseText);
			}
		} else {
			callback(request.responseText);
		}
	};

	request.onerror = function() {
		callback('Failed to contact remote server');
	};

	if (data) {
		request.send(data);
	} else {
		request.send();
	}
}


export const Http = {
	// key: The key of the store item to set with the response data
	// 	If key is set then the matching store item will be set
	// url: The url
	// callback: void function (err, responseData)
	get(key, url, callback) {
		request('GET', url, null, (err, value) => {
			if (err) {
				callback(err);
				return;
			}
			if (key) {
				Store.setItem(key, value);
			}
			callback(null, value);
		});
	},

	// key: The key of the store item to set with the response data
	// 	If key is set then the matching store item will be set
	// url: The url
	// data: The data to post
	// callback: void function (err, responseData)
	post(key, url, data, callback) {
		request('POST', url, data, (err, value) => {
			if (err) {
				callback(err);
				return;
			}
			if (key) {
				Store.setItem(key, value);
			}
			callback(null, value);
		});
	},

	// key: The key of the store item to set with the response data
	// 	If key is set then the matching store item will be set
	// url: The url
	// data: The data to put
	// callback: void function (err, responseData)
	put(key, url, data, callback) {
		request('PUT', url, data, (err, value) => {
			if (err) {
				callback(err);
				return;
			}
			if (key) {
				Store.setItem(key, value);
			}
			callback(null, value);
		});
	},

	// key: The key of the store item to set with the response data
	// 	If key is set then the matching store item will be set
	// url: The url
	// callback: void function (err, responseData)
	delete(key, url, callback) {
		request('DELETE', url, null, (err, value) => {
			if (err) {
				callback(err);
				return;
			}
			if (key) {
				Store.setItem(key, value);
			}
			callback(null, value);
		});
	},

	// key: The key of the store item to set with the response data
	// 	If key is set then the matching store item will be set
	// url: The url
	// data: The data to patch
	// callback: void function (err, responseData)
	patch(key, url, data, callback) {
		request('PATCH', url, data, (err, value) => {
			if (err) {
				callback(err);
				return;
			}
			if (key) {
				Store.setItem(key, value);
			}
			callback(null, value);
		});
	}
};
{'fraction_non_alphanumeric': 0.14558587479935794, 'fraction_numerical': 0.0022471910112359553, 'mean_word_length': 2.894375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '1630368', 'n_tokens_mistral': 2349, 'n_tokens_neox': 2063, 'n_words': 715}