RubyMoney / google_currency

Ruby Money::Bank interface for the Google Currency exchange data
http://rubymoney.github.com/google_currency
MIT License
182 stars 90 forks source link

Money::Bank::GoogleCurrencyFetchError and NoMethodError: undefined method `to_money' for 1:Fixnum #61

Closed mpz closed 7 years ago

mpz commented 7 years ago

I just try to run example code from readme

In Gemfile:

gem "google_currency", '3.2.0'
gem "money", "6.5.0"
gem 'monetize'

This code work fine in production for several years. Now i have issue.

>> require 'money'
=> []
>> require 'money/bank/google_currency'
=> []
>> 
?> # (optional)
?> # set the seconds after than the current rates are automatically expired
?> # by default, they never expire
?> Money::Bank::GoogleCurrency.ttl_in_seconds = 86400
=> 86400
>> 
?> # set default bank to instance of GoogleCurrency
?> Money.default_bank = Money::Bank::GoogleCurrency.new
=> #<Money::Bank::GoogleCurrency:0x000000037ae9e8 @rounding_method=nil, @rates={}, @mutex=#<Mutex:0x000000037ae880>>
>> 
?> # create a new money object, and use the standard #exchange_to method
?> money = Money.new(1_00, "USD") # amount is in cents
=> #<Money fractional:100 currency:USD>
>> money.exchange_to(:EUR)
Money::Bank::GoogleCurrencyFetchError: Money::Bank::GoogleCurrencyFetchError
    from /home/mpz/.rvm/gems/ruby-2.1.10/gems/google_currency-3.2.0/lib/money/bank/google_currency.rb:160:in `extract_rate'
    from /home/mpz/.rvm/gems/ruby-2.1.10/gems/google_currency-3.2.0/lib/money/bank/google_currency.rb:129:in `fetch_rate'
    from /home/mpz/.rvm/gems/ruby-2.1.10/gems/google_currency-3.2.0/lib/money/bank/google_currency.rb:99:in `block in get_rate'
    from /home/mpz/.rvm/gems/ruby-2.1.10/gems/google_currency-3.2.0/lib/money/bank/google_currency.rb:98:in `synchronize'
    from /home/mpz/.rvm/gems/ruby-2.1.10/gems/google_currency-3.2.0/lib/money/bank/google_currency.rb:98:in `get_rate'
    from /home/mpz/.rvm/gems/ruby-2.1.10/gems/money-6.5.0/lib/money/bank/variable_exchange.rb:92:in `exchange_with'
    from /home/mpz/.rvm/gems/ruby-2.1.10/gems/money-6.5.0/lib/money/money.rb:454:in `exchange_to'
    from (irb):34
    from /home/mpz/.rvm/rubies/ruby-2.1.10/bin/irb:11:in `<main>'
>> 
?> # or install and use the 'monetize' gem
?> require 'monetize'
=> []
>> money = 1.to_money(:USD)
NoMethodError: undefined method `to_money' for 1:Fixnum
    from (irb):38
    from /home/mpz/.rvm/rubies/ruby-2.1.10/bin/irb:11:in `<main>'
>> money.exchange_to(:EUR)
Money::Bank::GoogleCurrencyFetchError: Money::Bank::GoogleCurrencyFetchError
    from /home/mpz/.rvm/gems/ruby-2.1.10/gems/google_currency-3.2.0/lib/money/bank/google_currency.rb:160:in `extract_rate'
    from /home/mpz/.rvm/gems/ruby-2.1.10/gems/google_currency-3.2.0/lib/money/bank/google_currency.rb:129:in `fetch_rate'
    from /home/mpz/.rvm/gems/ruby-2.1.10/gems/google_currency-3.2.0/lib/money/bank/google_currency.rb:99:in `block in get_rate'
    from /home/mpz/.rvm/gems/ruby-2.1.10/gems/google_currency-3.2.0/lib/money/bank/google_currency.rb:98:in `synchronize'
    from /home/mpz/.rvm/gems/ruby-2.1.10/gems/google_currency-3.2.0/lib/money/bank/google_currency.rb:98:in `get_rate'
    from /home/mpz/.rvm/gems/ruby-2.1.10/gems/money-6.5.0/lib/money/bank/variable_exchange.rb:92:in `exchange_with'
    from /home/mpz/.rvm/gems/ruby-2.1.10/gems/money-6.5.0/lib/money/money.rb:454:in `exchange_to'
    from (irb):39
    from /home/mpz/.rvm/rubies/ruby-2.1.10/bin/irb:11:in `<main>'
antstorm commented 7 years ago

@mpz try using the latest version (3.4.0) of this gem, which fixes the DNS issue with google's currency calculator

mpz commented 7 years ago

Thank @antstorm. It is work. Please close issue.