<commit_before>/**
 * Dependencies
 */

var https = require('https');
var debug = require('debug')('domoweb');
var merge = require('merge-descriptors');

/**
 * Prototype
 */

var domoweb = exports = module.exports = {};

/**
 * Attach Functions
 */

/**
 * Domoweb Request
 * Basically just http.request(), adding the token header in
 */
domoweb.domoRequest = function(data, options, cb)
{

	// Set up the post data we're sending across
	var postData = null;

	switch(options.contentType)
	{
		// For JSON, stringify the object
		case "application/json": postData = JSON.stringify(data); break;

		// TODO Some requests use text/xml and other odd request types

		// Otherwise just send it along as is
		default: postData = data; break;
	}

	var options = {
		hostname: settings._instance,
		port: 443,
		path: options.path,
		method: options.method,
		headers: {
			'X-DOMO-Developer-Token': settings._authtoken,
			'Content-Type': options.contentType,
			'Content-Length': postData.length
		}
	};

	// Run the request and handle the callbacks
	var req = https.request(options, function(res){

		res.setEncoding('utf8');
		
		var responseData = "";

		// This is probably bad - if multiple data events are triggered the callback will fire multiple times
		// TODO: Fix this before it becomes a problem
		res.on('data', function(responseChunk){
			responseData += responseChunk;
		});
		
		res.on('end', function(){
			// Run the callback with the response data
			cb(null, JSON.parse(responseData));	
		});

	});

	req.on('error', function(e) {
		// TODO Implement better error handling
		debug(e);
	});

	// Send the request
	req.write(postData);
	req.end();

}<commit_msg>I fixed it!<commit_after>/**
 * Dependencies
 */

var https = require('https');
var debug = require('debug')('domoweb');
var merge = require('merge-descriptors');

/**
 * Prototype
 */

var domoweb = exports = module.exports = {};

/**
 * Attach Functions
 */

/**
 * Domoweb Request
 * Basically just http.request(), adding the token header in
 */
domoweb.domoRequest = function(data, options, cb)
{

	// Set up the post data we're sending across
	var postData = null;

	switch(options.contentType)
	{
		// For JSON, stringify the object
		case "application/json": postData = JSON.stringify(data); break;

		// TODO Some requests use text/xml and other odd request types

		// Otherwise just send it along as is
		default: postData = data; break;
	}

	var options = {
		hostname: settings._instance,
		port: 443,
		path: options.path,
		method: options.method,
		headers: {
			'X-DOMO-Developer-Token': settings._authtoken,
			'Content-Type': options.contentType,
			'Content-Length': postData.length
		}
	};

	// Run the request and handle the callbacks
	var req = https.request(options, function(res){

		res.setEncoding('utf8');
		
		var responseData = "";

		res.on('data', function(responseChunk){
			responseData += responseChunk;
		});
		
		res.on('end', function(){
			// Run the callback with the response data
			cb(null, JSON.parse(responseData));	
		});

	});

	req.on('error', function(e) {
		// TODO Implement better error handling
		debug(e);
	});

	// Send the request
	req.write(postData);
	req.end();

}
{'fraction_non_alphanumeric': 0.14040025015634772, 'fraction_numerical': 0.0025015634771732333, 'mean_word_length': 3.4866760168302946, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '294739', 'n_tokens_mistral': 1098, 'n_tokens_neox': 986, 'n_words': 294}