module SbifRails::Base
Constants
- URL
Public Instance Methods
api_key()
click to toggle source
# File lib/sbif-rails/base.rb, line 9 def api_key @api_key ||= SbifRails.config.api_key end
get_by_month(year, month)
click to toggle source
# File lib/sbif-rails/base.rb, line 13 def get_by_month(year, month) url = "#{URL}/#{name}/#{year.to_s}/#{month.to_s}?apikey=#{api_key}&formato=json" uri = URI(url) response = Net::HTTP.get uri currencies_response = JSON.parse response currencies = Array.new currencies_response["#{plural_name}"].each do |currency| currency_date = currency['Fecha'].to_s.split('-') date = Date.new(currency_date[0].to_i, currency_date[1].to_i, currency_date[2].to_i) currencies << Currency.new(date, currency['Valor'].gsub('.', '').gsub(',', '.').to_f) end currencies end
get_by_year(year)
click to toggle source
# File lib/sbif-rails/base.rb, line 27 def get_by_year(year) url = "#{URL}/#{name}/#{year.to_s}?apikey=#{api_key}&formato=json" uri = URI(url) response = Net::HTTP.get uri currencies_response = JSON.parse response currencies = Array.new currencies_response["#{plural_name}"].each do |currency| currency_date = currency['Fecha'].to_s.split('-') date = Date.new(currency_date[0].to_i, currency_date[1].to_i, currency_date[2].to_i) currencies << Currency.new(date, currency['Valor'].gsub('.', '').gsub(',', '.').to_f) end currencies end