Hardika Desai
Hardika Desai

Reputation: 83

Google Finance currency converter issue in rails

I am working on Google currency converter but it's not working. It just redirects to:

http://finance.google.com:80/bctzjpnsun/converter?a=1&from=EUR&to=USD

or it's gives error 404 Not Found

This my code:

gem file:

gem 'money'
gem 'google_currency', '~> 3.4.1'

converter method

def self.exchange_to_USD annual_salary, currency
  begin
    mothly_salary = annual_salary / 12
    if currency.present?
      salary = Money.new(mothly_salary, currency).exchange_to(:USD).fractional
    else
      salary = mothly_salary  
    end
  rescue Money::Bank::UnknownRate => e
    salary = mothly_salary
  rescue Exception => e
    salary = mothly_salary
  end
  salary
end

application.rb file

require 'money'
require 'money/bank/google_currency'

# set the seconds after than the current rates are automatically expired
# by default, they never expire
Money::Bank::GoogleCurrency.ttl_in_seconds = 86400

# set default bank to instance of GoogleCurrency
Money.default_bank = Money::Bank::GoogleCurrency.new

Upvotes: 1

Views: 605

Answers (2)

Joshua Pinter
Joshua Pinter

Reputation: 47551

Use eu_central_bank Instead.

We ended up replacing google_currency with eu_central_bank and it was very easy and worked great. It's part of RubyMoney so it should be well maintained. Basic replacement looks like this:

eu_central_bank = EuCentralBank.new

eu_central_bank.update_rates # TODO: Make this use a cache in a shared directory and just update it every day.

Money.default_bank = eu_central_bank

Definitely a good option to consider.

Upvotes: 1

durzel
durzel

Reputation: 3

Google has depreciated that way of retrieving rates. Previously the "bctzjpnsun" link was an alternative way of getting them, but that was switched off recently (possibly on 01-Jun-2018).

You can find some alternative services here: https://stackoverflow.com/a/8391430/6038636

Upvotes: 0

Related Questions