money-open-exchange-rates 1.4.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/History.md +20 -0
- data/LICENSE +1 -1
- data/README.md +1 -1
- data/lib/money/bank/open_exchange_rates_bank.rb +18 -2
- data/lib/open_exchange_rates_bank/version.rb +1 -1
- data/test/data/access_restricted_error.json +6 -0
- data/test/data/app_id_inactive.json +1 -0
- data/test/integration/Gemfile +2 -0
- data/test/integration/Gemfile.lock +11 -13
- data/test/open_exchange_rates_bank_test.rb +25 -7
- metadata +9 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86f324ed978cde7c5b05b50a8fe3d1ce4740333874457c8776c9871b3fa9ee31
|
4
|
+
data.tar.gz: ef5d0c06086d520f7a8816a69007b98d4741fb0063148ee0c66b9ec29a658b6d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5361f382ab1462ae3c6b1a18e543c1dbe4d8d31f68278c460092d8fd93b65a9fd9070f290915a498b1b9bb10b2c6c6c6fb3bff356a90f0f0b75b12d296914990
|
7
|
+
data.tar.gz: d85876e62c4f13ebe24c71a273cb6667e7a331707cd7f48e90393b1d620b51593ff03cc77bc24cac78075fd21983290d99cba5eb62bfdb3c2235d1b790669f8d
|
data/History.md
CHANGED
@@ -1,4 +1,24 @@
|
|
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
|
+
|
2
22
|
1.4.0 / 2020-09-11
|
3
23
|
==================
|
4
24
|
|
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
@@ -249,7 +249,7 @@ See [GitHub](https://github.com/spk/money-open-exchange-rates/graphs/contributor
|
|
249
249
|
|
250
250
|
The MIT License
|
251
251
|
|
252
|
-
Copyright © 2011-
|
252
|
+
Copyright © 2011-2023 Laurent Arnoud <laurent@spkdev.net>
|
253
253
|
|
254
254
|
---
|
255
255
|
[![Build](https://img.shields.io/gitlab/pipeline/spkdev/money-open-exchange-rates/master)](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
|
@@ -17,6 +18,17 @@ class Money
|
|
17
18
|
# APP_ID not set error
|
18
19
|
class NoAppId < StandardError; end
|
19
20
|
|
21
|
+
# Access restricted (e.g. usage/request limit exceeded for account)
|
22
|
+
class AccessRestricted < StandardError; end
|
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
|
+
|
20
32
|
# OpenExchangeRatesBank base class
|
21
33
|
class OpenExchangeRatesBank < Money::Bank::VariableExchange
|
22
34
|
VERSION = ::OpenExchangeRatesBank::VERSION
|
@@ -371,6 +383,10 @@ class Money
|
|
371
383
|
# @return [Hash] key is country code (ISO 3166-1 alpha-3) value Float
|
372
384
|
def exchange_rates
|
373
385
|
doc = JSON.parse(read_from_cache || read_from_url)
|
386
|
+
if doc['error'] && ERROR_MAP.key?(doc['message'].to_sym)
|
387
|
+
raise ERROR_MAP[doc['message'].to_sym]
|
388
|
+
end
|
389
|
+
|
374
390
|
self.rates_timestamp = doc[TIMESTAMP_KEY]
|
375
391
|
@oer_rates = doc[RATES_KEY]
|
376
392
|
end
|
@@ -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
|
@@ -25,6 +25,12 @@ describe Money::Bank::OpenExchangeRatesBank do
|
|
25
25
|
let(:oer_historical_path) do
|
26
26
|
data_file('2015-01-01.json')
|
27
27
|
end
|
28
|
+
let(:oer_access_restricted_error_path) do
|
29
|
+
data_file('access_restricted_error.json')
|
30
|
+
end
|
31
|
+
let(:oer_app_id_inactive_error_path) do
|
32
|
+
data_file('app_id_inactive.json')
|
33
|
+
end
|
28
34
|
|
29
35
|
describe 'exchange' do
|
30
36
|
before do
|
@@ -96,6 +102,20 @@ describe Money::Bank::OpenExchangeRatesBank do
|
|
96
102
|
subject.update_rates
|
97
103
|
end
|
98
104
|
|
105
|
+
it 'should raise AccessRestricted error when restricted by oer' do
|
106
|
+
subject.cache = nil
|
107
|
+
filepath = oer_access_restricted_error_path
|
108
|
+
subject.stubs(:api_response).returns File.read(filepath)
|
109
|
+
_(proc { subject.update_rates }).must_raise Money::Bank::AccessRestricted
|
110
|
+
end
|
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
|
+
|
99
119
|
it 'should update itself with exchange rates from OpenExchangeRates' do
|
100
120
|
subject.oer_rates.keys.each do |currency|
|
101
121
|
next unless Money::Currency.find(currency)
|
@@ -285,13 +305,11 @@ describe Money::Bank::OpenExchangeRatesBank do
|
|
285
305
|
end
|
286
306
|
|
287
307
|
it 'should allow update after save' do
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
assert false, 'Should allow updating after saving'
|
294
|
-
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'
|
295
313
|
end
|
296
314
|
|
297
315
|
it 'should not break an existing file if save fails to read' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: money-open-exchange-rates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Laurent Arnoud
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: money
|
@@ -143,6 +143,8 @@ files:
|
|
143
143
|
- lib/money/bank/open_exchange_rates_bank.rb
|
144
144
|
- lib/open_exchange_rates_bank/version.rb
|
145
145
|
- test/data/2015-01-01.json
|
146
|
+
- test/data/access_restricted_error.json
|
147
|
+
- test/data/app_id_inactive.json
|
146
148
|
- test/data/latest.json
|
147
149
|
- test/integration/Gemfile
|
148
150
|
- test/integration/Gemfile.lock
|
@@ -153,7 +155,7 @@ homepage: http://github.com/spk/money-open-exchange-rates
|
|
153
155
|
licenses:
|
154
156
|
- MIT
|
155
157
|
metadata: {}
|
156
|
-
post_install_message:
|
158
|
+
post_install_message:
|
157
159
|
rdoc_options: []
|
158
160
|
require_paths:
|
159
161
|
- lib
|
@@ -161,15 +163,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
163
|
requirements:
|
162
164
|
- - ">="
|
163
165
|
- !ruby/object:Gem::Version
|
164
|
-
version: '2.
|
166
|
+
version: '2.6'
|
165
167
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
168
|
requirements:
|
167
169
|
- - ">="
|
168
170
|
- !ruby/object:Gem::Version
|
169
171
|
version: '0'
|
170
172
|
requirements: []
|
171
|
-
rubygems_version: 3.
|
172
|
-
signing_key:
|
173
|
+
rubygems_version: 3.3.15
|
174
|
+
signing_key:
|
173
175
|
specification_version: 4
|
174
176
|
summary: A gem that calculates the exchange rate using published rates from open-exchange-rates.
|
175
177
|
test_files:
|