omni_exchange 1.8.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -3
- data/lib/omni_exchange/providers/open_exchange_rates.rb +2 -8
- data/lib/omni_exchange/providers/xe.rb +2 -6
- data/lib/omni_exchange/version.rb +1 -1
- data/lib/omni_exchange.rb +15 -5
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b8b209ec25ddad7e22d1aecc9c8073e6e41ac9e6121e29fcb15c1a240a86a80
|
4
|
+
data.tar.gz: d31a7913b18dd4636d449e86f7bb059c2196026e360b2dbdc20e6376e91a96ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4e0c80da124045ae0ae12d4c874e464ba6084e399ca6b785bc8c23641a88169c9cb1548f90fd4c7e563a48d31f633568b4a0d3545f0d80e98494931e163f985f
|
7
|
+
data.tar.gz: '08705073d9dc0f158e67c067a021e122527e69851f7d62ce08cb494b30cc681399ef9567a820a9dcea2a1fae79f66d970ed0c3709c500a7fdf9114fcbc99abdc'
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
omni_exchange (1.
|
4
|
+
omni_exchange (1.9.0)
|
5
5
|
faraday (< 2)
|
6
6
|
money (~> 6.13.1)
|
7
7
|
|
@@ -10,7 +10,7 @@ GEM
|
|
10
10
|
specs:
|
11
11
|
ast (2.4.2)
|
12
12
|
coderay (1.1.3)
|
13
|
-
concurrent-ruby (1.
|
13
|
+
concurrent-ruby (1.2.2)
|
14
14
|
diff-lcs (1.5.0)
|
15
15
|
dotenv (2.8.1)
|
16
16
|
faraday (1.10.3)
|
@@ -36,7 +36,7 @@ GEM
|
|
36
36
|
faraday-patron (1.0.0)
|
37
37
|
faraday-rack (1.0.0)
|
38
38
|
faraday-retry (1.0.3)
|
39
|
-
i18n (1.
|
39
|
+
i18n (1.14.1)
|
40
40
|
concurrent-ruby (~> 1.0)
|
41
41
|
method_source (1.0.0)
|
42
42
|
money (6.13.8)
|
@@ -23,10 +23,7 @@ module OmniExchange
|
|
23
23
|
req.params['symbols'] = target_currency
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
currency_unit = get_currency_unit(base_currency).to_d
|
28
|
-
|
29
|
-
(exchange_rate * currency_unit).to_d
|
26
|
+
body['rates'][target_currency].to_d
|
30
27
|
end
|
31
28
|
|
32
29
|
def get_historic_rate(base_currency:, target_currencies:, date:)
|
@@ -37,10 +34,7 @@ module OmniExchange
|
|
37
34
|
req.params['symbols'] = target_currencies.join(',')
|
38
35
|
end
|
39
36
|
|
40
|
-
|
41
|
-
body['rates'].transform_values do |rate|
|
42
|
-
(rate * currency_unit).to_d
|
43
|
-
end
|
37
|
+
body['rates']
|
44
38
|
end
|
45
39
|
|
46
40
|
private
|
@@ -17,14 +17,12 @@ module OmniExchange
|
|
17
17
|
# rate will be used to calculate an convert an exchange of currencies. However, an exception will be raised
|
18
18
|
# if there is a timeout while connecting to xe.com or a timeout while reading xe.com's API.
|
19
19
|
def get_exchange_rate(base_currency:, target_currency:)
|
20
|
-
currency_unit = get_currency_unit(base_currency)
|
21
|
-
|
22
20
|
body = api_get do |req|
|
23
21
|
req.url 'v1/convert_from.json'
|
24
22
|
|
25
23
|
req.params['from'] = base_currency
|
26
24
|
req.params['to'] = target_currency
|
27
|
-
req.params['amount'] =
|
25
|
+
req.params['amount'] = 1
|
28
26
|
end
|
29
27
|
|
30
28
|
body[:to][0][:mid].to_d
|
@@ -38,14 +36,12 @@ module OmniExchange
|
|
38
36
|
# exchanging to. ie. ["EUR", "KRW"]
|
39
37
|
# @param date: [Date] the date for which you want the historic exchange rate.
|
40
38
|
def get_historic_rate(base_currency:, target_currencies:, date:)
|
41
|
-
currency_unit = get_currency_unit(base_currency)
|
42
|
-
|
43
39
|
body = api_get do |req|
|
44
40
|
req.url 'v1/historic_rate.json'
|
45
41
|
|
46
42
|
req.params['from'] = base_currency
|
47
43
|
req.params['to'] = target_currencies.join(',')
|
48
|
-
req.params['amount'] =
|
44
|
+
req.params['amount'] = 1
|
49
45
|
req.params['date'] = date.strftime('%Y-%m-%d')
|
50
46
|
end
|
51
47
|
|
data/lib/omni_exchange.rb
CHANGED
@@ -116,14 +116,19 @@ module OmniExchange
|
|
116
116
|
error_messages = []
|
117
117
|
|
118
118
|
provider_classes.each do |klass|
|
119
|
-
|
119
|
+
rate = klass.get_exchange_rate(base_currency: base_currency,
|
120
120
|
target_currency: target_currency)
|
121
121
|
|
122
|
+
return {
|
123
|
+
rate: rate,
|
124
|
+
provider: OmniExchange::Provider.all.key(klass)
|
125
|
+
}
|
126
|
+
|
122
127
|
rescue *EXCEPTIONS, OmniExchange::XeMonthlyLimit, JSON::ParserError => e
|
123
128
|
error_messages << e.inspect
|
124
129
|
end
|
125
130
|
|
126
|
-
raise OmniExchange::HttpError, "Failed to get
|
131
|
+
raise OmniExchange::HttpError, "Failed to get exchange rate:\n" \
|
127
132
|
"#{error_messages.join("\n")}"
|
128
133
|
end
|
129
134
|
|
@@ -146,9 +151,14 @@ module OmniExchange
|
|
146
151
|
error_messages = []
|
147
152
|
|
148
153
|
provider_classes.each do |klass|
|
149
|
-
|
150
|
-
|
151
|
-
|
154
|
+
rates = klass.get_historic_rate(base_currency: base_currency,
|
155
|
+
target_currencies: target_currencies,
|
156
|
+
date: date)
|
157
|
+
|
158
|
+
return {
|
159
|
+
rates: rates,
|
160
|
+
provider: OmniExchange::Provider.all.key(klass)
|
161
|
+
}
|
152
162
|
|
153
163
|
rescue *EXCEPTIONS, OmniExchange::XeMonthlyLimit, JSON::ParserError => e
|
154
164
|
error_messages << e.inspect
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omni_exchange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yun Chung
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -175,7 +175,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
175
|
- !ruby/object:Gem::Version
|
176
176
|
version: '0'
|
177
177
|
requirements: []
|
178
|
-
rubygems_version: 3.
|
178
|
+
rubygems_version: 3.3.26
|
179
179
|
signing_key:
|
180
180
|
specification_version: 4
|
181
181
|
summary: OmniExchange converts currencies using up-to-the-minute foreign exchange
|