<commit_before>/*
 * @module
 * @description
 * Request utils for module
 */

var request = require('request');

module.exports = function (apiKey, options) {
    return {
        /*
         * @param API endopint {String}
         * @param Params {Object}
         * @param Callback {any}
         */
        buildQuery: function (endPoint, params) {
            // Build url
            let url;

            switch (options.api) {
                case 'upload':
                    url = "https://upload.wistia.com/";
                    break;

                case 'data':
                    url = "https://api.wistia.com/" + options.version + '/' + endPoint + "." + options.format;
                    break;
            }

            url += "?" + "api_password=" + apiKey + "&";

            let reqMethod = 'GET';

            if (typeof params._method != "undefined") {
                reqMethod = params._method;

                delete params._method;
            }

            if (typeof params.formEncoded != 'undefined') {
                delete params.formEncoded;

                return this._sendRequestUrlEncoded(url, params);
            } else {
                //Set params
                if (params) {
                    const paramKeys = Object.keys(params);

                    if (paramKeys.length > 0) {
                        for (let key in paramKeys) {
                            url += paramKeys[key] + "=" + params[paramKeys[key]] + "&";
                        }
                    }
                }

                return this._sendRequest(encodeURI(url), reqMethod);
            }
        },

        /*
         * @param API url {String}
         * @param Callback {any}
         */
        _sendRequest: function (url, method) {
			return new Promise((resolve, reject) => {
				request({
					url: url,
					method: method
				}, function (error, response, body) {
					if (error) {
						return cb(error);
					}

					if (response.statusCode == 200 || response.statusCode == 201) {
						resolve(body);
					} else {
						reject(new Error(`Server responded with error: ${response.statusCode}. Message: ${JSON.parse(body).error}`));
					}
				})
			})
        },

        /*
         * @param url {string}
         * @param FormData {Object}
         * @param Callback {any}
         */
        _sendRequestUrlEncoded: function (url, formData) {
			return new Promise((resolve, reject) => {
				request.post({url: url, formData: formData}, function (error, response, body) {
					if (error) {
						reject(error);
					}

					if (response.statusCode == 200 || response.statusCode == 201) {
						resolve(null, body);
					} else {
						reject(new Error(`Server responded with error: ${response.statusCode}. Message: ${JSON.parse(body).error}`));
					}
				});
			});
        }
    }

};<commit_msg>Parse JSON response from Wistia<commit_after>/*
 * @module
 * @description
 * Request utils for module
 */

var request = require('request');

module.exports = function (apiKey, options) {
    return {
        /*
         * @param API endopint {String}
         * @param Params {Object}
         * @param Callback {any}
         */
        buildQuery: function (endPoint, params) {
            // Build url
            let url;

            switch (options.api) {
                case 'upload':
                    url = "https://upload.wistia.com/";
                    break;

                case 'data':
                    url = "https://api.wistia.com/" + options.version + '/' + endPoint + "." + options.format;
                    break;
            }

            url += "?" + "api_password=" + apiKey + "&";

            let reqMethod = 'GET';

            if (typeof params._method != "undefined") {
                reqMethod = params._method;

                delete params._method;
            }

            if (typeof params.formEncoded != 'undefined') {
                delete params.formEncoded;

                return this._sendRequestUrlEncoded(url, params);
            } else {
                //Set params
                if (params) {
                    const paramKeys = Object.keys(params);

                    if (paramKeys.length > 0) {
                        for (let key in paramKeys) {
                            url += paramKeys[key] + "=" + params[paramKeys[key]] + "&";
                        }
                    }
                }

                return this._sendRequest(encodeURI(url), reqMethod);
            }
        },

        /*
         * @param API url {String}
         * @param Callback {any}
         */
        _sendRequest: function (url, method) {
			return new Promise((resolve, reject) => {
				request({
					url: url,
					method: method
				}, function (error, response, body) {
					if (error) {
						return cb(error);
					}

					if (response.statusCode == 200 || response.statusCode == 201) {
						resolve(JSON.parse(body));
					} else {
						reject(new Error(`Server responded with error: ${response.statusCode}. Message: ${JSON.parse(body).error}`));
					}
				})
			})
        },

        /*
         * @param url {string}
         * @param FormData {Object}
         * @param Callback {any}
         */
        _sendRequestUrlEncoded: function (url, formData) {
			return new Promise((resolve, reject) => {
				request.post({url: url, formData: formData}, function (error, response, body) {
					if (error) {
						reject(error);
					}

					if (response.statusCode == 200 || response.statusCode == 201) {
						resolve(JSON.parse(body));
					} else {
						reject(new Error(`Server responded with error: ${response.statusCode}. Message: ${JSON.parse(body).error}`));
					}
				});
			});
        }
    }

};
{'fraction_non_alphanumeric': 0.1325322187391153, 'fraction_numerical': 0.004528039010797631, 'mean_word_length': 1.4563729683490163, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 4, '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': '855155', 'n_tokens_mistral': 1813, 'n_tokens_neox': 1522, 'n_words': 363}