money-currencylayer-bank 0.5.4 → 0.5.8
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 +5 -5
- data/LICENSE +1 -1
- data/README.md +24 -15
- data/lib/money/bank/currencylayer_bank.rb +57 -46
- data/test/currencylayer_bank_test.rb +27 -26
- metadata +5 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ad15fc05b8e56c61e10554fd8574e0dbd358e3adc287c140ee11cb4b5c5747d8
|
4
|
+
data.tar.gz: 3ace2bd923ee971f5f6fca67f5ada19a0edf25687fbf0806b197f8876ee33146
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25849b05854111ab7ec51474fdbe9d02a5dd03d80719d46f0358a1c9c87b63e6296f2edcacd46e65e975e5510f16a456b4be50f1c92aa87c2b9af81504d5cf49
|
7
|
+
data.tar.gz: ce7667380baef8501825232ff7425b3a3121e85f0bfc4d8656d4c8b310e50d84ed787e6384d7da1bd692bf44233cccbaadee7dcf559232aece1ef83b28f258ec
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -3,9 +3,8 @@
|
|
3
3
|
[](https://rubygems.org/gems/money-currencylayer-bank)
|
4
4
|
[](https://rubygems.org/gems/money-currencylayer-bank)
|
5
5
|
[](https://travis-ci.org/phlegx/money-currencylayer-bank)
|
6
|
-
[](https://codeclimate.com/github/phlegx/money-currencylayer-bank)
|
7
7
|
[](http://inch-ci.org/github/phlegx/money-currencylayer-bank)
|
8
|
-
[](https://gemnasium.com/phlegx/money-currencylayer-bank)
|
9
8
|
[](http://opensource.org/licenses/MIT)
|
10
9
|
|
11
10
|
A gem that calculates the exchange rate using published rates from
|
@@ -40,6 +39,7 @@ See more about Currencylayer product plans on https://currencylayer.com/product.
|
|
40
39
|
* average response time < 20ms
|
41
40
|
* supports caching currency rates
|
42
41
|
* calculates every pair rate calculating inverse rate or using base currency rate
|
42
|
+
* supports multiple server instances, thread safe
|
43
43
|
|
44
44
|
## Installation
|
45
45
|
|
@@ -60,36 +60,41 @@ Or install it yourself as:
|
|
60
60
|
## Usage
|
61
61
|
|
62
62
|
~~~ ruby
|
63
|
-
# Minimal requirements
|
63
|
+
# Minimal requirements.
|
64
64
|
require 'money/bank/currencylayer_bank'
|
65
65
|
mclb = Money::Bank::CurrencylayerBank.new
|
66
66
|
mclb.access_key = 'your access_key from https://currencylayer.com/product'
|
67
67
|
|
68
|
-
# Update rates (get new rates from remote if expired or access rates from cache)
|
69
|
-
mclb.update_rates
|
70
|
-
|
71
|
-
# Force update rates from remote and store in cache
|
72
|
-
# mclb.update_rates(true)
|
73
|
-
|
74
68
|
# (optional)
|
75
69
|
# Set the base currency for all rates. By default, USD is used.
|
76
70
|
# CurrencylayerBank only allows USD as base currency for the free plan users.
|
77
71
|
mclb.source = 'EUR'
|
78
72
|
|
79
73
|
# (optional)
|
80
|
-
# Set the seconds after than the current rates are automatically expired
|
74
|
+
# Set the seconds after than the current rates are automatically expired.
|
81
75
|
# by default, they never expire, in this example 1 day.
|
82
76
|
mclb.ttl_in_seconds = 86400
|
83
77
|
|
84
78
|
# (optional)
|
85
|
-
# Use https to fetch rates from CurrencylayerBank
|
79
|
+
# Use https to fetch rates from CurrencylayerBank.
|
86
80
|
# CurrencylayerBank only allows http as connection for the free plan users.
|
87
81
|
mclb.secure_connection = true
|
88
82
|
|
89
|
-
# Define cache (string or pathname)
|
83
|
+
# Define cache (string or pathname).
|
90
84
|
mclb.cache = 'path/to/file/cache'
|
91
85
|
|
92
|
-
#
|
86
|
+
# Update rates (get new rates from remote if expired or access rates from cache).
|
87
|
+
# Be sure to define the cache first before updating the rates.
|
88
|
+
mclb.update_rates
|
89
|
+
|
90
|
+
# Force update rates from remote and store in cache.
|
91
|
+
# Be sure to define the cache first before updating the rates.
|
92
|
+
# mclb.update_rates(true)
|
93
|
+
|
94
|
+
# Set money rounding mode.
|
95
|
+
Money.rounding_mode = BigDecimal::ROUND_HALF_EVEN
|
96
|
+
|
97
|
+
# Set money default bank to Currencylayer bank.
|
93
98
|
Money.default_bank = mclb
|
94
99
|
~~~
|
95
100
|
|
@@ -104,7 +109,7 @@ mclb.source
|
|
104
109
|
# Expires rates if the expiration time is reached.
|
105
110
|
mclb.expire_rates!
|
106
111
|
|
107
|
-
#
|
112
|
+
# Returns true if the expiration time is reached.
|
108
113
|
mclb.expired?
|
109
114
|
|
110
115
|
# Get the API source url.
|
@@ -112,6 +117,9 @@ mclb.source_url
|
|
112
117
|
|
113
118
|
# Get the rates timestamp of the last API request.
|
114
119
|
mclb.rates_timestamp
|
120
|
+
|
121
|
+
# Get the rates timestamp of loaded rates in memory.
|
122
|
+
moxb.rates_mem_timestamp
|
115
123
|
~~~
|
116
124
|
|
117
125
|
### How to exchange
|
@@ -184,6 +192,7 @@ bundle exec rake
|
|
184
192
|
## Other Implementations
|
185
193
|
|
186
194
|
* Gem [currencylayer](https://github.com/askuratovsky/currencylayer)
|
195
|
+
* Gem [money-openexchangerates-bank](https://github.com/phlegx/money-openexchangerates-bank)
|
187
196
|
* Gem [money-open-exchange-rates](https://github.com/spk/money-open-exchange-rates)
|
188
197
|
* Gem [money-historical-bank](https://github.com/atwam/money-historical-bank)
|
189
198
|
* Gem [eu_central_bank](https://github.com/RubyMoney/eu_central_bank)
|
@@ -207,4 +216,4 @@ bundle exec rake
|
|
207
216
|
|
208
217
|
The MIT License
|
209
218
|
|
210
|
-
Copyright (c)
|
219
|
+
Copyright (c) 2022 Phlegx Systems OG
|
@@ -13,7 +13,6 @@ class Money
|
|
13
13
|
class Memory
|
14
14
|
# Add method to reset the build in memory store
|
15
15
|
# @param [Hash] rt Optional initial exchange rate data.
|
16
|
-
#
|
17
16
|
# @return [Object] store.
|
18
17
|
def reset!(rt = {})
|
19
18
|
transaction { @index = rt }
|
@@ -32,32 +31,29 @@ class Money
|
|
32
31
|
# CurrencylayerBank base class
|
33
32
|
class CurrencylayerBank < Money::Bank::VariableExchange
|
34
33
|
# CurrencylayerBank url
|
35
|
-
CL_URL = 'http://
|
34
|
+
CL_URL = 'http://api.currencylayer.com/live'.freeze
|
36
35
|
# CurrencylayerBank secure url
|
37
|
-
CL_SECURE_URL = CL_URL.
|
36
|
+
CL_SECURE_URL = CL_URL.sub('http:', 'https:')
|
38
37
|
# Default base currency
|
39
|
-
CL_SOURCE = 'USD'
|
38
|
+
CL_SOURCE = 'USD'.freeze
|
40
39
|
|
41
40
|
# Use https to fetch rates from CurrencylayerBank
|
42
41
|
# CurrencylayerBank only allows http as connection
|
43
42
|
# for the free plan users.
|
44
43
|
#
|
45
44
|
# @param value [Boolean] true for secure connection
|
46
|
-
#
|
47
45
|
# @return [Boolean] chosen secure connection
|
48
46
|
attr_accessor :secure_connection
|
49
47
|
|
50
48
|
# API must have a valid access_key
|
51
49
|
#
|
52
50
|
# @param value [String] API access key
|
53
|
-
#
|
54
51
|
# @return [String] chosen API access key
|
55
52
|
attr_accessor :access_key
|
56
53
|
|
57
54
|
# Cache accessor, can be a String or a Proc
|
58
55
|
#
|
59
56
|
# @param value [String,Pathname,Proc] cache system
|
60
|
-
#
|
61
57
|
# @return [String,Pathname,Proc] chosen cache system
|
62
58
|
attr_accessor :cache
|
63
59
|
|
@@ -75,7 +71,6 @@ class Money
|
|
75
71
|
# ttl_in_seconds = 86400 # will expire the rates in one day
|
76
72
|
#
|
77
73
|
# @param value [Integer] time to live in seconds
|
78
|
-
#
|
79
74
|
# @return [Integer] chosen time to live in seconds
|
80
75
|
attr_writer :ttl_in_seconds
|
81
76
|
|
@@ -87,7 +82,6 @@ class Money
|
|
87
82
|
# source = 'USD'
|
88
83
|
#
|
89
84
|
# @param value [String] Currency code, ISO 3166-1 alpha-3
|
90
|
-
#
|
91
85
|
# @return [String] chosen base currency
|
92
86
|
def source=(value)
|
93
87
|
@source = Money::Currency.find(value.to_s).try(:iso_code) || CL_SOURCE
|
@@ -110,7 +104,7 @@ class Money
|
|
110
104
|
# @return [Array] array of exchange rates
|
111
105
|
def update_rates(straight = false)
|
112
106
|
store.reset!
|
113
|
-
exchange_rates(straight).each do |exchange_rate|
|
107
|
+
rates = exchange_rates(straight).each do |exchange_rate|
|
114
108
|
currency = exchange_rate.first[3..-1]
|
115
109
|
rate = exchange_rate.last
|
116
110
|
next unless Money::Currency.find(currency)
|
@@ -118,53 +112,30 @@ class Money
|
|
118
112
|
add_rate(currency, source, 1.0 / rate)
|
119
113
|
end
|
120
114
|
@rates_mem_timestamp = rates_timestamp
|
115
|
+
rates
|
121
116
|
end
|
122
117
|
|
123
118
|
# Override Money `add_rate` method for caching
|
124
119
|
# @param [String] from_currency Currency ISO code. ex. 'USD'
|
125
120
|
# @param [String] to_currency Currency ISO code. ex. 'CAD'
|
126
121
|
# @param [Numeric] rate Rate to use when exchanging currencies.
|
127
|
-
#
|
128
122
|
# @return [Numeric] rate.
|
129
123
|
def add_rate(from_currency, to_currency, rate)
|
130
124
|
super
|
131
125
|
end
|
132
126
|
|
127
|
+
# Alias super method
|
128
|
+
alias super_get_rate get_rate
|
129
|
+
|
133
130
|
# Override Money `get_rate` method for caching
|
134
131
|
# @param [String] from_currency Currency ISO code. ex. 'USD'
|
135
132
|
# @param [String] to_currency Currency ISO code. ex. 'CAD'
|
136
133
|
# @param [Hash] opts Options hash to set special parameters.
|
137
|
-
#
|
138
134
|
# @return [Numeric] rate.
|
139
|
-
def get_rate(from_currency, to_currency, opts = {})
|
135
|
+
def get_rate(from_currency, to_currency, opts = {})
|
140
136
|
expire_rates!
|
141
|
-
rate =
|
142
|
-
|
143
|
-
# Tries to calculate an inverse rate
|
144
|
-
inverse_rate = super(to_currency, from_currency, opts)
|
145
|
-
if inverse_rate
|
146
|
-
rate = 1.0 / inverse_rate
|
147
|
-
add_rate(from_currency, to_currency, rate)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
unless rate
|
151
|
-
# Tries to calculate a pair rate using base currency rate
|
152
|
-
from_base_rate = super(source, from_currency, opts)
|
153
|
-
unless from_base_rate
|
154
|
-
from_inverse_rate = super(from_currency, source, opts)
|
155
|
-
from_base_rate = 1.0 / from_inverse_rate if from_inverse_rate
|
156
|
-
end
|
157
|
-
to_base_rate = super(source, to_currency, opts)
|
158
|
-
unless to_base_rate
|
159
|
-
to_inverse_rate = super(to_currency, source, opts)
|
160
|
-
to_base_rate = 1.0 / to_inverse_rate if to_inverse_rate
|
161
|
-
end
|
162
|
-
if to_base_rate && from_base_rate
|
163
|
-
rate = to_base_rate / from_base_rate
|
164
|
-
add_rate(from_currency, to_currency, rate)
|
165
|
-
end
|
166
|
-
end
|
167
|
-
rate
|
137
|
+
rate = get_rate_or_calc_inverse(from_currency, to_currency, opts)
|
138
|
+
rate || calc_pair_rate_using_base(from_currency, to_currency, opts)
|
168
139
|
end
|
169
140
|
|
170
141
|
# Fetch new rates if cached rates are expired or stale
|
@@ -269,7 +240,7 @@ class Money
|
|
269
240
|
# Opens an url and reads the content
|
270
241
|
# @return [String] unparsed JSON content
|
271
242
|
def open_url
|
272
|
-
open(source_url).read
|
243
|
+
URI.open(source_url).read
|
273
244
|
rescue OpenURI::HTTPError
|
274
245
|
''
|
275
246
|
end
|
@@ -297,14 +268,22 @@ class Money
|
|
297
268
|
# @param straight [Boolean] true for straight, default is careful
|
298
269
|
# @return [Hash] key is country code (ISO 3166-1 alpha-3) value Float
|
299
270
|
def exchange_rates(straight = false)
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
271
|
+
rates = if straight
|
272
|
+
raw_rates_straight
|
273
|
+
else
|
274
|
+
raw_rates_careful
|
275
|
+
end
|
276
|
+
if rates.key?('quotes')
|
277
|
+
@rates = rates['quotes']
|
278
|
+
elsif rates.key?('error')
|
279
|
+
raise Error, rates.dig('error', 'info')
|
280
|
+
else
|
281
|
+
raise Error, 'Unknown rates situation!'
|
282
|
+
end
|
305
283
|
end
|
306
284
|
|
307
285
|
# Get raw exchange rates from cache and then from url
|
286
|
+
# @param rescue_straight [Boolean] true for rescue straight, default true
|
308
287
|
# @return [String] JSON content
|
309
288
|
def raw_rates_careful(rescue_straight = true)
|
310
289
|
JSON.parse(read_from_cache.to_s)
|
@@ -319,6 +298,38 @@ class Money
|
|
319
298
|
rescue JSON::ParserError
|
320
299
|
raw_rates_careful(false)
|
321
300
|
end
|
301
|
+
|
302
|
+
# Get rate or calculate it as inverse rate
|
303
|
+
# @param [String] from_currency Currency ISO code. ex. 'USD'
|
304
|
+
# @param [String] to_currency Currency ISO code. ex. 'CAD'
|
305
|
+
# @return [Numeric] rate or rate calculated as inverse rate.
|
306
|
+
def get_rate_or_calc_inverse(from_currency, to_currency, opts = {})
|
307
|
+
rate = super_get_rate(from_currency, to_currency, opts)
|
308
|
+
unless rate
|
309
|
+
# Tries to calculate an inverse rate
|
310
|
+
inverse_rate = super_get_rate(to_currency, from_currency, opts)
|
311
|
+
if inverse_rate
|
312
|
+
rate = 1.0 / inverse_rate
|
313
|
+
add_rate(from_currency, to_currency, rate)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
rate
|
317
|
+
end
|
318
|
+
|
319
|
+
# Tries to calculate a pair rate using base currency rate
|
320
|
+
# @param [String] from_currency Currency ISO code. ex. 'USD'
|
321
|
+
# @param [String] to_currency Currency ISO code. ex. 'CAD'
|
322
|
+
# @return [Numeric] rate or nil if cannot calculate rate.
|
323
|
+
def calc_pair_rate_using_base(from_currency, to_currency, opts = {})
|
324
|
+
from_base_rate = get_rate_or_calc_inverse(source, from_currency, opts)
|
325
|
+
to_base_rate = get_rate_or_calc_inverse(source, to_currency, opts)
|
326
|
+
if to_base_rate && from_base_rate
|
327
|
+
rate = to_base_rate / from_base_rate
|
328
|
+
add_rate(from_currency, to_currency, rate)
|
329
|
+
return rate
|
330
|
+
end
|
331
|
+
nil
|
332
|
+
end
|
322
333
|
end
|
323
334
|
end
|
324
335
|
end
|
@@ -4,6 +4,7 @@
|
|
4
4
|
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
5
5
|
|
6
6
|
describe Money::Bank::CurrencylayerBank do
|
7
|
+
Money.rounding_mode = BigDecimal::ROUND_HALF_EVEN
|
7
8
|
subject { Money::Bank::CurrencylayerBank.new }
|
8
9
|
let(:url) { Money::Bank::CurrencylayerBank::CL_URL }
|
9
10
|
let(:secure_url) { Money::Bank::CurrencylayerBank::CL_SECURE_URL }
|
@@ -30,12 +31,12 @@ describe Money::Bank::CurrencylayerBank do
|
|
30
31
|
describe 'without rates' do
|
31
32
|
it 'able to exchange a money to its own currency even without rates' do
|
32
33
|
money = Money.new(0, 'USD')
|
33
|
-
subject.exchange_with(money, 'USD').must_equal money
|
34
|
+
_(subject.exchange_with(money, 'USD')).must_equal money
|
34
35
|
end
|
35
36
|
|
36
37
|
it "raise if it can't find an exchange rate" do
|
37
38
|
money = Money.new(0, 'USD')
|
38
|
-
proc { subject.exchange_with(money, 'SSP') }
|
39
|
+
_(proc { subject.exchange_with(money, 'SSP') })
|
39
40
|
.must_raise Money::Bank::UnknownRate
|
40
41
|
end
|
41
42
|
end
|
@@ -47,17 +48,17 @@ describe Money::Bank::CurrencylayerBank do
|
|
47
48
|
|
48
49
|
it 'should be able to exchange money from USD to a known exchange rate' do
|
49
50
|
money = Money.new(100, 'USD')
|
50
|
-
subject.exchange_with(money, 'BBD').must_equal Money.new(200, 'BBD')
|
51
|
+
_(subject.exchange_with(money, 'BBD')).must_equal Money.new(200, 'BBD')
|
51
52
|
end
|
52
53
|
|
53
54
|
it 'should be able to exchange money from a known exchange rate to USD' do
|
54
55
|
money = Money.new(200, 'BBD')
|
55
|
-
subject.exchange_with(money, 'USD').must_equal Money.new(100, 'USD')
|
56
|
+
_(subject.exchange_with(money, 'USD')).must_equal Money.new(100, 'USD')
|
56
57
|
end
|
57
58
|
|
58
59
|
it "should raise if it can't find an exchange rate" do
|
59
60
|
money = Money.new(0, 'USD')
|
60
|
-
proc { subject.exchange_with(money, 'SSP') }
|
61
|
+
_(proc { subject.exchange_with(money, 'SSP') })
|
61
62
|
.must_raise Money::Bank::UnknownRate
|
62
63
|
end
|
63
64
|
end
|
@@ -87,21 +88,21 @@ describe Money::Bank::CurrencylayerBank do
|
|
87
88
|
initial_size = File.read(temp_cache_path).size
|
88
89
|
stub(subject).open_url { '' }
|
89
90
|
subject.update_rates
|
90
|
-
File.read(temp_cache_path).size.must_equal initial_size
|
91
|
+
_(File.read(temp_cache_path).size).must_equal initial_size
|
91
92
|
end
|
92
93
|
|
93
94
|
it 'should not break an existing file if save returns json without rates' do
|
94
95
|
initial_size = File.read(temp_cache_path).size
|
95
96
|
stub(subject).open_url { '{ "error": "An error" }' }
|
96
97
|
subject.update_rates
|
97
|
-
File.read(temp_cache_path).size.must_equal initial_size
|
98
|
+
_(File.read(temp_cache_path).size).must_equal initial_size
|
98
99
|
end
|
99
100
|
|
100
101
|
it 'should not break an existing file if save returns a invalid json' do
|
101
102
|
initial_size = File.read(temp_cache_path).size
|
102
103
|
stub(subject).open_url { '{ invalid_json: "An error" }' }
|
103
104
|
subject.update_rates
|
104
|
-
File.read(temp_cache_path).size.must_equal initial_size
|
105
|
+
_(File.read(temp_cache_path).size).must_equal initial_size
|
105
106
|
end
|
106
107
|
end
|
107
108
|
|
@@ -114,7 +115,7 @@ describe Money::Bank::CurrencylayerBank do
|
|
114
115
|
|
115
116
|
it 'should get from url' do
|
116
117
|
subject.update_rates
|
117
|
-
subject.rates.wont_be_empty
|
118
|
+
_(subject.rates).wont_be_empty
|
118
119
|
end
|
119
120
|
end
|
120
121
|
|
@@ -126,7 +127,7 @@ describe Money::Bank::CurrencylayerBank do
|
|
126
127
|
end
|
127
128
|
|
128
129
|
it 'should raise an error if invalid path is given' do
|
129
|
-
proc { subject.update_rates }.must_raise Money::Bank::InvalidCache
|
130
|
+
_(proc { subject.update_rates }).must_raise Money::Bank::InvalidCache
|
130
131
|
end
|
131
132
|
end
|
132
133
|
|
@@ -146,16 +147,16 @@ describe Money::Bank::CurrencylayerBank do
|
|
146
147
|
it 'should get from url normally' do
|
147
148
|
stub(subject).source_url { data_path }
|
148
149
|
subject.update_rates
|
149
|
-
subject.rates.wont_be_empty
|
150
|
+
_(subject.rates).wont_be_empty
|
150
151
|
end
|
151
152
|
|
152
153
|
it 'should save from url and get from cache' do
|
153
154
|
stub(subject).source_url { data_path }
|
154
155
|
subject.update_rates
|
155
|
-
@global_rates.wont_be_empty
|
156
|
+
_(@global_rates).wont_be_empty
|
156
157
|
dont_allow(subject).source_url
|
157
158
|
subject.update_rates
|
158
|
-
subject.rates.wont_be_empty
|
159
|
+
_(subject.rates).wont_be_empty
|
159
160
|
end
|
160
161
|
end
|
161
162
|
|
@@ -163,23 +164,23 @@ describe Money::Bank::CurrencylayerBank do
|
|
163
164
|
it "should use the non-secure http url if secure_connection isn't set" do
|
164
165
|
subject.secure_connection = nil
|
165
166
|
subject.access_key = TEST_ACCESS_KEY
|
166
|
-
subject.source_url.must_equal "#{url}?source=#{source}&"\
|
167
|
+
_(subject.source_url).must_equal "#{url}?source=#{source}&"\
|
167
168
|
"access_key=#{TEST_ACCESS_KEY}"
|
168
169
|
end
|
169
170
|
|
170
171
|
it 'should use the non-secure http url if secure_connection is false' do
|
171
172
|
subject.secure_connection = false
|
172
173
|
subject.access_key = TEST_ACCESS_KEY
|
173
|
-
subject.source_url.must_equal "#{url}?source=#{source}&"\
|
174
|
+
_(subject.source_url).must_equal "#{url}?source=#{source}&"\
|
174
175
|
"access_key=#{TEST_ACCESS_KEY}"
|
175
176
|
end
|
176
177
|
|
177
178
|
it 'should use the secure https url if secure_connection is set to true' do
|
178
179
|
subject.secure_connection = true
|
179
180
|
subject.access_key = TEST_ACCESS_KEY
|
180
|
-
subject.source_url.must_equal "#{secure_url}?source=#{source}&"\
|
181
|
+
_(subject.source_url).must_equal "#{secure_url}?source=#{source}&"\
|
181
182
|
"access_key=#{TEST_ACCESS_KEY}"
|
182
|
-
subject.source_url.must_include 'https://'
|
183
|
+
_(subject.source_url).must_include 'https://'
|
183
184
|
end
|
184
185
|
end
|
185
186
|
|
@@ -214,7 +215,7 @@ describe Money::Bank::CurrencylayerBank do
|
|
214
215
|
subject.add_rate('USD', 'WTF', 2)
|
215
216
|
subject.add_rate('WTF', 'USD', 2)
|
216
217
|
subject.exchange_with(5000.to_money('WTF'), 'USD').cents
|
217
|
-
subject.exchange_with(5000.to_money('WTF'), 'USD').cents.wont_equal 0
|
218
|
+
_(subject.exchange_with(5000.to_money('WTF'), 'USD').cents).wont_equal 0
|
218
219
|
end
|
219
220
|
end
|
220
221
|
end
|
@@ -226,7 +227,7 @@ describe Money::Bank::CurrencylayerBank do
|
|
226
227
|
end
|
227
228
|
|
228
229
|
it 'should raise an error if no access key is set' do
|
229
|
-
proc { subject.update_rates }.must_raise Money::Bank::NoAccessKey
|
230
|
+
_(proc { subject.update_rates }).must_raise Money::Bank::NoAccessKey
|
230
231
|
end
|
231
232
|
end
|
232
233
|
|
@@ -250,11 +251,11 @@ describe Money::Bank::CurrencylayerBank do
|
|
250
251
|
describe 'when the ttl has expired' do
|
251
252
|
it 'should update the rates' do
|
252
253
|
Timecop.freeze(subject.rates_timestamp + 1000) do
|
253
|
-
subject.get_rate('USD', 'EUR').must_equal @old_usd_eur_rate
|
254
|
+
_(subject.get_rate('USD', 'EUR')).must_equal @old_usd_eur_rate
|
254
255
|
end
|
255
256
|
Timecop.freeze(subject.rates_timestamp + 1001) do
|
256
|
-
subject.get_rate('USD', 'EUR').wont_equal @old_usd_eur_rate
|
257
|
-
subject.get_rate('USD', 'EUR').must_equal @new_usd_eur_rate
|
257
|
+
_(subject.get_rate('USD', 'EUR')).wont_equal @old_usd_eur_rate
|
258
|
+
_(subject.get_rate('USD', 'EUR')).must_equal @new_usd_eur_rate
|
258
259
|
end
|
259
260
|
end
|
260
261
|
|
@@ -262,7 +263,7 @@ describe Money::Bank::CurrencylayerBank do
|
|
262
263
|
Timecop.freeze(subject.rates_timestamp + 1001) do
|
263
264
|
exp_time = subject.rates_timestamp + 1000
|
264
265
|
subject.expire_rates!
|
265
|
-
subject.rates_expiration.must_equal exp_time
|
266
|
+
_(subject.rates_expiration).must_equal exp_time
|
266
267
|
end
|
267
268
|
end
|
268
269
|
end
|
@@ -272,7 +273,7 @@ describe Money::Bank::CurrencylayerBank do
|
|
272
273
|
subject.update_rates
|
273
274
|
exp_time = subject.rates_expiration
|
274
275
|
subject.expire_rates!
|
275
|
-
subject.rates_expiration.must_equal exp_time
|
276
|
+
_(subject.rates_expiration).must_equal exp_time
|
276
277
|
end
|
277
278
|
end
|
278
279
|
end
|
@@ -291,12 +292,12 @@ describe Money::Bank::CurrencylayerBank do
|
|
291
292
|
it 'should return 1970-01-01 datetime if no rates' do
|
292
293
|
stub(subject).open_url { '' }
|
293
294
|
subject.update_rates
|
294
|
-
subject.rates_timestamp.must_equal Time.at(0)
|
295
|
+
_(subject.rates_timestamp).must_equal Time.at(0)
|
295
296
|
end
|
296
297
|
|
297
298
|
it 'should return a Time object' do
|
298
299
|
subject.update_rates
|
299
|
-
subject.rates_timestamp.class.must_equal Time
|
300
|
+
_(subject.rates_timestamp.class).must_equal Time
|
300
301
|
end
|
301
302
|
end
|
302
303
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money-currencylayer-bank
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Egon Zemmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: money
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: 0.
|
131
|
+
version: 0.49.1
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: 0.
|
138
|
+
version: 0.49.1
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: inch
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -185,11 +185,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
185
185
|
- !ruby/object:Gem::Version
|
186
186
|
version: '0'
|
187
187
|
requirements: []
|
188
|
-
|
189
|
-
rubygems_version: 2.5.2
|
188
|
+
rubygems_version: 3.2.24
|
190
189
|
signing_key:
|
191
190
|
specification_version: 4
|
192
191
|
summary: A gem that calculates the exchange rate using published rates from currencylayer.com.
|
193
192
|
test_files:
|
194
193
|
- test/currencylayer_bank_test.rb
|
195
|
-
has_rdoc:
|