<commit_before>'use strict';

(function() {

	var module = angular.module('hermes', []);

	module.provider('Hermes', function() {
		var defaultConfiguration;

		var Configuration = function() {
			this.baseUrl = '';
			this.requestBuilderHooks = [];
			this.responseErrorHooks = [];

			this.setBaseUrl = function(url) {
				this.baseUrl = url;

				if (this.baseUrl[this.baseUrl.length - 1] == '/') {
					this.baseUrl = this.baseUrl.substr(0, this.baseUrl.length - 1);
				}
			};
		};

		var Element = function(service, baseUrl, name) {
			var methods = ['get', 'put', 'post', 'patch', 'delete'];
			var url = baseUrl + '/' + name;

			_.each(methods, function(method) {
				this[method] = function(config) {
					return service.sendRequest(method, url, config || {});
				};
			}, this);

			this.element = function(name) {
				return new Element(service, url, name);
			};
		};

		var createService = function($q, $http, configuration) {
			var service = {};

			service.configuration = configuration;

			service.processRequest = function(requestData) {
				var self = this;
				var request = _.extend(requestData.request, {});

				_.each(this.configuration.requestBuilderHooks, function(hook) {
					request = hook(request);
				}, this);

				$http(request).success(function(data, status, headers, config) {
					requestData.result.resolve(data, status, headers);
				}).error(function(data, status, headers, config) {
					_.each(self.configuration.responseErrorHooks, function(hook) {
						var result = hook(data, status, headers, request);

						if (_.isObject(result)) {
							result.then(function() {
								this.processRequest(requestData);
							});
						} else {
							requestData.result.reject(data, status, headers);
						}
					}, self);
				});
			};

			service.sendRequest = function(method, url, config) {
				var deferred = $q.defer();

				var request = _.extend(config, {
					url: url,
					method: method,
					headers: config.headers || {},
					params: config.params || {}
				});

				var requestData = {
					request: request,
					result: deferred
				};

				this.processRequest(requestData);

				return deferred.promise;
			};

			service.element = function(name) {
				return new Element(this, configuration.baseUrl, name);
			};

			return service;
		};

		defaultConfiguration = new Configuration();

		this.Configuration = Configuration;
		this.defaultConfiguration = defaultConfiguration;
		this.createService = createService;

		this.$get = function($q, $http) {
			return createService($q, $http, defaultConfiguration);
		};
	});

})();
<commit_msg>Fix bug.<commit_after>'use strict';

(function() {

	var module = angular.module('hermes', []);

	module.provider('Hermes', function() {
		var defaultConfiguration;

		var Configuration = function() {
			this.baseUrl = '';
			this.requestBuilderHooks = [];
			this.responseErrorHooks = [];

			this.setBaseUrl = function(url) {
				this.baseUrl = url;

				if (this.baseUrl[this.baseUrl.length - 1] == '/') {
					this.baseUrl = this.baseUrl.substr(0, this.baseUrl.length - 1);
				}
			};
		};

		var Element = function(service, baseUrl, name) {
			var methods = ['get', 'put', 'post', 'patch', 'delete'];
			var url = baseUrl + '/' + name;

			_.each(methods, function(method) {
				this[method] = function(config) {
					return service.sendRequest(method, url, config || {});
				};
			}, this);

			this.element = function(name) {
				return new Element(service, url, name);
			};
		};

		var createService = function($q, $http, configuration) {
			var service = {};

			service.configuration = configuration;

			service.processRequest = function(requestData) {
				var self = this;
				var request = _.extend(requestData.request, {});

				_.each(this.configuration.requestBuilderHooks, function(hook) {
					request = hook(request);
				}, this);

				$http(request).success(function(data, status, headers, config) {
					requestData.result.resolve(data, status, headers);
				}).error(function(data, status, headers, config) {
					_.each(self.configuration.responseErrorHooks, function(hook) {
						var result = hook(data, status, headers, request);

						if (_.isObject(result)) {
							result.then(function() {
								self.processRequest(requestData);
							});
						} else {
							requestData.result.reject(data, status, headers);
						}
					}, self);
				});
			};

			service.sendRequest = function(method, url, config) {
				var deferred = $q.defer();

				var request = _.extend(config, {
					url: url,
					method: method,
					headers: config.headers || {},
					params: config.params || {}
				});

				var requestData = {
					request: request,
					result: deferred
				};

				this.processRequest(requestData);

				return deferred.promise;
			};

			service.element = function(name) {
				return new Element(this, configuration.baseUrl, name);
			};

			return service;
		};

		defaultConfiguration = new Configuration();

		this.Configuration = Configuration;
		this.defaultConfiguration = defaultConfiguration;
		this.createService = createService;

		this.$get = function($q, $http) {
			return createService($q, $http, defaultConfiguration);
		};
	});

})();

{'fraction_non_alphanumeric': 0.15181835674427555, 'fraction_numerical': 0.0011545122185876468, 'mean_word_length': 3.148443735035914, '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': '1012634', 'n_tokens_mistral': 2006, 'n_tokens_neox': 1527, 'n_words': 323}