money-open-exchange-rates 0.7.0 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2bb0f3d444f2239012893ebb5b147ea7ed833685
4
- data.tar.gz: 73c55f153751549bda537ea4450fbe1dcf13b955
2
+ SHA256:
3
+ metadata.gz: 86f324ed978cde7c5b05b50a8fe3d1ce4740333874457c8776c9871b3fa9ee31
4
+ data.tar.gz: ef5d0c06086d520f7a8816a69007b98d4741fb0063148ee0c66b9ec29a658b6d
5
5
  SHA512:
6
- metadata.gz: e84776814c80e1720bd0bac0014fd30b0bd58028c73d1dae3ab284ab374c25eca032c91ee6aab353e308358b977bd18776940c07908cfc871c577e180f692be6
7
- data.tar.gz: 8d6cac3341389cf16dd7431b2cd32a1b61d210afd9e650ccdfe6935500a8eba1bcd68de7922a468806ad5ba0a8234cac48fab7ff3034171d45a12d214c9f770d
6
+ metadata.gz: 5361f382ab1462ae3c6b1a18e543c1dbe4d8d31f68278c460092d8fd93b65a9fd9070f290915a498b1b9bb10b2c6c6c6fb3bff356a90f0f0b75b12d296914990
7
+ data.tar.gz: d85876e62c4f13ebe24c71a273cb6667e7a331707cd7f48e90393b1d620b51593ff03cc77bc24cac78075fd21983290d99cba5eb62bfdb3c2235d1b790669f8d
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
6
+
7
+ gem 'simplecov', require: false
data/History.md CHANGED
@@ -1,4 +1,127 @@
1
1
 
2
+ 1.4.2 / 2023-07-25
3
+ ==================
4
+
5
+ * gitlab: Ruby 3.2 in, 2.6 out
6
+ * Merge pull request #70 from @swiknaba / master
7
+ * CI: nicer name, latest versions of Github actions
8
+ * CI: Ruby 3.2 in, 2.6 out
9
+ * Bump year
10
+ * Update jruby version
11
+ * Update rubocop target ruby version
12
+ * Update Rubies on CIs
13
+ * Handle AppIdInactive error
14
+
15
+ 1.4.1 / 2023-05-07
16
+ ==================
17
+
18
+ * Merge pull request #69 from @fuentesjr / identify-access-restricted-errors
19
+ * Fixing typo in scoping of must_raise in access restricted test
20
+ * Raise a new AccessRestricted error when account is restricted by oer
21
+
22
+ 1.4.0 / 2020-09-11
23
+ ==================
24
+
25
+ * Fix jruby test for cross courses
26
+ * Fix deprecation global use of must_equal
27
+ * Merge pull request #66 from @korun / clear-cross-courses
28
+ * Update rates inside transaction, to prevent RC issues
29
+ * Merge pull request #65 from @korun / ensure-file-closed
30
+ * Fix unclosed file descriptor after read_from_cache
31
+ * Merge pull request #64 from @anton-smagin / clear-cross-courses
32
+ * Set old rates to nil on #update_rates before set new one to expire pair rates using base
33
+ * Add coverage stage on ci
34
+ * Remove Ruby 2.3 support
35
+ * Switch to gitlab ci
36
+ * Update README
37
+ * Fix rubocop to 0.76.0 and remove minitest-focus
38
+ * Update gitlab ci gem install does not have --no-ri anymore
39
+ * README add more doc about update_rates
40
+ * Fix deprecation for minitest 6
41
+ * Fix flaky test about Money::Bank::NoAppId
42
+ * Support Pathname for cache
43
+ * Update rubocop to 0.76
44
+ * Remove Ruby 2.2 support and update rubocop
45
+ * Update travis list
46
+ * README: improve refresh doc
47
+
48
+ 1.3.0 / 2019-01-20
49
+ ==================
50
+
51
+ * Update webmock to 3.5
52
+ * Update rubocop to 0.63
53
+ * Switch from rr to mocha/minitest
54
+ * Add prettyprint option
55
+ * README: add info about tests
56
+ * Remove deprecated secure_connection= option
57
+ * Merge pull request #54 from @LinkUpStudioUA / symbols-doc-link-fix
58
+ * Fix link to filtering by symbols doc
59
+ * Fix bundler to <2 on travis (dropped support Ruby < 2.3)
60
+ * Fix bundler to 1.17.3 (2.0 dropped support Ruby < 2.3)
61
+ * Merge pull request #52 from @thejchap / feature/symbols
62
+ * add support for symbols query param
63
+ * Remove ruby 2.0/2.1 support and fix rubocop offenses
64
+ * Add minitest-focus gem
65
+ * Avoid redefine json_response method
66
+
67
+ v1.2.2 / 2018-03-31
68
+ ===================
69
+
70
+ * Warn secure_connection= is deprecated
71
+ * More simple code on calc_pair_rate_using_base
72
+ * Increase code coverage on source_url
73
+ * Fix parse error specs on refresh_rates
74
+ * Use Coveralls for coverage
75
+ * Add tests for rates_timestamp issue
76
+
77
+ v1.2.1 / 2018-03-31
78
+ ===================
79
+
80
+ * Fix rates_timestamp should be now per default
81
+
82
+ v1.2.0 / 2018-03-31
83
+ ===================
84
+
85
+ * Merge pull request #51 from spk/fix-expire_rates
86
+ * Add force_refresh_rate_on_expire option and use api timestamp
87
+ * README: info currency-exchange
88
+
89
+ v1.1.1 / 2018-03-30
90
+ ===================
91
+
92
+ * Merge pull request #50 from @v-kolesnikov / fix/avoid-monetize
93
+ * Use `monetize` as a development dependency only
94
+
95
+ v1.1.0 / 2018-03-28
96
+ ===================
97
+
98
+ * Force refresh when ttl is expire and cache invalid (issue #47)
99
+ * Less strict dependency version for money/monetize
100
+
101
+ v1.0.2 / 2018-03-27
102
+ ===================
103
+
104
+ * Merge pull request #46 from @cedricpim / fix-float-big-decimal-casting
105
+ * Fix issue with Float casting for BigDecimal
106
+
107
+ v1.0.1 / 2018-03-25
108
+ ===================
109
+
110
+ * Use BigDecimal instead of Float
111
+
112
+ v1.0.0 / 2018-03-25
113
+ ===================
114
+
115
+ * Merge pull request #41 from @b-mandelbrot /add-show-alternative
116
+ * Add support for black market and digital currency rates
117
+ * Merge pull request #42 from spk/save-rates-when-ttl-expire
118
+ * Save rates to cache after first fetch and add example with Rails
119
+ * Improve documation about cache and rates ttl
120
+ * Save rates when ttl expire
121
+ * Merge pull request #40 from @Jetbuilt / deprecate-secure_connection
122
+ * Closes #39 - Make all requests over https and deprecate `secure_connection`
123
+ * Support Ruby >= 2.0
124
+
2
125
  v0.7.0 / 2016-10-23
3
126
  ===================
4
127
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2011-2016 Laurent Arnoud <laurent@spkdev.net>
3
+ Copyright (c) 2011-2023 Laurent Arnoud <laurent@spkdev.net>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # Money Open Exchange Rates
2
2
 
3
3
  A gem that calculates the exchange rate using published rates from
4
- [open-exchange-rates](https://openexchangerates.org/)
4
+ [open-exchange-rates](https://openexchangerates.org/). Compatible with
5
+ [Money](https://github.com/RubyMoney/money#currency-exchange) [currency
6
+ exchange](http://www.rubydoc.info/gems/money/Money/Bank/VariableExchange).
5
7
 
6
8
  Check [api documentation](https://docs.openexchangerates.org/)
7
9
 
@@ -11,69 +13,136 @@ Check [api documentation](https://docs.openexchangerates.org/)
11
13
  [180 currencies](https://docs.openexchangerates.org/docs/supported-currencies).
12
14
  * [Free plan](https://openexchangerates.org/signup) hourly updates, with USD
13
15
  base and up to 1,000 requests/month.
14
- * Currency caching.
16
+ * Automatically caches API results to file or Rails cache.
15
17
  * Calculate pair rates.
18
+ * Automatically fetches new data from API if data becomes stale when
19
+ `ttl_in_seconds` option is provided.
20
+ * Support for black market and digital currency rates with `show_alternative`
21
+ option.
16
22
 
17
23
  ## Installation
18
24
 
19
25
  Add this line to your application's Gemfile:
20
26
 
21
- ~~~ ruby
27
+ ``` ruby
22
28
  gem 'money-open-exchange-rates'
23
- ~~~
29
+ ```
24
30
 
25
31
  And then execute:
26
32
 
27
- ~~~
33
+ ```
28
34
  bundle
29
- ~~~
35
+ ```
30
36
 
31
37
  Or install it yourself as:
32
38
 
33
- ~~~
39
+ ```
34
40
  gem install money-open-exchange-rates
35
- ~~~
41
+ ```
36
42
 
37
43
  ## Usage
38
44
 
39
- ~~~ ruby
45
+ ``` ruby
40
46
  require 'money/bank/open_exchange_rates_bank'
41
- oxr = Money::Bank::OpenExchangeRatesBank.new
42
- oxr.cache = 'path/to/file/cache.json'
47
+
48
+ # Memory store per default; for others just pass as argument a class like
49
+ # explained in https://github.com/RubyMoney/money#exchange-rate-stores
50
+ oxr = Money::Bank::OpenExchangeRatesBank.new(Money::RatesStore::Memory.new)
43
51
  oxr.app_id = 'your app id from https://openexchangerates.org/signup'
52
+
53
+ # Update the rates for the current rates storage
54
+ # If the storage is memory you will have to restart the server to be taken into
55
+ # account.
56
+ # If the storage is a database, file, this can be added to
57
+ # crontab/worker/scheduler `Money.default_bank.update_rates`
44
58
  oxr.update_rates
45
59
 
46
60
  # (optional)
47
- # set the seconds after than the current rates are automatically expired
61
+ # See https://github.com/spk/money-open-exchange-rates#cache for more info
62
+ # Updated only when `refresh_rates` is called
63
+ oxr.cache = 'path/to/file/cache.json'
64
+
65
+ # (optional)
66
+ # Set the seconds after than the current rates are automatically expired
48
67
  # by default, they never expire, in this example 1 day.
68
+ # This ttl is about money store (memory, database ...) passed though
69
+ # `Money::Bank::OpenExchangeRatesBank` as argument not about `cache` option.
70
+ # The base time is the timestamp fetched from API.
49
71
  oxr.ttl_in_seconds = 86400
72
+
50
73
  # (optional)
51
- # use https to fetch rates from Open Exchange Rates
52
- # disabled by default to support free-tier users
53
- # see https://openexchangerates.org/documentation#https
54
- oxr.secure_connection = true
55
- # (optional)
56
- # set historical date of the rate
74
+ # Set historical date of the rate
57
75
  # see https://openexchangerates.org/documentation#historical-data
58
76
  oxr.date = '2015-01-01'
77
+
59
78
  # (optional)
60
79
  # Set the base currency for all rates. By default, USD is used.
61
80
  # OpenExchangeRates only allows USD as base currency
62
81
  # for the free plan users.
63
82
  oxr.source = 'USD'
64
83
 
65
- # Store in cache
66
- oxr.save_rates
84
+ # (optional)
85
+ # Extend returned values with alternative, black market and digital currency
86
+ # rates. By default, false is used
87
+ # see: https://docs.openexchangerates.org/docs/alternative-currencies
88
+ oxr.show_alternative = true
89
+
90
+ # (optional)
91
+ # Minified Response ('prettyprint')
92
+ # see https://docs.openexchangerates.org/docs/prettyprint
93
+ oxr.prettyprint = false
94
+
95
+ # (optional)
96
+ # Refresh rates, store in cache and update rates
97
+ # Should be used on crontab/worker/scheduler `Money.default_bank.refresh_rates`
98
+ # If you are using unicorn-worker-killer gem or on Heroku like platform,
99
+ # you should avoid to put this on the initializer of your Rails application,
100
+ # because will increase your OXR API usage.
101
+ oxr.refresh_rates
102
+
103
+ # (optional)
104
+ # Force refresh rates cache and store on the fly when ttl is expired
105
+ # This will slow down request on get_rate, so use at your on risk, if you don't
106
+ # want to setup crontab/worker/scheduler for your application.
107
+ # Again this is not safe with multiple servers and could increase API usage.
108
+ oxr.force_refresh_rate_on_expire = true
67
109
 
68
110
  Money.default_bank = oxr
69
111
 
70
112
  Money.default_bank.get_rate('USD', 'CAD')
71
- ~~~
113
+ ```
114
+
115
+ ## Refresh rates
116
+
117
+ ### With [whenever](https://github.com/javan/whenever)
118
+
119
+ ``` ruby
120
+ every :hour do
121
+ runner "Money.default_bank.refresh_rates"
122
+ # you will have to restart the server if you are using memory rate store
123
+ runner "Money.default_bank.update_rates"
124
+ end
125
+ ```
72
126
 
73
- You can also provide a Proc as a cache to provide your own caching mechanism
127
+ ### With rake task
128
+
129
+ ``` ruby
130
+ namespace :open_exchange_rates do
131
+ desc "Refresh rates from cache and update rates"
132
+ task :refresh_rates => :environment do
133
+ Money.default_bank.refresh_rates
134
+ # you will have to restart the server if you are using memory rate store
135
+ Money.default_bank.update_rates
136
+ end
137
+ end
138
+ ```
139
+
140
+ ## Cache
141
+
142
+ You can also provide a `Proc` as a cache to provide your own caching mechanism
74
143
  perhaps with Redis or just a thread safe `Hash` (global). For example:
75
144
 
76
- ~~~ ruby
145
+ ``` ruby
77
146
  oxr.cache = Proc.new do |v|
78
147
  key = 'money:exchange_rates'
79
148
  if v
@@ -82,16 +151,88 @@ oxr.cache = Proc.new do |v|
82
151
  Thread.current[key]
83
152
  end
84
153
  end
85
- ~~~
154
+ ```
155
+
156
+ With `Rails` cache example:
157
+
158
+ ``` ruby
159
+ OXR_CACHE_KEY = "#{Rails.env}:money:exchange_rates".freeze
160
+ oxr.ttl_in_seconds = 86400
161
+ oxr.cache = Proc.new do |text|
162
+ if text
163
+ Rails.cache.write(OXR_CACHE_KEY, text)
164
+ else
165
+ Rails.cache.read(OXR_CACHE_KEY)
166
+ end
167
+ end
168
+ ```
169
+
170
+ To update the cache call `Money.default_bank.refresh_rates` on
171
+ crontab/worker/scheduler. This have to be done this way because the fetch can
172
+ take some time (HTTP call) and can fail.
173
+
174
+ ## Full example configuration initializer with Rails and cache
175
+
176
+ ``` ruby
177
+ require 'money/bank/open_exchange_rates_bank'
178
+
179
+ OXR_CACHE_KEY = "#{Rails.env}:money:exchange_rates".freeze
180
+ # ExchangeRate is an ActiveRecord model
181
+ # more info at https://github.com/RubyMoney/money#exchange-rate-stores
182
+ oxr = Money::Bank::OpenExchangeRatesBank.new(ExchangeRate)
183
+ oxr.ttl_in_seconds = 86400
184
+ oxr.cache = Proc.new do |text|
185
+ if text
186
+ # only expire when refresh_rates is called or `force_refresh_rate_on_expire`
187
+ # option is enabled
188
+ # you can also set `expires_in` option on write to force fetch new rates
189
+ Rails.cache.write(OXR_CACHE_KEY, text)
190
+ else
191
+ Rails.cache.read(OXR_CACHE_KEY)
192
+ end
193
+ end
194
+ oxr.app_id = ENV['OXR_API_KEY']
195
+ oxr.show_alternative = true
196
+ oxr.prettyprint = false
197
+
198
+ # This can be removed if you have data to avoid http call on boot for production
199
+ oxr.update_rates
200
+
201
+ Money.default_bank = oxr
202
+ ```
203
+
204
+ See also how to [refresh and update rates](#refresh-rates)
205
+
206
+ ### Tests
207
+
208
+ To avoid to hit the API we can use the cache option with a saved file like this:
209
+
210
+ ``` ruby
211
+ OXR_CACHE_KEY = "#{Rails.env}:money:exchange_rates".freeze
212
+ if Rails.env.test?
213
+ oxr.cache = Rails.root.join("test/fixtures/currency-rates.json").to_s
214
+ else
215
+ oxr.ttl_in_seconds = 5.minutes.to_i
216
+ oxr.cache = Proc.new do |text|
217
+ if text
218
+ Rails.cache.write(OXR_CACHE_KEY, text)
219
+ else
220
+ Rails.cache.read(OXR_CACHE_KEY)
221
+ end
222
+ end
223
+ end
224
+ ```
225
+
226
+ ## Pair rates
86
227
 
87
228
  Unknown pair rates are transparently calculated: using inverse rate (if known),
88
229
  or using base currency rate to both currencies forming the pair.
89
230
 
90
231
  ## Tests
91
232
 
92
- ~~~
233
+ ```
93
234
  bundle exec rake
94
- ~~~
235
+ ```
95
236
 
96
237
  ## Refs
97
238
 
@@ -108,12 +249,12 @@ See [GitHub](https://github.com/spk/money-open-exchange-rates/graphs/contributor
108
249
 
109
250
  The MIT License
110
251
 
111
- Copyright © 2011-2016 Laurent Arnoud <laurent@spkdev.net>
252
+ Copyright © 2011-2023 Laurent Arnoud <laurent@spkdev.net>
112
253
 
113
254
  ---
114
- [![Build](https://img.shields.io/travis-ci/spk/money-open-exchange-rates.svg)](https://travis-ci.org/spk/money-open-exchange-rates)
255
+ [![Build](https://img.shields.io/gitlab/pipeline/spkdev/money-open-exchange-rates/master)](https://gitlab.com/spkdev/money-open-exchange-rates/-/commits/master)
256
+ [![Coverage](https://gitlab.com/spkdev/money-open-exchange-rates/badges/master/coverage.svg)](https://gitlab.com/spkdev/money-open-exchange-rates/-/commits/master)
115
257
  [![Version](https://img.shields.io/gem/v/money-open-exchange-rates.svg)](https://rubygems.org/gems/money-open-exchange-rates)
116
258
  [![Documentation](https://img.shields.io/badge/doc-rubydoc-blue.svg)](http://www.rubydoc.info/gems/money-open-exchange-rates)
117
259
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT "MIT")
118
- [![Code Climate](https://img.shields.io/codeclimate/github/spk/money-open-exchange-rates.svg)](https://codeclimate.com/github/spk/money-open-exchange-rates)
119
260
  [![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)