omni_exchange 1.7.0 → 1.9.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/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 +69 -0
- 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
@@ -98,5 +98,74 @@ module OmniExchange
|
|
98
98
|
raise OmniExchange::HttpError, "Failed to load #{base_currency}->#{target_currency}:\n" \
|
99
99
|
"#{error_messages.join("\n")}"
|
100
100
|
end
|
101
|
+
|
102
|
+
# returns the latest foreign exchange rate from the base currency to the target currency.
|
103
|
+
#
|
104
|
+
# @param base_currency: [String] the ISO Currency Code of the currency that you're exchanging from.
|
105
|
+
# ie. "USD", "JPY"
|
106
|
+
# @param target_currency: [String] the ISO Currency Code of the currency that you're exchanging to.
|
107
|
+
# ie. "EUR", "KRW"
|
108
|
+
# @param providers: [Array] an array of symbols of the providers that will be used to get exchange rates API
|
109
|
+
# data. The symbols must be found in the @providers hash in the Provider class (lib/omni_exchange/provider.rb).
|
110
|
+
# ie. xe:, :open_exchange_rates
|
111
|
+
# @ return [BigDecimal] an exchange rate is returned as a BigDecimal for precise calculation since this exchange
|
112
|
+
# rate will be used to calculate an convert an exchange of currencies.
|
113
|
+
def get_exchange_rate(base_currency:, target_currency:, providers:)
|
114
|
+
provider_classes = providers.map { |p| OmniExchange::Provider.load_provider(p) }
|
115
|
+
|
116
|
+
error_messages = []
|
117
|
+
|
118
|
+
provider_classes.each do |klass|
|
119
|
+
rate = klass.get_exchange_rate(base_currency: base_currency,
|
120
|
+
target_currency: target_currency)
|
121
|
+
|
122
|
+
return {
|
123
|
+
rate: rate,
|
124
|
+
provider: OmniExchange::Provider.all.key(klass)
|
125
|
+
}
|
126
|
+
|
127
|
+
rescue *EXCEPTIONS, OmniExchange::XeMonthlyLimit, JSON::ParserError => e
|
128
|
+
error_messages << e.inspect
|
129
|
+
end
|
130
|
+
|
131
|
+
raise OmniExchange::HttpError, "Failed to get exchange rate:\n" \
|
132
|
+
"#{error_messages.join("\n")}"
|
133
|
+
end
|
134
|
+
|
135
|
+
# returns the historic exchange rate from the base currency to the target currency at a certain date.
|
136
|
+
#
|
137
|
+
# @param base_currency: [String] the ISO Currency Code of the currency that you're exchanging from.
|
138
|
+
# ie. "USD", "JPY"
|
139
|
+
# @param target_currency: [String] the ISO Currency Code of the currency that you're exchanging to.
|
140
|
+
# ie. "EUR", "KRW"
|
141
|
+
# @param date: [Date] the specific date you want a historic exchange rate for.
|
142
|
+
# ie. Date.new(2018, 12, 25)
|
143
|
+
# @param providers: [Array] an array of symbols of the providers that will be used to get exchange rates API
|
144
|
+
# data. The symbols must be found in the @providers hash in the Provider class (lib/omni_exchange/provider.rb).
|
145
|
+
# ie. xe:, :open_exchange_rates
|
146
|
+
#
|
147
|
+
# @ return [Hash]: A hash containing the exchange rates.
|
148
|
+
def get_historic_rate(base_currency:, target_currencies:, date:, providers:)
|
149
|
+
provider_classes = providers.map { |p| OmniExchange::Provider.load_provider(p) }
|
150
|
+
|
151
|
+
error_messages = []
|
152
|
+
|
153
|
+
provider_classes.each do |klass|
|
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
|
+
}
|
162
|
+
|
163
|
+
rescue *EXCEPTIONS, OmniExchange::XeMonthlyLimit, JSON::ParserError => e
|
164
|
+
error_messages << e.inspect
|
165
|
+
end
|
166
|
+
|
167
|
+
raise OmniExchange::HttpError, "Failed to get historic rate:\n" \
|
168
|
+
"#{error_messages.join("\n")}"
|
169
|
+
end
|
101
170
|
end
|
102
171
|
# rubocop:enable Lint/Syntax
|
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
|