omni_exchange 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +12 -4
- data/Gemfile.lock +5 -7
- data/README.md +5 -3
- data/lib/omni_exchange/providers/open_exchange_rates.rb +3 -4
- data/lib/omni_exchange/providers/xe.rb +4 -4
- data/lib/omni_exchange/version.rb +1 -1
- data/lib/omni_exchange.rb +36 -6
- data/omni_exchange.gemspec +6 -6
- metadata +13 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f688c61226d02342f3c6e2730982b059d46cf6033fa61f822477d332bf21fc6b
|
4
|
+
data.tar.gz: 19d3020b4d6146634d6931e8ac72247e5d17072156bca230a75307c398b26c4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44b9222aa670f9495d713b62b3a01115388c68e820cd24d699beab5b8df9a80a084a3f3613f9edac17c2e0e4e5fa642cd0bab6b466b87b56e25ee8b6ae88387e
|
7
|
+
data.tar.gz: 704c9d03570dec02e8115bf224a354e1bcea4a85574167b826cbb33b9d7dccce7c88c404d18d76d58291b4c74709624f6cd888353e05ca0b12e86c2dac6709b6
|
data/.rubocop_todo.yml
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2022-06-
|
3
|
+
# on 2022-06-24 08:14:59 UTC using RuboCop version 0.93.1.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
@@ -9,7 +9,7 @@
|
|
9
9
|
# Offense count: 2
|
10
10
|
# Configuration parameters: IgnoredMethods.
|
11
11
|
Metrics/AbcSize:
|
12
|
-
Max:
|
12
|
+
Max: 28
|
13
13
|
|
14
14
|
# Offense count: 1
|
15
15
|
# Configuration parameters: CountComments, CountAsOne, ExcludedMethods.
|
@@ -32,14 +32,22 @@ Style/Documentation:
|
|
32
32
|
- 'lib/omni_exchange/providers/open_exchange_rates.rb'
|
33
33
|
- 'lib/omni_exchange/providers/xe.rb'
|
34
34
|
|
35
|
-
# Offense count:
|
35
|
+
# Offense count: 2
|
36
36
|
# Configuration parameters: EnforcedStyle.
|
37
37
|
# SupportedStyles: scientific, engineering, integral
|
38
38
|
Style/ExponentialNotation:
|
39
39
|
Exclude:
|
40
40
|
- 'spec/omni_exchange_spec.rb'
|
41
41
|
|
42
|
-
# Offense count:
|
42
|
+
# Offense count: 3
|
43
|
+
# Cop supports --auto-correct.
|
44
|
+
# Configuration parameters: EnforcedStyle, ConsistentQuotesInMultiline.
|
45
|
+
# SupportedStyles: single_quotes, double_quotes
|
46
|
+
Style/StringLiterals:
|
47
|
+
Exclude:
|
48
|
+
- 'lib/sandbox.rb'
|
49
|
+
|
50
|
+
# Offense count: 16
|
43
51
|
# Cop supports --auto-correct.
|
44
52
|
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
45
53
|
# URISchemes: http, https
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
omni_exchange (0.
|
5
|
-
faraday
|
4
|
+
omni_exchange (0.2.0)
|
5
|
+
faraday (= 0.17.4)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -11,11 +11,10 @@ GEM
|
|
11
11
|
coderay (1.1.3)
|
12
12
|
diff-lcs (1.5.0)
|
13
13
|
dotenv (2.7.6)
|
14
|
-
faraday (
|
15
|
-
|
16
|
-
ruby2_keywords (>= 0.0.4)
|
17
|
-
faraday-net_http (2.0.3)
|
14
|
+
faraday (0.17.4)
|
15
|
+
multipart-post (>= 1.2, < 3)
|
18
16
|
method_source (1.0.0)
|
17
|
+
multipart-post (2.2.3)
|
19
18
|
parallel (1.22.1)
|
20
19
|
parser (3.1.2.0)
|
21
20
|
ast (~> 2.4.1)
|
@@ -51,7 +50,6 @@ GEM
|
|
51
50
|
rubocop-ast (1.18.0)
|
52
51
|
parser (>= 3.1.1.0)
|
53
52
|
ruby-progressbar (1.11.0)
|
54
|
-
ruby2_keywords (0.0.5)
|
55
53
|
unicode-display_width (1.8.0)
|
56
54
|
vcr (6.1.0)
|
57
55
|
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# OmniExchange
|
2
2
|
|
3
|
-
OmniExchange converts currencies using up-to-the-minute foreign exchange rates
|
3
|
+
OmniExchange converts currencies using up-to-the-minute foreign exchange rates.
|
4
|
+
|
5
|
+
OmniExchange also supports fail-over logic and handles timeouts. In other words, if currency conversion isn't possible because an API data source cannot provide an exchange rate, OR if that data source times out, OmniExchange will retrieve exchange rate data from another API data source.
|
4
6
|
|
5
7
|
## Installation
|
6
8
|
|
@@ -73,7 +75,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
73
75
|
|
74
76
|
## Contributing
|
75
77
|
|
76
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
78
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/degica/omni_exchange. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/degica/omni_exchange/blob/master/CODE_OF_CONDUCT.md).
|
77
79
|
|
78
80
|
## License
|
79
81
|
|
@@ -81,4 +83,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
81
83
|
|
82
84
|
## Code of Conduct
|
83
85
|
|
84
|
-
Everyone interacting in the OmniExchange project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
86
|
+
Everyone interacting in the OmniExchange project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/degica/omni_exchange/blob/master/CODE_OF_CONDUCT.md).
|
@@ -19,9 +19,7 @@ module OmniExchange
|
|
19
19
|
config = OmniExchange.configuration.provider_config[:open_exchange_rates]
|
20
20
|
app_id = config[:app_id]
|
21
21
|
|
22
|
-
api = Faraday.new(ENDPOINT_URL)
|
23
|
-
conn.response :json, parser_options: { symbolize_names: true }
|
24
|
-
end
|
22
|
+
api = Faraday.new(OmniExchange::OpenExchangeRates::ENDPOINT_URL)
|
25
23
|
|
26
24
|
begin
|
27
25
|
response = api.get do |req|
|
@@ -32,7 +30,8 @@ module OmniExchange
|
|
32
30
|
rescue Faraday::Error, Faraday::ConnectionFailed => e
|
33
31
|
raise e.class, 'Open Exchange Rates has timed out.'
|
34
32
|
end
|
35
|
-
|
33
|
+
|
34
|
+
exchange_rate = JSON.parse(response.body, symbolize_names: true)[:rates][target_currency.to_sym].to_d
|
36
35
|
|
37
36
|
currency_unit = get_currency_unit(base_currency)
|
38
37
|
|
@@ -21,9 +21,9 @@ module OmniExchange
|
|
21
21
|
api_key = config[:api_key]
|
22
22
|
currency_unit = get_currency_unit(base_currency)
|
23
23
|
|
24
|
-
api = Faraday.new(ENDPOINT_URL) do |
|
25
|
-
|
26
|
-
|
24
|
+
api = Faraday.new(OmniExchange::Xe::ENDPOINT_URL) do |f|
|
25
|
+
f.request :basic_auth, api_id, api_key
|
26
|
+
f.adapter :net_http
|
27
27
|
end
|
28
28
|
|
29
29
|
begin
|
@@ -36,7 +36,7 @@ module OmniExchange
|
|
36
36
|
raise e.class, 'xe.com has timed out.'
|
37
37
|
end
|
38
38
|
|
39
|
-
response.body[:to][0][:mid].to_d
|
39
|
+
JSON.parse(response.body, symbolize_names: true)[:to][0][:mid].to_d
|
40
40
|
end
|
41
41
|
|
42
42
|
# when this file is required at the top of lib/omni_exchange.rb, this method call is run and allows
|
data/lib/omni_exchange.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
#
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
require 'omni_exchange/provider'
|
4
|
+
# in order to make sure that all API data providers are registered correctly,
|
5
|
+
# all of the provider files in the providers folder must be required
|
6
|
+
require 'omni_exchange/providers/open_exchange_rates'
|
7
|
+
require 'omni_exchange/providers/xe'
|
8
8
|
require 'omni_exchange/version'
|
9
9
|
require 'omni_exchange/configuration'
|
10
10
|
require 'faraday'
|
@@ -54,7 +54,7 @@ module OmniExchange
|
|
54
54
|
# Gracefully hit each provider and fail-over to the next one
|
55
55
|
provider_classes.each do |klass|
|
56
56
|
rate = klass.get_exchange_rate(base_currency: base_currency, target_currency: target_currency)
|
57
|
-
|
57
|
+
|
58
58
|
return rate * amount.to_d
|
59
59
|
rescue Faraday::Error, Faraday::ConnectionFailed => e
|
60
60
|
error_messages << e.inspect
|
@@ -62,5 +62,35 @@ module OmniExchange
|
|
62
62
|
|
63
63
|
raise "Failed to load #{base_currency}->#{target_currency}:\n#{exception_messages.join("\n")}"
|
64
64
|
end
|
65
|
+
|
66
|
+
# This method returns the exchange rate, the rate at which the smallest unit of one currency (the base currency)
|
67
|
+
# will be exchanged for another currency (the target currency), from API providers
|
68
|
+
#
|
69
|
+
# @param base_currency: [String] the ISO Currency Code of the currency that you're exchanging from. ie. "USD", "JPY"
|
70
|
+
# @param target_currency: [String] the ISO Currency Code of the currency that you're exchanging to. ie. "EUR", "KRW"
|
71
|
+
# @param providers: [Array] an array of symbols of the providers that will be used to get exchange rates API
|
72
|
+
# data. The symbols must be found in the @providers hash in the Provider class (lib/omni_exchange/provider.rb).
|
73
|
+
# ie. xe:, :open_exchange_rates
|
74
|
+
# @return [BigDecimal] the amount of the base currency exchanged to the target currency using an exchange rate
|
75
|
+
# provided by one of the data providers in the providers hash. The final amount is returned as a BigDecimal
|
76
|
+
# for precise calculation. If all of the providers in the providers hash fail to retrieve data,
|
77
|
+
# an exception is raised.
|
78
|
+
def get_exchange_rate(base_currency:, target_currency:, providers:)
|
79
|
+
error_messages = []
|
80
|
+
|
81
|
+
# Make sure all providers passed exist. If not, a LoadError is raise and not rescued
|
82
|
+
provider_classes = providers.map { |p| OmniExchange::Provider.load_provider(p) }
|
83
|
+
|
84
|
+
# Gracefully hit each provider and fail-over to the next one
|
85
|
+
provider_classes.each do |klass|
|
86
|
+
rate = klass.get_exchange_rate(base_currency: base_currency, target_currency: target_currency)
|
87
|
+
|
88
|
+
return rate
|
89
|
+
rescue Faraday::Error, Faraday::ConnectionFailed => e
|
90
|
+
error_messages << e.inspect
|
91
|
+
end
|
92
|
+
|
93
|
+
raise "Failed to load #{base_currency}->#{target_currency}:\n#{exception_messages.join("\n")}"
|
94
|
+
end
|
65
95
|
end
|
66
96
|
# rubocop:enable Lint/Syntax
|
data/omni_exchange.gemspec
CHANGED
@@ -8,17 +8,17 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ['Yun Chung']
|
9
9
|
spec.email = ['yunseok_chung@degica.com']
|
10
10
|
|
11
|
-
spec.summary = '
|
12
|
-
spec.description = '
|
11
|
+
spec.summary = 'OmniExchange converts currencies using up-to-the-minute foreign exchange rates.'
|
12
|
+
spec.description = 'OmniExchange converts currencies using up-to-the-minute foreign exchange rates.'
|
13
13
|
spec.homepage = 'https://degica.com'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
16
16
|
|
17
17
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
18
18
|
|
19
|
-
spec.metadata['homepage_uri'] =
|
20
|
-
spec.metadata['source_code_uri'] = 'https://
|
21
|
-
spec.metadata['changelog_uri'] = 'https://
|
19
|
+
spec.metadata['homepage_uri'] = 'https://degica.com'
|
20
|
+
spec.metadata['source_code_uri'] = 'https://github.com/degica/omni_exchange'
|
21
|
+
spec.metadata['changelog_uri'] = 'https://github.com/degica/omni_exchange'
|
22
22
|
|
23
23
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
24
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
@@ -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', '0.17.4'
|
31
31
|
|
32
32
|
spec.add_development_dependency 'dotenv'
|
33
33
|
spec.add_development_dependency 'pry'
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omni_exchange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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: 2022-06-
|
11
|
+
date: 2022-06-27 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
|
-
version:
|
19
|
+
version: 0.17.4
|
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
|
-
version:
|
26
|
+
version: 0.17.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: dotenv
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,7 +108,8 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
description:
|
111
|
+
description: OmniExchange converts currencies using up-to-the-minute foreign exchange
|
112
|
+
rates.
|
112
113
|
email:
|
113
114
|
- yunseok_chung@degica.com
|
114
115
|
executables: []
|
@@ -143,8 +144,8 @@ licenses:
|
|
143
144
|
metadata:
|
144
145
|
allowed_push_host: https://rubygems.org
|
145
146
|
homepage_uri: https://degica.com
|
146
|
-
source_code_uri: https://
|
147
|
-
changelog_uri: https://
|
147
|
+
source_code_uri: https://github.com/degica/omni_exchange
|
148
|
+
changelog_uri: https://github.com/degica/omni_exchange
|
148
149
|
post_install_message:
|
149
150
|
rdoc_options: []
|
150
151
|
require_paths:
|
@@ -160,8 +161,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
161
|
- !ruby/object:Gem::Version
|
161
162
|
version: '0'
|
162
163
|
requirements: []
|
163
|
-
rubygems_version: 3.
|
164
|
+
rubygems_version: 3.2.3
|
164
165
|
signing_key:
|
165
166
|
specification_version: 4
|
166
|
-
summary:
|
167
|
+
summary: OmniExchange converts currencies using up-to-the-minute foreign exchange
|
168
|
+
rates.
|
167
169
|
test_files: []
|