<commit_before>var _ = require('lodash')

var AlipaySubmit = require('./AlipaySubmit')

// test key
// real gate way = https://mapi.alipay.com/gateway.do?
var defaultConfig = {
  partner: '2088101122136241',
  key: '<KEY>',
  gateway: 'https://openapi.alipaydev.com/gateway.do?',
  sign_type: 'MD5'
}

function Alipay (config) {
  this.config = config ? _.assignIn(defaultConfig, config) : defaultConfig
}

Alipay.prototype.payment = function (params) {
  var alipaySubmit = new AlipaySubmit(this.config)
  return alipaySubmit.buildRequest(_.extend({}, {
    service: 'create_forex_trade'
  }, params), 'get')
}

Alipay.prototype.loadExchangeRate = function (cb) {
  var alipaySubmit = new AlipaySubmit(this.config)
  var param = alipaySubmit.buildRequestPara({
    service: 'forex_rate_file'
  })
  return alipaySubmit.request({
    data: param
  }, function (err, resp, body) {
    if (err) {
      return cb(err)
    }
    cb(null, _.map(body.split('\n'), function (str) {
      var o = str.split('|')
      var dt = strToDate('' + o[0] + o[1])
      return {
        date: dt,
        currency: o[2],
        rate: parseFloat(o[3])
      }
    }))
  })
}

function strToDate (str) {
  return new Date(
    str.substring(0, 4),
    str.substring(4, 6) - 1,
    str.substring(6, 8),
    str.substring(8, 10),
    str.substring(10, 12),
    str.substring(12, 14)<commit_msg>Exchange rate data sgtructure change.<commit_after>var _ = require('lodash')

var AlipaySubmit = require('./AlipaySubmit')

// test key
// real gate way = https://mapi.alipay.com/gateway.do?
var defaultConfig = {
  partner: '2088101122136241',
  key: '<KEY>',
  gateway: 'https://openapi.alipaydev.com/gateway.do?',
  sign_type: 'MD5'
}

function Alipay (config) {
  this.config = config ? _.assignIn(defaultConfig, config) : defaultConfig
}

Alipay.prototype.payment = function (params) {
  var alipaySubmit = new AlipaySubmit(this.config)
  return alipaySubmit.buildRequest(_.extend({}, {
    service: 'create_forex_trade'
  }, params), 'get')
}

Alipay.prototype.loadExchangeRate = function (cb) {
  var alipaySubmit = new AlipaySubmit(this.config)
  var param = alipaySubmit.buildRequestPara({
    service: 'forex_rate_file'
  })
  return alipaySubmit.request({
    data: param
  }, function (err, resp, body) {
    if (err) {
      return cb(err)
    }
    cb(null, _.reduce(body.split('\n'), function (map, str) {
      var o = str.split('|')
      var dt = strToDate('' + o[0] + o[1])
      map[o[2]] = {
        rate: parseFloat(o[3]),
        ts: Math.floor(dt.getTime() / 1000)
      }
      return map
    }, {}))
  })
}

function strToDate (str) {
  return new Date(
    str.substring(0, 4),
    str.substring(4, 6) - 1,
    str.substring(6, 8),
    str.substring(8, 10),
    str.substring(10, 12),
    str.substring(12, 14)
{'fraction_non_alphanumeric': 0.15972963358235504, 'fraction_numerical': 0.029171113482746355, 'mean_word_length': 3.2222222222222223, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5848914', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1027, 'n_words': 213}