module SbifRails::Base::GetByDayMethods
Public Instance Methods
get_by_day(year, month, day)
click to toggle source
# File lib/sbif-rails/base.rb, line 47 def get_by_day(year, month, day) date = Date.new(year, month, day) currencies_response = Array.new # looking for business day loop do url = "#{URL}/#{name}/#{date.year.to_s}/#{date.month.to_s}/dias/#{date.day}?apikey=#{api_key}&formato=json" uri = URI(url) response = Net::HTTP.get uri currencies_response = JSON.parse response break if currencies_response["#{plural_name}"] date -= 1 end Currency.new(date, currencies_response["#{plural_name}"][0]['Valor'].gsub('.', '').gsub(',', '.').to_f) end
get_current()
click to toggle source
# File lib/sbif-rails/base.rb, line 42 def get_current today = Date.today get_by_day(today.year, today.month, today.day) end