<commit_before>var urllib = require('urllib');
var moment = require('moment');
var crypto = require('crypto');
var _ = require('lodash');

/**
 * 根据appid和appsecret创建API的构造函数
 * @param {String} appid       在口袋通申请得到的appid
 * @param {String} appsecret   在口袋通申请得到的app secret
 * @param {String} format      （可选）指定响应格式。默认json,目前支持格式为json
 * @param {String} apiVersion  （可选）API协议版本，可选值:1.0，默认1.0
 * @param {String} signMethod  （可选）参数的加密方法选择。默认为md5，可选值是：md5
 */
var API = function (appid, appsecret, format, apiVersion, signMethod) {
  this.appid = appid;
  this.appsecret = appsecret;
  this.format = format || 'json';
  this.v = apiVersion || '1.0';
  this.signMethod = signMethod || 'md5';
  this.prefix = 'http://open.koudaitong.com/api/entry';
};

API.prototype.get = function(method, apiParams, callback) {
  var params = this.buildRequestParams(method, apiParams);
  var paramsStr = '?';
  params.forEach(function (item) {
    paramsStr += item.name;
    paramsStr += '=';
    paramsStr += item.value;
    paramsStr += '&';
  });
  var url = this.prefix + paramsStr;
  var opts = {
    method: 'GET',
    dataType: 'json',
    timeout: 3000
  }
  urllib.request(url, opts, function (err, data, res) {<commit_msg>query string and url basa64 safe code<commit_after>var urllib = require('urllib');
var moment = require('moment');
var crypto = require('crypto');
var _ = require('lodash');
var querystring = require('querystring'); //FIX

/**
 * 根据appid和appsecret创建API的构造函数
 * @param {String} appid       在口袋通申请得到的appid
 * @param {String} appsecret   在口袋通申请得到的app secret
 * @param {String} format      （可选）指定响应格式。默认json,目前支持格式为json
 * @param {String} apiVersion  （可选）API协议版本，可选值:1.0，默认1.0
 * @param {String} signMethod  （可选）参数的加密方法选择。默认为md5，可选值是：md5
 */
var API = function (appid, appsecret, format, apiVersion, signMethod) {
  this.appid = appid;
  this.appsecret = appsecret;
  this.format = format || 'json';
  this.v = apiVersion || '1.0';
  this.signMethod = signMethod || 'md5';
  this.prefix = 'http://open.koudaitong.com/api/entry';
};

API.prototype.get = function(method, apiParams, callback) {
  var params = this.buildRequestParams(method, apiParams);
  var _params = {};
    params.forEach(function(item) {
        _params[item.name] = item.value;
    });
  var url = this.prefix + '?' + querystring.stringify(_params);
  var opts = {
    method: 'GET',
    dataType: 'json',
    timeout: 3000
  };
  urllib.request(url, opts, function (err, data, res) {
{'fraction_non_alphanumeric': 0.15556458164094233, 'fraction_numerical': 0.011372867587327376, 'mean_word_length': 4.099378881987578, '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': '4364614', 'n_tokens_mistral': 964, 'n_tokens_neox': 983, 'n_words': 189}