Giter Site home page Giter Site logo

eu_central_bank's People

Contributors

ahukkanen avatar alto avatar antstorm avatar bak1an avatar boone avatar ej2015 avatar fedorn avatar flop avatar holek avatar ilake avatar joshuapinter avatar kevthedev avatar kriskhaira avatar laurens avatar liangzan avatar lomefin avatar maltoe avatar mcls avatar mgadikota-rpx avatar overloadedargs avatar pabse avatar petergoldstein avatar prognostikos avatar richardvenneman avatar saurabhnanda avatar semmons99 avatar suciuvlad avatar taki avatar timdiggins avatar zachaysan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eu_central_bank's Issues

Update gem on rubygems

eu_central_bank on RubyGems still require 6.8.0 rather than 6.9.0 is there a possibility for you to push a update?

Avoid nokogiri?

I was observing that it took long to build nokogiri so I thought I'd try to have a take on building a bank. ECB publishes the rates in CSV (zipped), so I build a simple bank that use that instead of the XML file.

https://github.com/ct-clearhaus/money-ecb

Could it be a supplementary bank or have I done too much wrong?

Missing ISK conversion support

We have a use case where we need to convert ISK to another currency.

I checked the central bank rates that are downloaded by saving the rates locally "eu_bank.save_rates(cache)".

It turns out that the ISK currency is included in the xml, but not supported by the gem. Could you add this as a supported currency?

nil can't be coerced into Float

Hi there,

when trying to exchange:

 Money.add_rate("EUR", "USD", 0.123)
 Money.new(100, 'EUR').exchange_to("USD")

I get

 TypeError:
       nil can't be coerced into Float
        # .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/eu_central_bank-0.5.0/lib/eu_central_bank.rb:64:in `/'
        # .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/eu_central_bank-0.5.0/lib/eu_central_bank.rb:64:in `exchange_with'
        # .rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/money-6.5.1/lib/money/money.rb:412:in `exchange_to'

I already found the reason for this..
dirty fix: also add

 Money.add_rate("EUR", "EUR", 1)

but I would like to contribute a clean patch for this issue.
Question: how to fork the current version 0.5.0, because I can only clone version 0.4.0 here via github?

Thx!

No rates available for ARS

Money.new(5, "ARS").exchange_to('EUR').to_f

CurrencyUnavailable: No rates available for ARS

Is there any fix for this in future?

Converting currency to same currency throws error

Using eu_central_bank (0.3.7), money (6.0.1):

>> Money.new(100, 'USD').exchange_to('USD')
!! #<NoMethodError: undefined method `each_pair' for nil:NilClass>

Shouldn't this just behave like an identity function?

export_rates with :json and :yaml format issue

When exporting rates, using export_rates, with :json and :yaml formats, rates are exported in String format.

Then, reimporting rates, with import_rates causes an Exception (String to bigInt conversion)

Loosen dependency on money gem

Currently if you add money to Gemfile and install you'll get 6.10.1. If you then install eu_central_bank you'll get 0.3.8 (!) -- because this was the last one that had a loose dependency (>= 6.0.1). To get the latest eu_central_bank you need to downgrade money to 6.9.0.

I think eu_central_bank should be able to work with 6.x.x (cause breaking changes would surely require a change to 7.x.x). So the dependency on money in gemspec should be

  s.add_dependency "money", "~> 6.9"

I hope that sounds reasonable. I'll submit a PR if I can make it all work.

"NoMethodError: undefined method `/' for nil:NilClass" for certain currencies

Note: This error occurs with 145 of the 178 currencies available.

Money.new(100_00, 'GBP').exchange_to('BYR')
NoMethodError: undefined method /' for nil:NilClass from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/bundler/gems/eu_central_bank-d2cc9ac3c8f5/lib/eu_central_bank.rb:63:inexchange_with'
from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/money-6.7.0/lib/money/money.rb:434:in exchange_to' from (irb):294 from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/console.rb:110:instart'
from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/console.rb:9:in start' from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:68:inconsole'
from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands/commands_tasks.rb:39:in run_command!' from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/railties-4.2.1/lib/rails/commands.rb:17:in<top (required)>'
from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:in require' from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:inblock in require'
from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:in load_dependency' from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:274:inrequire'
from /home/peter/TipShield/workspace/tipshield/bin/rails:9:in <top (required)>' from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:inload'
from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in block in load' from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:240:inload_dependency'
from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/activesupport-4.2.1/lib/active_support/dependencies.rb:268:in load' from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/commands/rails.rb:6:incall'
from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/command_wrapper.rb:38:in call' from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/application.rb:185:inblock in serve'
from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/application.rb:156:in fork' from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/application.rb:156:inserve'
from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/application.rb:131:in block in run' from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/application.rb:125:inloop'
from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/application.rb:125:in run' from /home/peter/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/spring-1.6.4/lib/spring/application/boot.rb:18:in<top (required)>'
from /home/peter/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from /home/peter/.rbenv/versions/2.2.2/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from -e:1:in `

'irb(main):295:0>

undefined method `synchronize' for nil:NilClass

If I try to update_rates I get this error.

NoMethodError: undefined method `synchronize' for nil:NilClass
from /.rvm/gems/ruby-2.3.0/gems/eu_central_bank-0.3.8/lib/eu_central_bank.rb:69:in `update_parsed_rates`

Just me or broken master?

Rails 4.2.5
ruby 2.3.0p0

RUB is missing from exchange rates

As of today, we started to get errors about missing exchange rate for EUR-RUB (Russian Ruble).

> Money.default_bank.update_rates

=> #<EuCentralBank:0x00007fb8fa3c3d80 @store=#<Money::RatesStore::StoreWithHistoricalDataSupport:0x00007fb8fa3c3d58 @rates={"EUR_TO_USD"=>0.11076e1, "EUR_TO_JPY"=>0.12818e3, "EUR_TO_BGN"=>0.19558e1, "EUR_TO_CZK"=>0.25634e2, "EUR_TO_DKK"=>0.74399e1, "EUR_TO_GBP"=>0.82773e0, "EUR_TO_HUF"=>0.37864e3, "EUR_TO_PLN"=>0.47691e1, "EUR_TO_RON"=>0.49496e1, "EUR_TO_SEK"=>0.107688e2, "EUR_TO_CHF"=>0.10192e1, "EUR_TO_ISK"=>0.1434e3, "EUR_TO_NOK"=>0.98418e1, "EUR_TO_HRK"=>0.757e1, "EUR_TO_TRY"=>0.156897e2, "EUR_TO_AUD"=>0.15139e1, "EUR_TO_BRL"=>0.56041e1, "EUR_TO_CAD"=>0.13992e1, "EUR_TO_CNY"=>0.69996e1, "EUR_TO_HKD"=>0.86547e1, "EUR_TO_IDR"=>0.1593442e5, "EUR_TO_ILS"=>0.35872e1, "EUR_TO_INR"=>0.84174e2, "EUR_TO_KRW"=>0.13342e4, "EUR_TO_MXN"=>0.228945e2, "EUR_TO_MYR"=>0.4637e1, "EUR_TO_NZD"=>0.16329e1, "EUR_TO_PHP"=>0.57293e2, "EUR_TO_SGD"=>0.15042e1, "EUR_TO_THB"=>0.36063e2, "EUR_TO_ZAR"=>0.168798e2, "EUR_TO_EUR"=>1}, @options={}, @guard=#<Monitor:0x00007fb8fa3c3ce0 @mon_mutex=#<Thread::Mutex:0x00007fb8fa3c3c18>, @mon_mutex_owner_object_id=70216224480880, @mon_owner=nil, @mon_count=0>>, @rounding_method=nil, @currency_string=nil, @rates_updated_at=2022-03-03 00:00:00 +0200, @last_updated=2022-03-04 13:57:02 +0200>

ArgumentError: wrong number of arguments (given 3, expected 2)

We are getting the following error when trying to call .exchange_to:

#<ArgumentError: wrong number of arguments (given 3, expected 2)>
/Users/thibaut/.rvm/gems/ruby-2.7.4/gems/money-6.9.0/lib/money/rates_store/memory.rb:56:in `get_rate'
/Users/thibaut/.rvm/gems/ruby-2.7.4/gems/eu_central_bank-1.1.3/lib/eu_central_bank.rb:91:in `get_rate'
/Users/thibaut/.rvm/gems/ruby-2.7.4/gems/eu_central_bank-1.1.3/lib/eu_central_bank.rb:59:in `exchange_with'
/Users/thibaut/.rvm/gems/ruby-2.7.4/gems/money-6.9.0/lib/money/money.rb:436:in `exchange_to'

It seems like the instantiated store is the money RatesStore instead of the eu_central_bank StoreWithHistoricalDataSupport.

How can we fix that?

Function that checks if the currency is supported

Hi,
I was wondering if there is/could be a function that returns a boolean on whether or not a currency is supported by eu_central_bank. I know currently there is a function check_currency_available(currency) but that raises an exception if the currency rate doesn't exist. Can there be a function which returns false if the currency rate doesn't exist and true if it does.

def currency_available(currency)?
    currency_string = currency.to_s
    return true if currency_string == "EUR"
    return CURRENCIES.include?(currency_string)
end

rates_updated_at efficiency

Thanks for a beautiful peace of code!

I want to ask about how to optimize this condition:
"if [email protected]_updated_at || @bank.rates_updated_at < Time.now - 1.days"

Eu Central bank sets last rates on Friday, so all weekend it gives "true" value and makes new caches every time...

Tests failing and using 100% CPU

When I run the gem tests, three of them fail, then the suite just runs indefinitely using 100% cpu.

Tested on OSX Mavericks and Ruby 2.1.2.

License missing from gemspec

RubyGems.org doesn't report a license for your gem. This is because it is not specified in the gemspec of your last release.

via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

Including a license in your gemspec is an easy way for rubygems.org and other tools to check how your gem is licensed. As you can image, scanning your repository for a LICENSE file or parsing the README, and then attempting to identify the license or licenses is much more difficult and more error prone. So, even for projects that already specify a license, including a license in your gemspec is a good practice. See, for example, how rubygems.org uses the gemspec to display the rails gem license.

There is even a License Finder gem to help companies/individuals ensure all gems they use meet their licensing needs. This tool depends on license information being available in the gemspec. This is an important enough issue that even Bundler now generates gems with a default 'MIT' license.

I hope you'll consider specifying a license in your gemspec. If not, please just close the issue with a nice message. In either case, I'll follow up. Thanks for your time!

Appendix:

If you need help choosing a license (sorry, I haven't checked your readme or looked for a license file), GitHub has created a license picker tool. Code without a license specified defaults to 'All rights reserved'-- denying others all rights to use of the code.
Here's a list of the license names I've found and their frequencies

p.s. In case you're wondering how I found you and why I made this issue, it's because I'm collecting stats on gems (I was originally looking for download data) and decided to collect license metadata,too, and make issues for gemspecs not specifying a license as a public service :). See the previous link or my blog post about this project for more information.

TypeError: nil can't be coerced into Fixnum

I have following code:

bank = EuCentralBank.new
bank.add_rate(:EUR, :USD, 10)
Money.default_bank = bank
Money.new(100, :EUR).exchange_to(:USD)

And i get

TypeError: nil can't be coerced into Fixnum
from /Users/dmitrij/.rvm/gems/ruby-2.2.2@my_app/gems/eu_central_bank-0.5.0/lib/eu_central_bank.rb:57:in `/'

Apparently rate is set to nil, but:

bank.get_rate(:EUR, :USD)
=> 10
Money.default_bank.get_rate(:EUR, :USD)
=> 10

What could be the problem?

Thanks in advance.

Issue while converting from Indonesian currency to British Pound

I tried using eu central bank, its giving me error while converting currency from Indonesian rupee(IDR) to British pound(GBP).

subunit_to_unit = Money.new(1, "GBP").currency.subunit_to_unit
=> 100
Money.new(0*subunit_to_unit, 'IDR').exchange_to('GBP')
*** NoMethodError Exception: undefined method `/' for nil:NilClass

Thanks for help

`options` removed from Money 6.13.5

Seems that this gem isn't compatible with the latest money version (6.13.5)

NameError: undefined local variable or method `options' for #<Money::RatesStore::StoreWithHistoricalDataSupport:0x000055ad13572018>
Did you mean?  @options
/home/circleci/mrclean/vendor/bundle/ruby/2.6.0/gems/eu_central_bank-1.4.2/lib/money/rates_store/store_with_historical_data_support.rb:23:in `transaction'
/home/circleci/mrclean/vendor/bundle/ruby/2.6.0/gems/eu_central_bank-1.4.2/lib/eu_central_bank.rb:179:in `update_parsed_rates'
/home/circleci/mrclean/vendor/bundle/ruby/2.6.0/gems/eu_central_bank-1.4.2/lib/eu_central_bank.rb:29:in `update_rates'
/home/circleci/mrclean/app/better_now/accounting/ecb_bank.rb:25:in `update_rates'
/home/circleci/mrclean/app/better_now/accounting/ecb_bank.rb:20:in `initialize'
/home/circleci/mrclean/app/better_now/accounting/ecb_bank.rb:12:in `new'
/home/circleci/mrclean/app/better_now/accounting/ecb_bank.rb:12:in `setup'
/home/circleci/mrclean/config/initializers/money_exchange_bank.rb:4:in `<top (********)>'

This looks like the change that causes the problem: https://github.com/RubyMoney/money/pull/898/files#diff-70409fffc5690f30fb7495abab7a7dbfL103

update_rates fails to connect to server

We download eurofxref-daily.xml externally to our application and then make this call in our money initializer. The intent of this is to not have our server reaching out to fetch the exchange rate file as described in the README.

eu_bank = EuCentralBank.new
eu_bank.update_rates(File.join(Rails.root, "eurofxref-daily.xml"))

We have discovered an issue if the update_rates method is not able to read the cache file, it attempts to download it anyway. This behavior is subtle and not expected when updated_rates is advertised as simply loading a cache file.

See eu_central_bank.rb around line 168

  def doc(cache, url=ECB_RATES_URL)
    rates_source = !!cache ? cache : url
    Nokogiri::XML(open_url(rates_source)).tap { |doc| 
    doc.xpath('gesmes:Envelope/xmlns:Cube/xmlns:Cube//xmlns:Cube') }
  rescue Nokogiri::XML::XPath::SyntaxError
    Nokogiri::XML(open_url(url))
  end

The rescue path here should not attempt to make a network connection. Thank you for considering this change.

Thread-safe / concurrency?

I was just skimming through https://github.com/RubyMoney/eu_central_bank/blob/master/lib/eu_central_bank.rb and was wondering how update_parsed_rates would behave under the following circumstances:

  • One thread is trying to convert USD to INR while the other thread is simultaneously trying to update the rates using update_parsed_rates. The problem is that both the operations are not atomic in nature. USD to INR conversion will result in TWO fetches from the exchange-rate table: USD->EUR & EUR->INR. Similarly update_parsed_rates will make multiple calls to add_rate. Depending upon how the execution pans-out, one may end-up with a situation where the first call to get_rate (USD to EUR) gets the new exchange rate while the second call to get_rate (EUR to INR) gets the old exchange rate. Therefore the resultant blended exchange rate would be incorrect.
  • Similarly, say we're in the context of a multi-process Rail application, where there aren't threads running in parallel, but parallel processes. Say, a DelayedJob update_rates and caches them in a file using save_rates('tmp/cache/eu_bank_rates.xml'). Say, each Rails process is configured with EuCentralBank::ECB_RATES_URL='tmp/cache/eu_bank_rates.xml' and keeps calling update_rates very frequently (because the overhead of updating rates is very low). Here again we may end-up in a soup if the Rails process calls update_rates at the same time as DelayedJob calls save_rates. Both the operations are not atomic in nature and the Rails process may end-up reading a half-written file.

Any thoughts on the above?

Requires money 4.0.1, when will be working with money 5.0.0?

Hi, I am trying to use the latest versions of money, money-rails and eu_central_bank in my rails application, but it looks like that it is not possible, because of the dependencies of the eu_central_bank gem. I need the latest money-rails which requires money 5.0.0, so changing their versions is not an option for me. Is it possible to for the eu_central_bank gem to use the 5.0.0 version of money?

in my gemfile:

gem 'money', '> 5.0.0'
gem 'money-rails', '
> 0.2.0'
gem 'eu_central_bank', '~> 0.3.1'

bundle update produces:

Bundler could not find compatible versions for gem "money":
In Gemfile:
eu_central_bank (> 0.3.1) ruby depends on
money (
> 4.0.1) ruby

money (5.0.0)

Tests are failing

I believe it has something to do with the subunits. Every currency has different subunits but the rounding is done by 0.

@bank.exchange(100, "EUR", currency).cents.should == (@exchange_rates["currencies"][currency].to_f * 100).round

Problem getting exchange rates

Hey there,

I tried to get the exchange rate from foreign_value to other foreign_value (or euros), but I always get nil. Getting rates from EUR to foreign_value works well.
Example: (default_bank is EuCentralBank)

Money.default_bank.get_rate('GBP', 'EUR')
=> nil

Money.default_bank.get_rate('EUR', 'GBP')
=> #<BigDecimal:7fe19819b190,'0.86595E0',9(18)>

Money.default_bank.get_rate('GBP', 'USD')
=> nil

The actual exchange works very well.

Did I miss something?
How can I get the exchange rates here? I need them so save the value in a ExchangeEvent record in my current application.

Regards,
pabse

Calling `update_rates` without a cache file on a `puma` cluster pins CPU threads to 100%.

Prior to setting up a cache file to store the latest currency exchange rates and just have them updated on a daily basis, we were just doing update_rates on our money.rb initializer.

After the first request, all of the puma workers (that were called) became pinned at 100% CPU usage so this is what our development machine's htop looked like at idle after the first few requests:

image

I went down a rabbit hole with puma, thinking it must be the culprit, but it was actually just calling update_rates that caused this. Here is a comparison of what changes between this issue being present or not.

Issue Present

eu_central_bank = EuCentralBank.new

eu_central_bank.update_rates

config.default_bank = eu_central_bank

Issue NOT Present

eu_central_bank = EuCentralBank.new

eu_central_bank.update_rates( Rails.root.join( "rates.xml" ) )

config.default_bank = eu_central_bank

We've moved on by just using a cache file but I wanted to post this here because I searched and I didn't find any Issues documenting this.

Update gemspec to support latest nokogiri ?

Currently eu_central_bank is locked to >=1.8.0 and <1.9 is there any reason behind it ? Will it break if we update gemspec to latest or >=1.9 version ?

Ruby: 2.5.3
Rails 5.2.2

Using with alternative rate stores

Hello,
The money gem allows you to use custom stores(ActiveRecord, Redis etc) in place of the default memory store. The way EuCentralBankHistoricalDataSupport module is implemented in this gem seems to be tied to that memory store.
Do you have an idea how I can go about replacing it with a Redis store? I suspect, it's only possible by rewriting the mentioned module to handle it in a more abstract way, right? Thanks.

No explicit error when rate is not defined.

I work with CLP (Chilean Peso)

I was trying to use rails-money gem and I wanted to test the exchange system. The EUBank is configured as default bank.

Money.new(1000, "CLP").exchange_to("EUR")

Returns


TypeError: nil can't be coerced into Fixnum
from /.../gems/eu_central_bank-1.0.1/lib/eu_central_bank.rb:63:in `/'

There could be a check, so if the currency is not found a more specific error can be thrown, such as NonExistingCurrecyError or something.

EU Central Bank Gem redirection forbidden

Currently I am receiving an error message from eu central bank gem on rails as;

2018-09-06T18:26:20.629896+00:00 app[web.1]:   Error ID: 79f8e4f3
2018-09-06T18:26:20.629903+00:00 app[web.1]:   Error details saved to: /tmp/passenger-error.ZqeFNI
2018-09-06T18:26:20.629905+00:00 app[web.1]:   Message from application: redirection forbidden: http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml -> https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml (RuntimeError)
2018-09-06T18:26:20.629907+00:00 app[web.1]:   /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/open-uri.rb:224:in `open_loop'
2018-09-06T18:26:20.629908+00:00 app[web.1]:   /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/open-uri.rb:150:in `open_uri'
2018-09-06T18:26:20.629912+00:00 app[web.1]:   /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/open-uri.rb:716:in `open'
2018-09-06T18:26:20.629916+00:00 app[web.1]:   /app/vendor/ruby-2.2.4/lib/ruby/2.2.0/open-uri.rb:34:in `open'
2018-09-06T18:26:20.629919+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/eu_central_bank-0.5.0/lib/eu_central_bank.rb:87:in `doc'
2018-09-06T18:26:20.629941+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/eu_central_bank-0.5.0/lib/eu_central_bank.rb:20:in `update_rates'
2018-09-06T18:26:20.629976+00:00 app[web.1]:   /app/config/initializers/money.rb:5:in `<top (required)>'
2018-09-06T18:26:20.630007+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
2018-09-06T18:26:20.630038+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
2018-09-06T18:26:20.630069+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
2018-09-06T18:26:20.630099+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
2018-09-06T18:26:20.630128+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/engine.rb:652:in `block in load_config_initializer'
2018-09-06T18:26:20.630158+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/activesupport-4.2.0/lib/active_support/notifications.rb:166:in `instrument'
2018-09-06T18:26:20.630205+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/engine.rb:651:in `load_config_initializer'
2018-09-06T18:26:20.630344+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/engine.rb:616:in `block (2 levels) in <class:Engine>'
2018-09-06T18:26:20.630376+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/engine.rb:615:in `each'
2018-09-06T18:26:20.630409+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/engine.rb:615:in `block in <class:Engine>'
2018-09-06T18:26:20.630438+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `instance_exec'
2018-09-06T18:26:20.630467+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/initializable.rb:30:in `run'
2018-09-06T18:26:20.630497+00:00 app[web.1]:   /app/vendor/bundle/ruby/2.2.0/gems/railties-4.2.0/lib/rails/initializable.rb:55:in `block in run_initializers'

Can not change the link from http to https

exchange_to causing NoMethodError: Undefined Method '/' for nil:NilClass

When attempting to convert a Money object, I am getting the error:

Money.us_dollar(100).exchange_to("CAD")
NoMethodError: Undefined Method '/' for nil:NilClass

Money.new("1000", "USD").exchange_to("EUR")
NoMethodError: Undefined Method '/' for nil:NilClass

Any idea of the issue? It's making my app unable to do any calculations requiring currency exchange which is a big problem. Thanks.

Latvia switched to euros

On Jan 1st, Latvia joined the euro zone. ( https://www.ecb.europa.eu/press/pr/date/2014/html/pr140101.en.html )
The ECB's webservice doesn't sends rates for the latvian lat any more.
When trying to convert to this currency, I get an error:

2.0.0p247 :004 > eu_bank.exchange(100, "EUR", "LVL")
NoMethodError: undefined method `/' for nil:NilClass
    from /home/florent/.rvm/gems/ruby-2.0.0-p247@lce_api/gems/eu_central_bank-0.3.7/lib/eu_central_bank.rb:45:in `exchange_with'
    from /home/florent/.rvm/gems/ruby-2.0.0-p247@lce_api/gems/eu_central_bank-0.3.7/lib/eu_central_bank.rb:37:in `exchange'

The LVL currency should be removed.

Saving rates every day

What's the best approach if I need to save rates into a file every day and use it while evaluating prices created at that date? Should I just save them into something like exchange_rates/dd_mm_yyyy.xml and then load the rates from the correct file based on when price was created or is there a better option? Is there a way to keep them all in one file and just ask the gem to give the rate for a given date? Thanks!

Does not resolve with Money 6.10.1

When trying to upgrade the Money gem:

Bundler could not find compatible versions for gem "money":
  In Gemfile:
    money (~> 6.10.1)

    eu_central_bank was resolved to 1.1.3, which depends on
      money (~> 6.9.0)

Dependency on Nokogiri

Hi,

Thanks for eu_central_bank, I'm using it and it's very helpful.

I'm wondering about the dependency on Nokogiri ~> 1.4.1
If I'm using eu_central_bank, I can't use Nokogiri 1.5 which is the latest version.

If it is on purpose, I'll find a way around this.
If not, it'd be cool to specify a softer dependency, for example ~> 1.4

Thanks

Bug: self defined currency / exchange not working when loaded eu_central_bank

If you create a new rails app, add money & eu_central_bank gem, bundle install, start rails console you can see following behaviour:

Following works fine:

    Money::Currency::TABLE[:btc] = {
      :priority        => 1,
      :iso_code        => "BTC",
      :name            => "Bitcoin",
      :symbol          => "BTC",
      :subunit         => "Cent",
      :subunit_to_unit => 100000000,
      :separator       => ".",
      :delimiter       => ","
    }
    Money.add_rate("USD", "BTC", 1 / 13.7603) #  price set at -> 1 BTC = 13.7603
    "0.1 USD".to_money.exchange_to("BTC")
   => #<Money cents:726728 currency:BTC>

But if you load eu central bank before and add it as the default bank then the exchange becomes corrupted

    eu_bank = EuCentralBank.new
    eu_bank.update_rates
    Money.default_bank = eu_bank
    Money::Currency::TABLE[:btc] = {
      :priority        => 1,
      :iso_code        => "BTC",
      :name            => "Bitcoin",
      :symbol          => "BTC",
      :subunit         => "Cent",
      :subunit_to_unit => 100000000,
      :separator       => ".",
      :delimiter       => ","
    }
    Money.add_rate("USD", "BTC", 1 / 13.7603) #  price set at -> 1 BTC = 13.7603
    "0.1 USD".to_money.exchange_to("BTC")
   => #<Money cents:1 currency:BTC>

This doesn't work too if you try to load the custom currency data before loading the eu central bank gem...

Didn't found out exactly why this behaviour happens..

exchange for a specific date

Is not posible to exchange for a specific date?
I try:

require 'eu_central_bank'
eu_bank = EuCentralBank.new
Money.default_bank = eu_bank
money1 = Money.new(10)
money1.bank # eu_bank

eu_bank.update_rates

eu_bank.exchange(100, "CAD", "USD", Date.parse('2012-01-01')) # NoMethodError: undefined method `/' for nil:NilClass

I think that the problem is because the rates are not cache for a specific date, but is not posible to call update_rates with a date.

So, it is an error or the feature does not exists?

NoMethodError: undefined method `synchronize' for nil:NilClass

If I use the gem with version 0.4.0 with rails 4.2.3 and ruby 2.2.2 I get the following error:

irb> eu_bank = EuCentralBank.new
irb> eu_bank.update_rates
irb> NoMethodError: undefined method `synchronize' for nil:NilClass
        from /bundler/gems/eu_central_bank-6038f21813e8/lib/eu_central_bank.rb:98:in `update_parsed_rates'
        from /bundler/gems/eu_central_bank-6038f21813e8/lib/eu_central_bank.rb:19:in `update_rates'

The variable @mutex seams to be nil! Any idea?

Update to Money 6.13.1

Hello!

Could you update the gem dependency to Money 6.13.1?

I am not able to bundle or use previous version without this commit:
RubyMoney/money@391c93e

Bundler could not find compatible versions for gem "money":
  In snapshot (Gemfile.lock):
    money (= 6.13.1)

  In Gemfile:
    money (= 6.13.1)

    eu_central_bank was resolved to 1.3.1, which depends on
      money (~> 6.12.0)

an option to pass read_timeout for rates updates

Time taken by update_rates call depends on response time of the European Central Bank servers and it's only possible to interrupt using Timeout::timeout (which can cause bugs) if the call is stuck in case I'd like to use a fallback bank. That would be great if I could pass timeout option to this call so it will be used by the underlying open call

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.