money-open-exchange-rates 1.4.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +23 -0
- data/LICENSE +1 -1
- data/README.md +7 -1
- data/lib/money/bank/open_exchange_rates_bank.rb +15 -10
- data/lib/open_exchange_rates_bank/version.rb +1 -1
- data/test/data/app_id_inactive.json +1 -0
- data/test/integration/Gemfile +3 -1
- data/test/integration/Gemfile.lock +11 -13
- data/test/integration/api.rb +5 -4
- data/test/open_exchange_rates_bank_test.rb +19 -11
- data/test/test_helper.rb +4 -0
- metadata +30 -24
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7a04f2f4222945d437a7c84bfed72c8fbc36188644d00da13528a677eda9515a
|
|
4
|
+
data.tar.gz: eb7c523fb8d74a9573ea65f8779fa5a41748b477dbc6f7ca9ceef5cde50de59a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 508710569f6c2ca135fc5f09047ab20137b5c6ed6e93496c4b02925bdcc85e6f6fbb0a31b7d959534e82649f1302e50a0f6a7e4c06106c8bfc41cc170ee9b1ae
|
|
7
|
+
data.tar.gz: f2dc857c17c69a5c4faec4bd432bdd3ff89091a24642715c56a0f1f99525118e3199653f1729d33227938ad6d3c943914405b893674be2258650cb65632371bb
|
data/History.md
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
|
|
2
|
+
2.0.0 / 2025-12-23
|
|
3
|
+
==================
|
|
4
|
+
|
|
5
|
+
* BREAKING: Upgrade to money ~> 7.0
|
|
6
|
+
* BREAKING: Require Ruby >= 3.1
|
|
7
|
+
* Update monetize dependency to ~> 2.0
|
|
8
|
+
* Update CI to test Ruby 3.1, 3.2, 3.3, 3.4
|
|
9
|
+
* Remove support for Ruby 2.7, 3.0
|
|
10
|
+
* Update README with money 7.x default currency configuration
|
|
11
|
+
|
|
12
|
+
1.4.2 / 2023-07-25
|
|
13
|
+
==================
|
|
14
|
+
|
|
15
|
+
* gitlab: Ruby 3.2 in, 2.6 out
|
|
16
|
+
* Merge pull request #70 from @swiknaba / master
|
|
17
|
+
* CI: nicer name, latest versions of Github actions
|
|
18
|
+
* CI: Ruby 3.2 in, 2.6 out
|
|
19
|
+
* Bump year
|
|
20
|
+
* Update jruby version
|
|
21
|
+
* Update rubocop target ruby version
|
|
22
|
+
* Update Rubies on CIs
|
|
23
|
+
* Handle AppIdInactive error
|
|
24
|
+
|
|
2
25
|
1.4.1 / 2023-05-07
|
|
3
26
|
==================
|
|
4
27
|
|
data/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2011-
|
|
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
|
@@ -45,6 +45,9 @@ gem install money-open-exchange-rates
|
|
|
45
45
|
``` ruby
|
|
46
46
|
require 'money/bank/open_exchange_rates_bank'
|
|
47
47
|
|
|
48
|
+
# Money 7.x requires explicit default currency configuration
|
|
49
|
+
Money.default_currency = Money::Currency.new('USD')
|
|
50
|
+
|
|
48
51
|
# Memory store per default; for others just pass as argument a class like
|
|
49
52
|
# explained in https://github.com/RubyMoney/money#exchange-rate-stores
|
|
50
53
|
oxr = Money::Bank::OpenExchangeRatesBank.new(Money::RatesStore::Memory.new)
|
|
@@ -176,6 +179,9 @@ take some time (HTTP call) and can fail.
|
|
|
176
179
|
``` ruby
|
|
177
180
|
require 'money/bank/open_exchange_rates_bank'
|
|
178
181
|
|
|
182
|
+
# Money 7.x requires explicit default currency configuration
|
|
183
|
+
Money.default_currency = Money::Currency.new('USD')
|
|
184
|
+
|
|
179
185
|
OXR_CACHE_KEY = "#{Rails.env}:money:exchange_rates".freeze
|
|
180
186
|
# ExchangeRate is an ActiveRecord model
|
|
181
187
|
# more info at https://github.com/RubyMoney/money#exchange-rate-stores
|
|
@@ -249,7 +255,7 @@ See [GitHub](https://github.com/spk/money-open-exchange-rates/graphs/contributor
|
|
|
249
255
|
|
|
250
256
|
The MIT License
|
|
251
257
|
|
|
252
|
-
Copyright © 2011-
|
|
258
|
+
Copyright © 2011-2023 Laurent Arnoud <laurent@spkdev.net>
|
|
253
259
|
|
|
254
260
|
---
|
|
255
261
|
[](https://gitlab.com/spkdev/money-open-exchange-rates/-/commits/master)
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'money'
|
|
3
5
|
require 'net/http'
|
|
6
|
+
require 'time'
|
|
4
7
|
require 'uri'
|
|
5
|
-
require 'money'
|
|
6
|
-
require 'json'
|
|
7
8
|
require File.expand_path('../../open_exchange_rates_bank/version', __dir__)
|
|
8
9
|
|
|
9
10
|
# Money gem class
|
|
@@ -20,6 +21,14 @@ class Money
|
|
|
20
21
|
# Access restricted (e.g. usage/request limit exceeded for account)
|
|
21
22
|
class AccessRestricted < StandardError; end
|
|
22
23
|
|
|
24
|
+
# app_id_inactive
|
|
25
|
+
class AppIdInactive < StandardError; end
|
|
26
|
+
|
|
27
|
+
ERROR_MAP = {
|
|
28
|
+
access_restricted: AccessRestricted,
|
|
29
|
+
app_id_inactive: AppIdInactive
|
|
30
|
+
}.freeze
|
|
31
|
+
|
|
23
32
|
# OpenExchangeRatesBank base class
|
|
24
33
|
class OpenExchangeRatesBank < Money::Bank::VariableExchange
|
|
25
34
|
VERSION = ::OpenExchangeRatesBank::VERSION
|
|
@@ -261,7 +270,7 @@ class Money
|
|
|
261
270
|
str = "#{str}&base=#{source}" unless source == OE_SOURCE
|
|
262
271
|
str = "#{str}&show_alternative=#{show_alternative}"
|
|
263
272
|
str = "#{str}&prettyprint=#{prettyprint}"
|
|
264
|
-
str = "#{str}&symbols=#{symbols.join(',')}" if symbols
|
|
273
|
+
str = "#{str}&symbols=#{symbols.join(',')}" if symbols.is_a?(Array)
|
|
265
274
|
str
|
|
266
275
|
end
|
|
267
276
|
|
|
@@ -315,9 +324,7 @@ class Money
|
|
|
315
324
|
if cache.is_a?(Proc)
|
|
316
325
|
cache.call(text)
|
|
317
326
|
elsif cache.is_a?(String) || cache.is_a?(Pathname)
|
|
318
|
-
File.
|
|
319
|
-
f.write(text)
|
|
320
|
-
end
|
|
327
|
+
File.write(cache.to_s, text)
|
|
321
328
|
else
|
|
322
329
|
raise InvalidCache
|
|
323
330
|
end
|
|
@@ -364,7 +371,7 @@ class Money
|
|
|
364
371
|
return false unless text
|
|
365
372
|
|
|
366
373
|
parsed = JSON.parse(text)
|
|
367
|
-
parsed&.key?(RATES_KEY) && parsed
|
|
374
|
+
parsed&.key?(RATES_KEY) && parsed.key?(TIMESTAMP_KEY)
|
|
368
375
|
rescue JSON::ParserError
|
|
369
376
|
false
|
|
370
377
|
end
|
|
@@ -374,9 +381,7 @@ class Money
|
|
|
374
381
|
# @return [Hash] key is country code (ISO 3166-1 alpha-3) value Float
|
|
375
382
|
def exchange_rates
|
|
376
383
|
doc = JSON.parse(read_from_cache || read_from_url)
|
|
377
|
-
if doc['error'] && doc['message']
|
|
378
|
-
raise AccessRestricted
|
|
379
|
-
end
|
|
384
|
+
raise ERROR_MAP[doc['message'].to_sym] if doc['error'] && ERROR_MAP.key?(doc['message'].to_sym)
|
|
380
385
|
|
|
381
386
|
self.rates_timestamp = doc[TIMESTAMP_KEY]
|
|
382
387
|
@oer_rates = doc[RATES_KEY]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"error": true, "status": 401, "message": "app_id_inactive", "description": "This App ID has been deactivated. Please use another or contact support@openexchangerates.org for assistance."}
|
data/test/integration/Gemfile
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
PATH
|
|
2
|
-
remote:
|
|
2
|
+
remote: ../..
|
|
3
3
|
specs:
|
|
4
|
-
money-open-exchange-rates (
|
|
5
|
-
|
|
6
|
-
money (~> 6.7)
|
|
4
|
+
money-open-exchange-rates (1.4.1)
|
|
5
|
+
money (~> 6.12)
|
|
7
6
|
|
|
8
7
|
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
9
|
specs:
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
money (6.
|
|
14
|
-
i18n (>= 0.6.4, <=
|
|
15
|
-
sixarm_ruby_unaccent (>= 1.1.1, < 2)
|
|
16
|
-
sixarm_ruby_unaccent (1.1.1)
|
|
10
|
+
concurrent-ruby (1.2.2)
|
|
11
|
+
i18n (1.13.0)
|
|
12
|
+
concurrent-ruby (~> 1.0)
|
|
13
|
+
money (6.16.0)
|
|
14
|
+
i18n (>= 0.6.4, <= 2)
|
|
17
15
|
|
|
18
16
|
PLATFORMS
|
|
19
|
-
|
|
17
|
+
x86_64-linux
|
|
20
18
|
|
|
21
19
|
DEPENDENCIES
|
|
22
20
|
money (~> 6.7)
|
|
23
21
|
money-open-exchange-rates!
|
|
24
22
|
|
|
25
23
|
BUNDLED WITH
|
|
26
|
-
|
|
24
|
+
2.4.12
|
data/test/integration/api.rb
CHANGED
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
require 'json'
|
|
4
4
|
require 'money/bank/open_exchange_rates_bank'
|
|
5
5
|
|
|
6
|
+
# Money 7.x requires explicit default currency configuration
|
|
7
|
+
Money.default_currency = Money::Currency.new('USD')
|
|
8
|
+
|
|
6
9
|
ERROR_MSG = 'Integration test failed!'
|
|
7
10
|
cache_path = '/tmp/latest.json'
|
|
8
11
|
to_currency = 'CAD'
|
|
9
|
-
app_id = ENV
|
|
12
|
+
app_id = ENV.fetch('OXR_APP_ID', nil)
|
|
10
13
|
|
|
11
14
|
if app_id.nil? || app_id.empty?
|
|
12
15
|
puts 'OXR_APP_ID env var not set skipping integration tests'
|
|
@@ -29,10 +32,8 @@ begin
|
|
|
29
32
|
json_to_currency = JSON.parse(File.read(cache_path))['rates'][to_currency]
|
|
30
33
|
puts 'JSON to_currency', json_to_currency
|
|
31
34
|
puts 'Money to_currency', cad_rate
|
|
32
|
-
# rubocop:disable Style/AndOr
|
|
33
35
|
json_to_currency == cad_rate or raise ERROR_MSG
|
|
34
|
-
|
|
35
|
-
# rubocop:disable Style/RescueStandardError
|
|
36
|
+
# rubocop:disable Style/RescueStandardError
|
|
36
37
|
rescue
|
|
37
38
|
# rubocop:enable Style/RescueStandardError
|
|
38
39
|
raise ERROR_MSG
|
|
@@ -28,6 +28,9 @@ describe Money::Bank::OpenExchangeRatesBank do
|
|
|
28
28
|
let(:oer_access_restricted_error_path) do
|
|
29
29
|
data_file('access_restricted_error.json')
|
|
30
30
|
end
|
|
31
|
+
let(:oer_app_id_inactive_error_path) do
|
|
32
|
+
data_file('app_id_inactive.json')
|
|
33
|
+
end
|
|
31
34
|
|
|
32
35
|
describe 'exchange' do
|
|
33
36
|
before do
|
|
@@ -106,8 +109,15 @@ describe Money::Bank::OpenExchangeRatesBank do
|
|
|
106
109
|
_(proc { subject.update_rates }).must_raise Money::Bank::AccessRestricted
|
|
107
110
|
end
|
|
108
111
|
|
|
112
|
+
it 'should raise AppIdInactive error when restricted by oer' do
|
|
113
|
+
subject.cache = nil
|
|
114
|
+
filepath = oer_app_id_inactive_error_path
|
|
115
|
+
subject.stubs(:api_response).returns File.read(filepath)
|
|
116
|
+
_(proc { subject.update_rates }).must_raise Money::Bank::AppIdInactive
|
|
117
|
+
end
|
|
118
|
+
|
|
109
119
|
it 'should update itself with exchange rates from OpenExchangeRates' do
|
|
110
|
-
subject.oer_rates.
|
|
120
|
+
subject.oer_rates.each_key do |currency|
|
|
111
121
|
next unless Money::Currency.find(currency)
|
|
112
122
|
|
|
113
123
|
_(subject.get_rate('USD', currency)).must_be :>, 0
|
|
@@ -295,34 +305,32 @@ describe Money::Bank::OpenExchangeRatesBank do
|
|
|
295
305
|
end
|
|
296
306
|
|
|
297
307
|
it 'should allow update after save' do
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
assert false, 'Should allow updating after saving'
|
|
304
|
-
end
|
|
308
|
+
subject.refresh_rates
|
|
309
|
+
# rubocop:disable Style/RescueStandardError
|
|
310
|
+
rescue
|
|
311
|
+
# rubocop:enable Style/RescueStandardError
|
|
312
|
+
assert false, 'Should allow updating after saving'
|
|
305
313
|
end
|
|
306
314
|
|
|
307
315
|
it 'should not break an existing file if save fails to read' do
|
|
308
316
|
initial_size = File.read(temp_cache_path).size
|
|
309
317
|
subject.stubs(:api_response).returns ''
|
|
310
318
|
subject.refresh_rates
|
|
311
|
-
_(File.
|
|
319
|
+
_(File.read(temp_cache_path).size).must_equal initial_size
|
|
312
320
|
end
|
|
313
321
|
|
|
314
322
|
it 'should not break an existing file if save returns json without rates' do
|
|
315
323
|
initial_size = File.read(temp_cache_path).size
|
|
316
324
|
subject.stubs(:api_response).returns '{"error": "An error"}'
|
|
317
325
|
subject.refresh_rates
|
|
318
|
-
_(File.
|
|
326
|
+
_(File.read(temp_cache_path).size).must_equal initial_size
|
|
319
327
|
end
|
|
320
328
|
|
|
321
329
|
it 'should not break an existing file if save returns a invalid json' do
|
|
322
330
|
initial_size = File.read(temp_cache_path).size
|
|
323
331
|
subject.stubs(:api_response).returns '{invalid_json: "An error"}'
|
|
324
332
|
subject.refresh_rates
|
|
325
|
-
_(File.
|
|
333
|
+
_(File.read(temp_cache_path).size).must_equal initial_size
|
|
326
334
|
end
|
|
327
335
|
end
|
|
328
336
|
|
data/test/test_helper.rb
CHANGED
|
@@ -7,6 +7,7 @@ rescue LoadError
|
|
|
7
7
|
warn 'simplecov not loaded'
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
require 'minitest/unit'
|
|
10
11
|
require 'minitest/autorun'
|
|
11
12
|
require 'mocha/minitest'
|
|
12
13
|
require 'webmock/minitest'
|
|
@@ -14,6 +15,9 @@ require 'money/bank/open_exchange_rates_bank'
|
|
|
14
15
|
require 'monetize'
|
|
15
16
|
require 'timecop'
|
|
16
17
|
|
|
18
|
+
# Money 7.x requires explicit default currency configuration
|
|
19
|
+
Money.default_currency = Money::Currency.new('USD')
|
|
20
|
+
|
|
17
21
|
TEST_APP_ID = 'TEST_APP_ID'
|
|
18
22
|
|
|
19
23
|
def data_file(file)
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: money-open-exchange-rates
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Laurent Arnoud
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: money
|
|
@@ -16,14 +15,28 @@ dependencies:
|
|
|
16
15
|
requirements:
|
|
17
16
|
- - "~>"
|
|
18
17
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
18
|
+
version: '7.0'
|
|
20
19
|
type: :runtime
|
|
21
20
|
prerelease: false
|
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
22
|
requirements:
|
|
24
23
|
- - "~>"
|
|
25
24
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
25
|
+
version: '7.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: ostruct
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0.6'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0.6'
|
|
27
40
|
- !ruby/object:Gem::Dependency
|
|
28
41
|
name: minitest
|
|
29
42
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -56,22 +69,16 @@ dependencies:
|
|
|
56
69
|
name: monetize
|
|
57
70
|
requirement: !ruby/object:Gem::Requirement
|
|
58
71
|
requirements:
|
|
59
|
-
- - "
|
|
60
|
-
- !ruby/object:Gem::Version
|
|
61
|
-
version: 1.3.1
|
|
62
|
-
- - "<"
|
|
72
|
+
- - "~>"
|
|
63
73
|
- !ruby/object:Gem::Version
|
|
64
|
-
version: '2'
|
|
74
|
+
version: '2.0'
|
|
65
75
|
type: :development
|
|
66
76
|
prerelease: false
|
|
67
77
|
version_requirements: !ruby/object:Gem::Requirement
|
|
68
78
|
requirements:
|
|
69
|
-
- - "
|
|
70
|
-
- !ruby/object:Gem::Version
|
|
71
|
-
version: 1.3.1
|
|
72
|
-
- - "<"
|
|
79
|
+
- - "~>"
|
|
73
80
|
- !ruby/object:Gem::Version
|
|
74
|
-
version: '2'
|
|
81
|
+
version: '2.0'
|
|
75
82
|
- !ruby/object:Gem::Dependency
|
|
76
83
|
name: rake
|
|
77
84
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -92,14 +99,14 @@ dependencies:
|
|
|
92
99
|
requirements:
|
|
93
100
|
- - "~>"
|
|
94
101
|
- !ruby/object:Gem::Version
|
|
95
|
-
version:
|
|
102
|
+
version: '1.69'
|
|
96
103
|
type: :development
|
|
97
104
|
prerelease: false
|
|
98
105
|
version_requirements: !ruby/object:Gem::Requirement
|
|
99
106
|
requirements:
|
|
100
107
|
- - "~>"
|
|
101
108
|
- !ruby/object:Gem::Version
|
|
102
|
-
version:
|
|
109
|
+
version: '1.69'
|
|
103
110
|
- !ruby/object:Gem::Dependency
|
|
104
111
|
name: timecop
|
|
105
112
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -144,6 +151,7 @@ files:
|
|
|
144
151
|
- lib/open_exchange_rates_bank/version.rb
|
|
145
152
|
- test/data/2015-01-01.json
|
|
146
153
|
- test/data/access_restricted_error.json
|
|
154
|
+
- test/data/app_id_inactive.json
|
|
147
155
|
- test/data/latest.json
|
|
148
156
|
- test/integration/Gemfile
|
|
149
157
|
- test/integration/Gemfile.lock
|
|
@@ -153,8 +161,8 @@ files:
|
|
|
153
161
|
homepage: http://github.com/spk/money-open-exchange-rates
|
|
154
162
|
licenses:
|
|
155
163
|
- MIT
|
|
156
|
-
metadata:
|
|
157
|
-
|
|
164
|
+
metadata:
|
|
165
|
+
rubygems_mfa_required: 'true'
|
|
158
166
|
rdoc_options: []
|
|
159
167
|
require_paths:
|
|
160
168
|
- lib
|
|
@@ -162,16 +170,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
162
170
|
requirements:
|
|
163
171
|
- - ">="
|
|
164
172
|
- !ruby/object:Gem::Version
|
|
165
|
-
version: '
|
|
173
|
+
version: '3.1'
|
|
166
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
167
175
|
requirements:
|
|
168
176
|
- - ">="
|
|
169
177
|
- !ruby/object:Gem::Version
|
|
170
178
|
version: '0'
|
|
171
179
|
requirements: []
|
|
172
|
-
rubygems_version: 3.
|
|
173
|
-
signing_key:
|
|
180
|
+
rubygems_version: 3.6.7
|
|
174
181
|
specification_version: 4
|
|
175
182
|
summary: A gem that calculates the exchange rate using published rates from open-exchange-rates.
|
|
176
|
-
test_files:
|
|
177
|
-
- test/open_exchange_rates_bank_test.rb
|
|
183
|
+
test_files: []
|