<commit_before>"use strict";

/**
 * Rest module 
 */
 
var https = require('https');

/**
 * Generic REST invocation function
 * Should handle all verbs
 * @param	  {object}	  opts		  options for request
 * @param  	{string}	  body		  body of request
 * @param  	{Function}	callback	function(data) error handling & parseing should be done by module
 */
function rest(opts, body, callback) {
  var callbackArgs = [],
      isDone = false;

  function finish(err, res) {
    if (isDone) return; //This would only happen if an error occurs AFTER the res has ended...doubtful that would ever happen.

    if (err) {
      callbackArgs[0] = err; //If there's an error and no res, collect it and keep waiting until the 'end' event
    } else {
      isDone = true;
      callbackArgs[1] = res;
      callback.apply(null, callbackArgs); //Pass both the err and res to the callback, because often times the body will be just fine despite errors
    }
  }

  var req = https.request(opts, function(res) {
    var data = '';

    res.on('data', function(d){data+=d;}); //capture data
    res.on('end', function(){
      res.body = res.message = data;
      finish(null, res);
    });
  });

  req.on('error', function(e) {
    console.log('[rest] error' + e);
    finish(e);
  });

  req.write(body);
  req.end();
}

module.exports = rest;<commit_msg>rest object form<commit_after>"use strict";

/**
 * Rest module 
 */

/**
*	rest
*	@param	{boolean}		secure	boolean ? https : http
*	@return	{object}						rest object
*	@constructor
*/
function rest(secure){
	var self = this;
	var type = (secure) ? "https" : "http";
	self.protocol = require(type);
	return self;
}

rest.prototype = {
	/**
 * Generic REST invocation function
 * Should handle all verbs
 * @param	  {object}	  opts		  options for request
 * @param  	{string}	  body		  body of request
 * @param  	{Function}	callback	function(data) error handling & parseing should be done by module
 */
	request : function(opts, body, callback){
		var callbackArgs = [], isDone = false, self = this;

		function finish(err, res) {
			if (isDone){
				//This would only happen if an error occurs AFTER the res has ended...doubtful that would ever happen.
				return;
			}
			
			if (err) {
				//If there's an error and no res, collect it and keep waiting until the 'end' event
				callbackArgs[0] = err;
			} else {
				isDone = true;
				callbackArgs[1] = res;
				//Pass both the err and res to the callback, because often times the body will be just fine despite errors
				callback.apply(null, callbackArgs);
			}
		}

		var req = self.protocol.request(opts, function(res) {
			var data = '';

			res.on('data', function(d){data+=d;}); //capture data
			res.on('end', function(){
				//TODO remove support for res.message
				res.body = res.message = data;
				finish(null, res);
			});
		});

		req.on('error', function(e) {
			console.log('[rest] error' + e);
			finish(e);
		});

		req.write(body);
		req.end();
		}
}

module.exports = rest;
{'fraction_non_alphanumeric': 0.13612040133779263, 'fraction_numerical': 0.0013377926421404682, 'mean_word_length': 2.940711462450593, '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': '3237199', 'n_tokens_mistral': 1043, 'n_tokens_neox': 941, 'n_words': 320}