class ExchangerFixer

Public Class Methods

new() click to toggle source

default constructor

Calls superclass method ExchangerBase::new
# 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

Public Instance Methods

get_rate(from_currency, to_currency) click to toggle source
# File lib/mrpin/core/currency_exchanger/fixer/exchanger_fixer.rb, line 21
def get_rate(from_currency, to_currency)
  result = nil

  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}

  rates = response_exchanger.assert_property!(:rates)

  #not all currencies supported by fixer.io. So we need check them.
  if rates.has_key?(to_currency.to_sym)
    rate_string = rates[to_currency.to_sym]
    result      = rate_string.to_f
  end

  result
end