lib/concurrency.rb in concurrency-0.2.0 vs lib/concurrency.rb in concurrency-1.0.0
- old
+ new
@@ -4,11 +4,11 @@
require 'json'
module Concurrency
class << self
attr_accessor :configuration
- end
+ end
def self.configuration
@configuration ||= Configuration.new
end
@@ -52,18 +52,21 @@
return initial*rate
end
end
def self.get_rate(from, to)
- url = "https://free.currencyconverterapi.com/api/v3/convert?q=#{from}_#{to}&compact=ultra"
+ puts "From:#{from}>>TO:#{to}>>APIKEY:#{Concurrency.configuration.api_key}"
+ if Concurrency.configuration.api_key.nil?
+ raise "API Key is missing. Kindly set API key CONCURRENCY_APIKEY."
+ end
+ url = "https://free.currencyconverterapi.com/api/v6/convert?q=#{from}_#{to}&compact=ultra&apiKey=#{Concurrency.configuration.api_key}"
uri = URI(url)
response = Net::HTTP.get(uri)
if response == nil
return nil
else
parsed_response = JSON.parse(response)
rate = (parsed_response["#{from}_#{to}"]).to_f
return rate
end
- end
-
+ end
end