omni_exchange 1.3.0 → 1.6.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: e498fc09556edce13c2f54ef7de9451e38546eaae859a38b2c0378d9011d8c2b
4
- data.tar.gz: 8ef08385d9b929689e825ed4ac9b1f19756105e0f4d393279fe8e7482d85a281
3
+ metadata.gz: bf795bf43c3ede8973124f10ff3afa6190a4c6af4705ecc481bf2a1112477f33
4
+ data.tar.gz: 4b8fc48b43b3cbcb9e118d8e1ee5238c71c9ddfceca7aa1cf1034a78fa693691
5
5
  SHA512:
6
- metadata.gz: a2dd2e4413a7c0f061d70f605d55395d924e48341a6f44b292c997ce58b6264d090d90d605fc4304e5afd36981797c4c49965684154c3a7b8b9719d4cb89dcc5
7
- data.tar.gz: '048bb4224fd6c1b61d6ef89daa5eb2a38fc3527b9428c892e11786bf621205be39795b7876cf5b1832faa2811b733a5fca0dc45a01e77f2240bbe7fd914adf8b'
6
+ metadata.gz: a42a179b5435a78d4aacd65c04e4c26223c1115c53b3160963ace5c8175dce8252a1ae7fc2272e758d16c0264c99294ac3a84763f0fa1f4cf5a51d08746327c3
7
+ data.tar.gz: 58186c5c5697ef71566e41ad717b4c76362e2650edc1bd72da11ff0964bc76e7e5936f656969b58e37f69f6f34e640c1f09cba2041eeeb25a73ad27fae037ef3
data/.gitignore CHANGED
@@ -14,9 +14,4 @@
14
14
  .env
15
15
 
16
16
  sandbox.rb
17
- omni_exchange-0.1.0.gem
18
- omni_exchange-0.2.0.gem
19
- omni_exchange-1.1.0.gem
20
- omni_exchange-1.1.1.gem
21
- omni_exchange-1.2.0.gem
22
- omni_exchange-1.3.0.gem
17
+ *.gem
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- omni_exchange (1.3.0)
5
- faraday (= 0.17.4)
4
+ omni_exchange (1.6.0)
5
+ faraday (< 2)
6
6
  money (~> 6.13.1)
7
7
 
8
8
  GEM
@@ -12,17 +12,38 @@ GEM
12
12
  coderay (1.1.3)
13
13
  concurrent-ruby (1.1.10)
14
14
  diff-lcs (1.5.0)
15
- dotenv (2.7.6)
16
- faraday (0.17.4)
17
- multipart-post (>= 1.2, < 3)
18
- i18n (1.10.0)
15
+ dotenv (2.8.1)
16
+ faraday (1.10.2)
17
+ faraday-em_http (~> 1.0)
18
+ faraday-em_synchrony (~> 1.0)
19
+ faraday-excon (~> 1.1)
20
+ faraday-httpclient (~> 1.0)
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)
19
40
  concurrent-ruby (~> 1.0)
20
41
  method_source (1.0.0)
21
42
  money (6.13.8)
22
43
  i18n (>= 0.6.4, <= 2)
23
44
  multipart-post (2.2.3)
24
45
  parallel (1.22.1)
25
- parser (3.1.2.0)
46
+ parser (3.1.2.1)
26
47
  ast (~> 2.4.1)
27
48
  pry (0.14.1)
28
49
  coderay (~> 1.1)
@@ -53,14 +74,16 @@ GEM
53
74
  rubocop-ast (>= 0.6.0)
54
75
  ruby-progressbar (~> 1.7)
55
76
  unicode-display_width (>= 1.4.0, < 2.0)
56
- rubocop-ast (1.18.0)
77
+ rubocop-ast (1.21.0)
57
78
  parser (>= 3.1.1.0)
58
79
  ruby-progressbar (1.11.0)
80
+ ruby2_keywords (0.0.5)
59
81
  unicode-display_width (1.8.0)
60
82
  vcr (6.1.0)
61
83
 
62
84
  PLATFORMS
63
85
  ruby
86
+ x86_64-darwin-19
64
87
 
65
88
  DEPENDENCIES
66
89
  dotenv
data/README.md CHANGED
@@ -57,7 +57,8 @@ To convert currency and/or get an exchange rate, all you have to do is call `Omn
57
57
  What you get back is a hash containing:
58
58
  1. converted_amount: (BigDecimal) the amount of money exchanged from the base currency to the target currency
59
59
  2. exchange_rate: (BigDecimal) the rate used to calculate the converted_amount
60
- 3. provider: (Symbol) the provider that supplied the exchange_rate (ie. :open_exchange_rates, :xe)
60
+ 3. non_subunit_fx_rate: (BigDecimal) an exchange rate that can be used to convert a formatted version of the base currency (ie. 100 USD being formatted as 1.00)
61
+ 4. provider: (Symbol) the provider that supplied the exchange_rate (ie. :open_exchange_rates, :xe)
61
62
 
62
63
  [For the sake of precise calculation](https://www.bigbinary.com/blog/handling-money-in-ruby), converted_amount and exchange_rate are BigDecimal. Simply call `.to_f` to the results if you'd like to see a number that is easier to read.
63
64
 
@@ -67,7 +68,7 @@ Here is an example. Lets say I want to convert $1.00 US Dollar to Japanese Yen,
67
68
  ```ruby
68
69
  USD_to_JPY = OmniExchange.get_fx_data(amount: 100, base_currency: 'USD', target_currency: 'JPY', providers: [:open_exchange_rates, :xe])
69
70
 
70
- puts USD_to_JPY # => { :converted_amount=>0.13566633333e3, :exchange_rate=>0.13566633333e1, :provider=>:open_exchange_rates }
71
+ puts USD_to_JPY # => { :converted_amount=>0.13566633333e3, :exchange_rate=>0.13566633333e1, :non_subunit_fx_rate=>0.13566633333e3, :provider=>:open_exchange_rates }
71
72
 
72
73
  puts USD_to_JPY[:converted_amount] # => 0.13566633333e3
73
74
  puts USD_to_JPY[:converted_amount].to_f # => 135.66633333
@@ -75,6 +76,10 @@ puts USD_to_JPY[:converted_amount].to_f # => 135.66633333
75
76
  puts USD_to_JPY[:exchange_rate] # => 0.13566633333e1
76
77
  puts USD_to_JPY[:exchange_rate].to_f # => 1.3566633333
77
78
 
79
+ # :fx_rate can be used when 100 USD is written as 1.00 instead of 100. In other words, you can do 1.00 * USD_to_JPY[:non_subunit_fx_rate] and get 135.66633333
80
+ puts USD_to_JPY[:non_subunit_fx_rate] # => 0.13566633333e3
81
+ puts USD_to_JPY[:non_subunit_fx_rate].to_f # => 135.66633333
82
+
78
83
  ```
79
84
 
80
85
  ## Development
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniExchange
4
- VERSION = '1.3.0'
4
+ VERSION = '1.6.0'
5
5
  end
data/lib/omni_exchange.rb CHANGED
@@ -34,7 +34,7 @@ module OmniExchange
34
34
  end
35
35
 
36
36
  # if a provider raises one of these exceptions, OmniExchange will gracefully attempt to use another provider
37
- EXCEPTIONS = [Faraday::Error, Faraday::ConnectionFailed, Faraday::TimeoutError, Net::OpenTimeout, Net::WriteTimeout, Net::ReadTimeout, OpenSSL::SSL::SSLError]
37
+ EXCEPTIONS = [Faraday::Error, Faraday::ConnectionFailed, Faraday::TimeoutError, Faraday::SSLError, Net::OpenTimeout, Net::WriteTimeout, Net::ReadTimeout, OpenSSL::SSL::SSLError]
38
38
 
39
39
  module_function
40
40
 
@@ -53,6 +53,7 @@ module OmniExchange
53
53
  # * :converted_amount [BigDecimal] the amount of money exchanged from the base currency to the target
54
54
  # currency as a BigDecimal for precice calculation. ie. 1, 10, 100
55
55
  # * :exchange_rate [BigDecimal] the rate used to calculate the converted_amount as a BigDecimal. ie. 0.95211e1
56
+ # * :non_subunit_fx_rate [BigDecimal] a rate that can be used when a currency with subunits is not in cents . ie. 0.95211e3
56
57
  # * :provider [Symbol] the provider that supplied the exchange_rate data. ie. :xe, :open_exchange_rates
57
58
  def get_fx_data(amount:, base_currency:, target_currency:, providers:)
58
59
  # if one of the currencies is not valid (ie. 'fake_crypto'), an exception is raised.
@@ -71,10 +72,11 @@ module OmniExchange
71
72
  # Gracefully hit each provider and fail-over to the next one
72
73
  provider_classes.each do |klass|
73
74
  rate = klass.get_exchange_rate(base_currency: base_currency, target_currency: target_currency)
75
+ plain_format_rate = (rate * Money::Currency.wrap(base_currency).subunit_to_unit).to_d
74
76
 
75
77
  exchanged_amount = rate.to_d * amount.to_d
76
78
 
77
- return { converted_amount: exchanged_amount, exchange_rate: rate, provider: OmniExchange::Provider.all.key(klass) }
79
+ return { converted_amount: exchanged_amount, exchange_rate: rate, non_subunit_fx_rate: plain_format_rate, provider: OmniExchange::Provider.all.key(klass) }
78
80
  rescue *EXCEPTIONS, OmniExchange::XeMonthlyLimit, JSON::ParserError => e
79
81
  error_messages << e.inspect
80
82
  end
@@ -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', '0.17.4'
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,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omni_exchange
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.6.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-07-12 00:00:00.000000000 Z
11
+ date: 2022-08-31 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: 0.17.4
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
- version: 0.17.4
26
+ version: '2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: money
29
29
  requirement: !ruby/object:Gem::Requirement