<commit_before>var request = require('request');
var xtend = require('xtend');

const URL_ROOT = 'https://api.blockcypher.com/v1/';

/**
 * <b>BlockCypher API Client</b>.
 * @constructor
 * @param {string}    coin    The coin for which you're using the BlockCypher API. Can be 'btc', 'ltc', 'doge', or 'bcy'.
 * @param {string}    chain   The chain for which you're using the BlockCypher API. Can be 'main', 'test', or 'test3'.
 * @param {string}    token   Your BlockCypher API Token.
 */
var Blockcy = function(coin, chain, token) {
	this.coin = coin;
	this.chain = chain;
	this.token = token;
};

module.exports = Blockcy;

/**
 * <b>Helper for GET calls</b>
 *
 * @private
 * @param {string}    url        Endpoint after URL_ROOT.
 * @param {Object}    params     Additional URL parameters.
 * @callback          cb
 * @memberof          Blockcy
 * @method            get
 */
Blockcy.prototype._get = function(url, params, cb) {
	var urlr = URL_ROOT + this.coin + '/' + this.chain + url;
	params = xtend(params, {token:this.token});
	request.get({
		url:urlr,
		strictSSL:true,
		json: true,
		qs: params
	}, function (error, response, body) {
		if (!error || response.statusCode !== 200) {
			cb(error, body || {});
		} else {
			cb(null, body);
		}
	});
};

/**
 * <b>Helper for POST calls</b>
 *
 * @private
 * @param {string}    url        Endpoint after URL_ROOT.
 * @param {Object}    params     Optional additional URL parameters.
 * @param {Object}    data       Optional data to post.
 * @callback          cb
 * @memberof          Blockcy
 * @method            post
 */
Blockcy.prototype._post = function(url, params, data, cb) {
	var urlr = URL_ROOT + this.coin + '/' + this.chain + url;
	params = xtend(params, {token:this.token});
	request.post({
		url:urlr,
		strictSSL:true,
		json: true,
		qs: params,
		body: data 
	}, function (error, response, body) {
		if (!error || (response.statusCode !== 200 && response.statusCode !== 201)) {
			cb(error, body || {});
		} else {
			cb(null, body);
		}
	});
};

/**
 * <b>Helper for DELETE calls</b>
 *
 * @private
 * @param {string}    url        Endpoint after URL_ROOT.
 * @param {Object}    params     Additional URL parameters.
 * @callback          cb
 * @memberof          Blockcy
 * @method            get
 */
Blockcy.prototype._del = function(url, params, cb) {
	var urlr = URL_ROOT + this.coin + '/' + this.chain + url;
	params = xtend(params, {token:this.token});
	request.del({
		url:urlr,
		strictSSL:true,
		json: true,
		qs: params
	}, function (error, response, body) {
		if (!error || response.statusCode !== 204) {
			cb(error, body || {});
		} else {
			cb(null, body);
		}
	});
};

/**
 * <b>Get Chain</b>
 * Get info about the blockchain you're querying.
 * @callback cb
 * @memberof Blockcy
 * @method getChain
 */
Blockcy.prototype.getChain = function(cb) {
	this._get('/',{}, function(error, body) {
		cb(error, body);
	});
};

/**
 * <b>Get Block</b><commit_msg>Error change on HTTP requests<commit_after>var request = require('request');
var xtend = require('xtend');

const URL_ROOT = 'https://api.blockcypher.com/v1/';

/**
 * <b>BlockCypher API Client</b>.
 * @constructor
 * @param {string}    coin    The coin for which you're using the BlockCypher API. Can be 'btc', 'ltc', 'doge', or 'bcy'.
 * @param {string}    chain   The chain for which you're using the BlockCypher API. Can be 'main', 'test', or 'test3'.
 * @param {string}    token   Your BlockCypher API Token.
 */
var Blockcy = function(coin, chain, token) {
	this.coin = coin;
	this.chain = chain;
	this.token = token;
};

module.exports = Blockcy;

/**
 * <b>Helper for GET calls</b>
 *
 * @private
 * @param {string}    url        Endpoint after URL_ROOT.
 * @param {Object}    params     Additional URL parameters.
 * @callback          cb
 * @memberof          Blockcy
 * @method            get
 */
Blockcy.prototype._get = function(url, params, cb) {
	var urlr = URL_ROOT + this.coin + '/' + this.chain + url;
	params = xtend(params, {token:this.token});
	request.get({
		url:urlr,
		strictSSL:true,
		json: true,
		qs: params
	}, function (error, response, body) {
		if (error || response.statusCode !== 200) {
			cb(error, body || {});
		} else {
			cb(null, body);
		}
	});
};

/**
 * <b>Helper for POST calls</b>
 *
 * @private
 * @param {string}    url        Endpoint after URL_ROOT.
 * @param {Object}    params     Optional additional URL parameters.
 * @param {Object}    data       Optional data to post.
 * @callback          cb
 * @memberof          Blockcy
 * @method            post
 */
Blockcy.prototype._post = function(url, params, data, cb) {
	var urlr = URL_ROOT + this.coin + '/' + this.chain + url;
	params = xtend(params, {token:this.token});
	request.post({
		url:urlr,
		strictSSL:true,
		json: true,
		qs: params,
		body: data 
	}, function (error, response, body) {
		if (error || (response.statusCode !== 200 && response.statusCode !== 201)) {
			cb(error, body || {});
		} else {
			cb(null, body);
		}
	});
};

/**
 * <b>Helper for DELETE calls</b>
 *
 * @private
 * @param {string}    url        Endpoint after URL_ROOT.
 * @param {Object}    params     Additional URL parameters.
 * @callback          cb
 * @memberof          Blockcy
 * @method            get
 */
Blockcy.prototype._del = function(url, params, cb) {
	var urlr = URL_ROOT + this.coin + '/' + this.chain + url;
	params = xtend(params, {token:this.token});
	request.del({
		url:urlr,
		strictSSL:true,
		json: true,
		qs: params
	}, function (error, response, body) {
		if (error || response.statusCode !== 204) {
			cb(error, body || {});
		} else {
			cb(null, body);
		}
	});
};

/**
 * <b>Get Chain</b>
 * Get info about the blockchain you're querying.
 * @callback cb
 * @memberof Blockcy
 * @method getChain
 */
Blockcy.prototype.getChain = function(cb) {
	this._get('/',{}, function(error, body) {
		cb(error, body);
	});
};

/**
 * <b>Get Block</b>
{'fraction_non_alphanumeric': 0.1639316528506175, 'fraction_numerical': 0.004736931145322281, 'mean_word_length': 2.836469824789098, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 2, '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': '1594459', 'n_tokens_mistral': 2128, 'n_tokens_neox': 2013, 'n_words': 553}