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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c10147e9b33c5288fe9d59249c2d51ff23e5fbf2be87f352fa59e6244b2949f8
4
- data.tar.gz: beff303239c412ff7e4d2691319be4fce1cf7c1424d2589397900f5c45184c21
3
+ metadata.gz: 2b8b209ec25ddad7e22d1aecc9c8073e6e41ac9e6121e29fcb15c1a240a86a80
4
+ data.tar.gz: d31a7913b18dd4636d449e86f7bb059c2196026e360b2dbdc20e6376e91a96ae
5
5
  SHA512:
6
- metadata.gz: cdb12eb02901081566e65046c780f02eea5691689b9d4fd7fa646f6acee57686d2eab1138a0c289ae893930076ba099235ed46fb3e1a95ca64815122502c8ee5
7
- data.tar.gz: c049ff4bc1946d7c87018f308beb7cffca268bae4601c3796447c22acef34118e5e50cb5aa004b012e690e15714c0b10342b0226bafb6c6a3a51d53266dd2365
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.8.0)
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.1.10)
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.12.0)
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
- exchange_rate = body['rates'][target_currency].to_d
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
- currency_unit = get_currency_unit(base_currency).to_d
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'] = currency_unit
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'] = currency_unit
44
+ req.params['amount'] = 1
49
45
  req.params['date'] = date.strftime('%Y-%m-%d')
50
46
  end
51
47
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniExchange
4
- VERSION = '1.8.0'
4
+ VERSION = '1.9.0'
5
5
  end
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
- return klass.get_exchange_rate(base_currency: base_currency,
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 historic rate:\n" \
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
- return klass.get_historic_rate(base_currency: base_currency,
150
- target_currencies: target_currencies,
151
- date: date)
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.8.0
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-06-27 00:00:00.000000000 Z
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.2.33
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