lib/fixer/request.rb in fixer-rb-0.1.1 vs lib/fixer/request.rb in fixer-rb-0.1.2

- old
+ new

@@ -1,9 +1,10 @@ module Fixer class Request attr_reader :response def initialize(base = Fixer.base) + @base = base base_host = "https://api.fixer.io/latest?base=#{base}" @response = HTTParty.get(base_host) end def transfer(data) @@ -18,9 +19,18 @@ end end else raise "only hash allowed" end + end + + def get_rate + result = JSON.parse @response.body, symbolize_names: true + base = {base: @base} + rates = result[:rates] + currencies = base.merge(rates) + r_obj = OpenStruct.new currencies + yield r_obj end private def valid_currency?(currency) valid_currencies = ["EUR", "AUD", "BGN", "BRL", "CAD", "CHF", "CNY",