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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 213847dd55f3bbc717a20dc056e61510f4b00ede31bce5b1c7022b16eedc875e
4
- data.tar.gz: e245e87886f4c2fc2d8ae6fcf25c80d5f7797ffc3d877eaafab18abd2f911050
3
+ metadata.gz: 86f324ed978cde7c5b05b50a8fe3d1ce4740333874457c8776c9871b3fa9ee31
4
+ data.tar.gz: ef5d0c06086d520f7a8816a69007b98d4741fb0063148ee0c66b9ec29a658b6d
5
5
  SHA512:
6
- metadata.gz: 7a63501cb0baad531f152bedc2a232697f9c64da9bfeef9dd576ecbcda9dceaed83aba902f272c5cd4d44af20e9a55bd7654e1c244a60a5620b9db6f033c6f4b
7
- data.tar.gz: 0c5466657cac8fb4e826d7d9e24ac354778eca529ac156385d3dc44070ed78d3e9278ffc2e17ccad705311195fdaa2822d17855cbcd2e721d90cab37ebe1c0c2
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-2020 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
@@ -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-2020 Laurent Arnoud <laurent@spkdev.net>
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  # Module for version constant
4
4
  module OpenExchangeRatesBank
5
- VERSION = '1.4.0'
5
+ VERSION = '1.4.2'
6
6
  end
@@ -0,0 +1,6 @@
1
+ {
2
+ "error": true,
3
+ "status": 429,
4
+ "message": "access_restricted",
5
+ "description": "Access restricted until 2050-01-01 (reason: too_many_requests). If there has been a mistake, please contact support@openexchangerates.org."
6
+ }
@@ -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."}
@@ -1,4 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ source 'https://rubygems.org'
4
+
3
5
  gem 'money', '~> 6.7'
4
6
  gem 'money-open-exchange-rates', path: '../../'
@@ -1,26 +1,24 @@
1
1
  PATH
2
- remote: ../../
2
+ remote: ../..
3
3
  specs:
4
- money-open-exchange-rates (0.6.1)
5
- monetize (~> 1.4)
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
- i18n (0.7.0)
11
- monetize (1.4.0)
12
- money (~> 6.7)
13
- money (6.7.1)
14
- i18n (>= 0.6.4, <= 0.7.0)
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
- ruby
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
- 1.13.1
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
- begin
289
- subject.refresh_rates
290
- # rubocop:disable Style/RescueStandardError
291
- rescue
292
- # rubocop:enable Style/RescueStandardError
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.0
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: 2020-09-11 00:00:00.000000000 Z
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.4'
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.1.2
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: