omni_exchange 1.8.0 → 2.0.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 +11 -29
- data/lib/omni_exchange/providers/open_exchange_rates.rb +2 -8
- data/lib/omni_exchange/providers/xe.rb +3 -7
- data/lib/omni_exchange/version.rb +1 -1
- data/lib/omni_exchange.rb +15 -5
- data/omni_exchange.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ae87cd7a839738c4e8a91ff800a1c0f5867c74540b90bdc69d2d7e1091cae8c
|
4
|
+
data.tar.gz: 84c043b737c6e7ad350dbedc02b4398059526f3ab39d282ee9d4f3cc07363653
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb39b4b6f07e8c7539055aa08e073b8a96c768537950b0c23053c03d978167f5c31d1ee3220125d41ca507d79a8956de7066f96041096d8d69f161a6a86a0fa4
|
7
|
+
data.tar.gz: f4b145799b92ba721a559db9623e188a9957877b87bffe6e7a899f3bb57469273882790627ad9e74b6fe8c3f42efbc6f34cfdc8f39fbabce161a2cb9a99843e5
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
omni_exchange (
|
5
|
-
faraday (
|
4
|
+
omni_exchange (2.0.0)
|
5
|
+
faraday (~> 2)
|
6
6
|
money (~> 6.13.1)
|
7
7
|
|
8
8
|
GEM
|
@@ -10,38 +10,20 @@ 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.3)
|
14
14
|
diff-lcs (1.5.0)
|
15
15
|
dotenv (2.8.1)
|
16
|
-
faraday (
|
17
|
-
faraday-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
faraday-multipart (~> 1.0)
|
22
|
-
faraday-net_http (~> 1.0)
|
23
|
-
faraday-net_http_persistent (~> 1.0)
|
24
|
-
faraday-patron (~> 1.0)
|
25
|
-
faraday-rack (~> 1.0)
|
26
|
-
faraday-retry (~> 1.0)
|
27
|
-
ruby2_keywords (>= 0.0.4)
|
28
|
-
faraday-em_http (1.0.0)
|
29
|
-
faraday-em_synchrony (1.0.0)
|
30
|
-
faraday-excon (1.1.0)
|
31
|
-
faraday-httpclient (1.0.1)
|
32
|
-
faraday-multipart (1.0.4)
|
33
|
-
multipart-post (~> 2)
|
34
|
-
faraday-net_http (1.0.1)
|
35
|
-
faraday-net_http_persistent (1.2.0)
|
36
|
-
faraday-patron (1.0.0)
|
37
|
-
faraday-rack (1.0.0)
|
38
|
-
faraday-retry (1.0.3)
|
39
|
-
i18n (1.12.0)
|
16
|
+
faraday (2.9.0)
|
17
|
+
faraday-net_http (>= 2.0, < 3.2)
|
18
|
+
faraday-net_http (3.1.0)
|
19
|
+
net-http
|
20
|
+
i18n (1.14.4)
|
40
21
|
concurrent-ruby (~> 1.0)
|
41
22
|
method_source (1.0.0)
|
42
23
|
money (6.13.8)
|
43
24
|
i18n (>= 0.6.4, <= 2)
|
44
|
-
|
25
|
+
net-http (0.4.1)
|
26
|
+
uri
|
45
27
|
parallel (1.22.1)
|
46
28
|
parser (3.1.2.1)
|
47
29
|
ast (~> 2.4.1)
|
@@ -77,8 +59,8 @@ GEM
|
|
77
59
|
rubocop-ast (1.21.0)
|
78
60
|
parser (>= 3.1.1.0)
|
79
61
|
ruby-progressbar (1.11.0)
|
80
|
-
ruby2_keywords (0.0.5)
|
81
62
|
unicode-display_width (1.8.0)
|
63
|
+
uri (0.13.0)
|
82
64
|
vcr (6.1.0)
|
83
65
|
|
84
66
|
PLATFORMS
|
@@ -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
|
|
@@ -81,7 +77,7 @@ module OmniExchange
|
|
81
77
|
api_key = config[:api_key]
|
82
78
|
|
83
79
|
Faraday.new(OmniExchange::Xe::ENDPOINT_URL) do |f|
|
84
|
-
f.
|
80
|
+
f.set_basic_auth api_id, api_key
|
85
81
|
f.adapter :net_http
|
86
82
|
end
|
87
83
|
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
|
-
|
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
|
data/omni_exchange.gemspec
CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
28
28
|
spec.require_paths = ['lib']
|
29
29
|
|
30
|
-
spec.add_dependency 'faraday', '
|
30
|
+
spec.add_dependency 'faraday', '~> 2'
|
31
31
|
spec.add_dependency 'money', '~> 6.13.1'
|
32
32
|
|
33
33
|
spec.add_development_dependency 'dotenv'
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omni_exchange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.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:
|
11
|
+
date: 2024-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2'
|
27
27
|
- !ruby/object:Gem::Dependency
|