Class: Changer
- Inherits:
-
Object
- Object
- Changer
- Defined in:
- lib/currency.rb
Instance Attribute Summary collapse
-
#rate ⇒ Object
readonly
Returns the value of attribute rate.
Instance Method Summary collapse
-
#initialize(from_type, to_type) ⇒ Changer
constructor
A new instance of Changer.
Constructor Details
#initialize(from_type, to_type) ⇒ Changer
Returns a new instance of Changer.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/currency.rb', line 9 def initialize(from_type, to_type) from_type = from_type.to_s.upcase to_type = to_type.to_s.upcase url = URI("https://currency-exchange.p.rapidapi.com/exchange?to=#{to_type}&from=#{from_type}&q=1.0") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(url) request["x-rapidapi-key"] = ENV['RAPID_API_KEY'] request["x-rapidapi-host"] = 'currency-exchange.p.rapidapi.com' response = http.request(request) @rate = JSON.parse(response.read_body).to_f end |
Instance Attribute Details
#rate ⇒ Object (readonly)
Returns the value of attribute rate.
7 8 9 |
# File 'lib/currency.rb', line 7 def rate @rate end |