class Genial::Currency
Public Class Methods
convert(from, to, value)
click to toggle source
# File lib/genial.rb, line 26 def self.convert(from, to, value) convert_response(get("/convert?from=#{from}&to=#{to}&value=#{value}")) end
dollar()
click to toggle source
# File lib/genial.rb, line 14 def self.dollar parse_response(get("/currency?code=USD")) end
euro()
click to toggle source
# File lib/genial.rb, line 18 def self.euro parse_response(get("/currency?code=EUR")) end
find(code)
click to toggle source
# File lib/genial.rb, line 10 def self.find(code) parse_response(get("/currency?code=#{code}")) end
pound()
click to toggle source
# File lib/genial.rb, line 22 def self.pound parse_response(get("/currency?code=GBP")) end
Private Class Methods
convert_response(response)
click to toggle source
# File lib/genial.rb, line 36 def self.convert_response(response) case response.code when 200 response.parsed_response["result"].to_f.round(2) when 404 puts "moeda(s) não encontrada(s)" when 400 puts "solicitação inválida" when 500 puts "erro interno." end end
parse_response(response)
click to toggle source
# File lib/genial.rb, line 32 def self.parse_response(response) response.parsed_response["buying_rate"].to_f.round(2) end