<commit_before>var request = require('request');
var Promise = require("bluebird");
Promise.promisifyAll(require("request"));

/**
 * 开始执行请求
 */
function startTask(jsonObj, completeCallback) {

	switch(jsonObj.type) {
		case 'get' : 
			return getRequest(jsonObj, completeCallback);
		break;

		case 'post' :
			return postRequest(jsonObj, completeCallback);
		break;

		default:
			console.log('不支持所提供的方式');
	};	
}

exports.task = startTask;

/**
 * GET请求
 */
function getRequest(jsonObj, completeCallback) {
	//开始飞吧
	return request.getAsync({
		url : jsonObj.url, 
		form: jsonObj.params
	}).spread(function(httpResponse, body){
		var err = null;
    return completeCallbackAgent(jsonObj, err, httpResponse, body, completeCallback);
	}).error(function(err){
		console.error("unable to get, because: ", err.message);
		var body = null;
		var httpResponse = null;
	   //handle error here
    return completeCallbackAgent(jsonObj, err, httpResponse, body, completeCallback);
	})
	
	// request.get(
// 		{
// 			url : jsonObj.url,
// 			form: jsonObj.params
// 		},
// 		function(err,httpResponse,body){
// 			completeCallbackAgent(jsonObj, err, httpResponse, body, completeCallback);
// 		});
}

/**
 * POST请求
 */
function postRequest(jsonObj, completeCallback) {
	request.post(
		{
			url : jsonObj.url, 
			form: jsonObj.params
		}, 
		function(err,httpResponse,body){
			completeCallbackAgent(jsonObj, err, httpResponse, body, completeCallback);
		});
}

/**
 *	返回格式转换
 */
function completeCallbackAgent(jsonObj, err, httpResponse, body, callback) {
	
	if (err) {
		body = null;
	}else {
		body = JSON.parse(body);
	}

	callback(jsonObj, err, httpResponse, body);
}<commit_msg>给post方法增加promise<commit_after>var request = require('request');
var Promise = require("bluebird");
Promise.promisifyAll(require("request"));

/**
 * 开始执行请求
 */
function startTask(jsonObj, completeCallback) {

	switch(jsonObj.type) {
		case 'get' : 
			return getRequest(jsonObj, completeCallback);
		break;

		case 'post' :
			return postRequest(jsonObj, completeCallback);
		break;

		default:
			console.log('不支持所提供的方式');
	};	
}

exports.task = startTask;

/**
 * GET请求
 */
function getRequest(jsonObj, completeCallback) {
	//开始飞吧
	return request.getAsync({
		url : jsonObj.url, 
		form: jsonObj.params
	}).spread(function(httpResponse, body){
		var err = null;
    return completeCallbackAgent(jsonObj, err, httpResponse, body, completeCallback);
	}).error(function(err){
		console.error("unable to get, because: ", err.message);
		var body = null;
		var httpResponse = null;
	   //handle error here
    return completeCallbackAgent(jsonObj, err, httpResponse, body, completeCallback);
	})
	
	// request.get(
// 		{
// 			url : jsonObj.url,
// 			form: jsonObj.params
// 		},
// 		function(err,httpResponse,body){
// 			completeCallbackAgent(jsonObj, err, httpResponse, body, completeCallback);
// 		});
}

/**
 * POST请求
 */
function postRequest(jsonObj, completeCallback) {
	return request.postAsync({
		url : jsonObj.url, 
		form: jsonObj.params
	}).spread(function(httpResponse, body){
		var err = null;
    return completeCallbackAgent(jsonObj, err, httpResponse, body, completeCallback);
	}).error(function(err){
		console.error("unable to get, because: ", err.message);
		var body = null;
		var httpResponse = null;
	   //handle error here
    return completeCallbackAgent(jsonObj, err, httpResponse, body, completeCallback);
	})
	
	// request.post(
	// 	{
	// 		url : jsonObj.url,
	// 		form: jsonObj.params
	// 	},
	// 	function(err,httpResponse,body){
	// 		completeCallbackAgent(jsonObj, err, httpResponse, body, completeCallback);
	// 	});
}

/**
 *	返回格式转换
 */
function completeCallbackAgent(jsonObj, err, httpResponse, body, callback) {
	
	if (err) {
		body = null;
	}else {
		body = JSON.parse(body);
	}

	callback(jsonObj, err, httpResponse, body);
}
{'fraction_non_alphanumeric': 0.14690587623504942, 'fraction_numerical': 0.0, 'mean_word_length': 3.9638709677419355, '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': '3466902', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1307, 'n_words': 268}