Class: ExchangerFixer

Inherits:
ExchangerBase show all
Defined in:
lib/mrpin/core/currency_exchanger/fixer/exchanger_fixer.rb

Instance Method Summary collapse

Constructor Details

#initializeExchangerFixer



13
14
15
16
17
# File 'lib/mrpin/core/currency_exchanger/fixer/exchanger_fixer.rb', line 13

def initialize
  super

  @exchanger_api = ManagerRemoteHttp.new(url: 'http://api.fixer.io')
end

Instance Method Details

#get_rate(from_currency, to_currency) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/mrpin/core/currency_exchanger/fixer/exchanger_fixer.rb', line 21

def get_rate(from_currency, to_currency)

  params =
      {
          base:    from_currency,
          symbols: to_currency
      }

  response = @exchanger_api.get('latest', params)

  assert(response[:status] == EResponseType::ERT_OK, response)

  response_exchanger = JSON.parse response[:response], {symbolize_names: true}

  rate_string = response_exchanger.assert_property!(:rates).assert_property!(to_currency.to_sym)

  rate_string.to_f
end