README.md in money-open-exchange-rates-1.3.0 vs README.md in money-open-exchange-rates-1.4.0

- old
+ new

@@ -28,29 +28,35 @@ gem 'money-open-exchange-rates' ``` And then execute: -~~~ +``` bundle -~~~ +``` Or install it yourself as: -~~~ +``` gem install money-open-exchange-rates -~~~ +``` ## Usage ``` ruby require 'money/bank/open_exchange_rates_bank' # Memory store per default; for others just pass as argument a class like # explained in https://github.com/RubyMoney/money#exchange-rate-stores -oxr = Money::Bank::OpenExchangeRatesBank.new +oxr = Money::Bank::OpenExchangeRatesBank.new(Money::RatesStore::Memory.new) oxr.app_id = 'your app id from https://openexchangerates.org/signup' + +# Update the rates for the current rates storage +# If the storage is memory you will have to restart the server to be taken into +# account. +# If the storage is a database, file, this can be added to +# crontab/worker/scheduler `Money.default_bank.update_rates` oxr.update_rates # (optional) # See https://github.com/spk/money-open-exchange-rates#cache for more info # Updated only when `refresh_rates` is called @@ -95,18 +101,44 @@ oxr.refresh_rates # (optional) # Force refresh rates cache and store on the fly when ttl is expired # This will slow down request on get_rate, so use at your on risk, if you don't -# want to setup crontab/worker/scheduler for your application +# want to setup crontab/worker/scheduler for your application. +# Again this is not safe with multiple servers and could increase API usage. oxr.force_refresh_rate_on_expire = true Money.default_bank = oxr Money.default_bank.get_rate('USD', 'CAD') ``` +## Refresh rates + +### With [whenever](https://github.com/javan/whenever) + +``` ruby +every :hour do + runner "Money.default_bank.refresh_rates" + # you will have to restart the server if you are using memory rate store + runner "Money.default_bank.update_rates" +end +``` + +### With rake task + +``` ruby +namespace :open_exchange_rates do + desc "Refresh rates from cache and update rates" + task :refresh_rates => :environment do + Money.default_bank.refresh_rates + # you will have to restart the server if you are using memory rate store + Money.default_bank.update_rates + end +end +``` + ## Cache You can also provide a `Proc` as a cache to provide your own caching mechanism perhaps with Redis or just a thread safe `Hash` (global). For example: @@ -160,15 +192,19 @@ end end oxr.app_id = ENV['OXR_API_KEY'] oxr.show_alternative = true oxr.prettyprint = false + +# This can be removed if you have data to avoid http call on boot for production oxr.update_rates Money.default_bank = oxr ``` +See also how to [refresh and update rates](#refresh-rates) + ### Tests To avoid to hit the API we can use the cache option with a saved file like this: ``` ruby @@ -192,13 +228,13 @@ Unknown pair rates are transparently calculated: using inverse rate (if known), or using base currency rate to both currencies forming the pair. ## Tests -~~~ +``` bundle exec rake -~~~ +``` ## Refs * <https://github.com/josscrowcroft/open-exchange-rates> * <https://github.com/RubyMoney/money> @@ -211,14 +247,14 @@ ## License The MIT License -Copyright © 2011-2019 Laurent Arnoud <laurent@spkdev.net> +Copyright © 2011-2020 Laurent Arnoud <laurent@spkdev.net> --- -[![Build](https://img.shields.io/travis-ci/spk/money-open-exchange-rates.svg)](https://travis-ci.org/spk/money-open-exchange-rates) +[![Build](https://img.shields.io/gitlab/pipeline/spkdev/money-open-exchange-rates/master)](https://gitlab.com/spkdev/money-open-exchange-rates/-/commits/master) +[![Coverage](https://gitlab.com/spkdev/money-open-exchange-rates/badges/master/coverage.svg)](https://gitlab.com/spkdev/money-open-exchange-rates/-/commits/master) [![Version](https://img.shields.io/gem/v/money-open-exchange-rates.svg)](https://rubygems.org/gems/money-open-exchange-rates) [![Documentation](https://img.shields.io/badge/doc-rubydoc-blue.svg)](http://www.rubydoc.info/gems/money-open-exchange-rates) [![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT "MIT") -[![Coverage Status](https://img.shields.io/coveralls/github/spk/money-open-exchange-rates.svg)](https://coveralls.io/github/spk/money-open-exchange-rates?branch=master) [![Inline docs](https://inch-ci.org/github/spk/money-open-exchange-rates.svg?branch=master)](http://inch-ci.org/github/spk/money-open-exchange-rates)