Module: AlipayGlobal::Service::Exchange

Defined in:
lib/alipay_global/service/exchange.rb

Class Method Summary collapse

Class Method Details

.build_requestObject



23
24
25
26
27
28
29
30
# File 'lib/alipay_global/service/exchange.rb', line 23

def self.build_request
  params = {
    'service'         => 'forex_rate_file',
    'partner'         => AlipayGlobal.api_partner_id,
  }

  AlipayGlobal::Service.request_uri(params).to_s
end

.current_ratesObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/alipay_global/service/exchange.rb', line 7

def self.current_rates
  exchange_rates_resp = {}
  open(build_request) do |file|
    file.each_line do |line|
      line = line.strip
      rate_results = line.split("|")

      exchange_rates_resp[rate_results[2]] = {
        time: DateTime.strptime("#{rate_results[0]} #{rate_results[1]}","%Y%m%d %H%M%S"),
        rate: rate_results[3].to_f
      }
    end
  end
  exchange_rates_resp
end