omni_exchange 1.7.0 → 1.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9e96486f0fec5e014b79827ca801fc70c717ad3f3c36a333fc2d1248ea7b3f6
4
- data.tar.gz: f52a460e18ad19a5cfeefe507dbce77563faf8e81ad5c2b23701fa7fec058190
3
+ metadata.gz: c10147e9b33c5288fe9d59249c2d51ff23e5fbf2be87f352fa59e6244b2949f8
4
+ data.tar.gz: beff303239c412ff7e4d2691319be4fce1cf7c1424d2589397900f5c45184c21
5
5
  SHA512:
6
- metadata.gz: e948110df897320119664e7dadd069a9b32a74c9f683f21d9af48c4166eda64dfd6494fee2719c11c670088b91276de8f8659e7248aa324297219981ae18865f
7
- data.tar.gz: 218e427ae203f24f0eeb4e74235b63fadaf47638061d6735f52d854b9413d5bfbcb08d5e541365cfcdeb9e4dfc481b2aedba145f6bfcf1f69b4a880a0e1451e9
6
+ metadata.gz: cdb12eb02901081566e65046c780f02eea5691689b9d4fd7fa646f6acee57686d2eab1138a0c289ae893930076ba099235ed46fb3e1a95ca64815122502c8ee5
7
+ data.tar.gz: c049ff4bc1946d7c87018f308beb7cffca268bae4601c3796447c22acef34118e5e50cb5aa004b012e690e15714c0b10342b0226bafb6c6a3a51d53266dd2365
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- omni_exchange (1.7.0)
4
+ omni_exchange (1.8.0)
5
5
  faraday (< 2)
6
6
  money (~> 6.13.1)
7
7
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniExchange
4
- VERSION = '1.7.0'
4
+ VERSION = '1.8.0'
5
5
  end
data/lib/omni_exchange.rb CHANGED
@@ -98,5 +98,64 @@ 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
+ return klass.get_exchange_rate(base_currency: base_currency,
120
+ target_currency: target_currency)
121
+
122
+ rescue *EXCEPTIONS, OmniExchange::XeMonthlyLimit, JSON::ParserError => e
123
+ error_messages << e.inspect
124
+ end
125
+
126
+ raise OmniExchange::HttpError, "Failed to get historic rate:\n" \
127
+ "#{error_messages.join("\n")}"
128
+ end
129
+
130
+ # returns the historic exchange rate from the base currency to the target currency at a certain date.
131
+ #
132
+ # @param base_currency: [String] the ISO Currency Code of the currency that you're exchanging from.
133
+ # ie. "USD", "JPY"
134
+ # @param target_currency: [String] the ISO Currency Code of the currency that you're exchanging to.
135
+ # ie. "EUR", "KRW"
136
+ # @param date: [Date] the specific date you want a historic exchange rate for.
137
+ # ie. Date.new(2018, 12, 25)
138
+ # @param providers: [Array] an array of symbols of the providers that will be used to get exchange rates API
139
+ # data. The symbols must be found in the @providers hash in the Provider class (lib/omni_exchange/provider.rb).
140
+ # ie. xe:, :open_exchange_rates
141
+ #
142
+ # @ return [Hash]: A hash containing the exchange rates.
143
+ def get_historic_rate(base_currency:, target_currencies:, date:, providers:)
144
+ provider_classes = providers.map { |p| OmniExchange::Provider.load_provider(p) }
145
+
146
+ error_messages = []
147
+
148
+ provider_classes.each do |klass|
149
+ return klass.get_historic_rate(base_currency: base_currency,
150
+ target_currencies: target_currencies,
151
+ date: date)
152
+
153
+ rescue *EXCEPTIONS, OmniExchange::XeMonthlyLimit, JSON::ParserError => e
154
+ error_messages << e.inspect
155
+ end
156
+
157
+ raise OmniExchange::HttpError, "Failed to get historic rate:\n" \
158
+ "#{error_messages.join("\n")}"
159
+ end
101
160
  end
102
161
  # 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.7.0
4
+ version: 1.8.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-09 00:00:00.000000000 Z
11
+ date: 2023-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday