currencyconversion 0.1.4 → 0.2.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 +4 -4
- data/example/example_change.rb +32 -0
- data/example/example_timeframe.rb +32 -0
- data/lib/currency_conversion.rb +218 -0
- data/lib/currency_conversion/change/change_exception.rb +13 -0
- data/lib/currency_conversion/change/change_options.rb +19 -0
- data/lib/currency_conversion/change/change_request.rb +18 -0
- data/lib/currency_conversion/change/change_response.rb +15 -0
- data/lib/currency_conversion/convert/convert_exception.rb +13 -0
- data/lib/currency_conversion/convert/convert_options.rb +19 -0
- data/lib/currency_conversion/convert/convert_request.rb +18 -0
- data/lib/currency_conversion/convert/convert_response.rb +15 -0
- data/lib/currency_conversion/historical/historical_exception.rb +13 -0
- data/lib/currency_conversion/historical/historical_options.rb +17 -0
- data/lib/currency_conversion/historical/historical_request.rb +18 -0
- data/lib/currency_conversion/historical/historical_response.rb +15 -0
- data/lib/currency_conversion/timeframe/timeframe_exception.rb +13 -0
- data/lib/currency_conversion/timeframe/timeframe_options.rb +19 -0
- data/lib/currency_conversion/timeframe/timeframe_request.rb +18 -0
- data/lib/currency_conversion/timeframe/timeframe_response.rb +15 -0
- data/lib/currency_conversion/version.rb +1 -1
- metadata +19 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f4d6706dc2b6be7510db89b46a566b1ad90ea384
|
4
|
+
data.tar.gz: 51abba7ca76ff4c5b98ba5482b38ff019acca66f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65e046b53545d6e75ad441f1670d4a6021689e7bf07be8d4ec005ce057bc0fe9ee4015ef365dcfa43c5f2a9ccbb0cc8a72a4f134b6b0b3b3887dd94cab4c5940
|
7
|
+
data.tar.gz: 9f556b29ae6e4745ecbca16a46589524f89c3a4e4ccbd40de2bb0bbb90bd9d2a78a34fbffcb2b04cb03727a197980cdeb978e120300bad098f8f4d8c95d67ec6
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'dotenv'
|
2
|
+
require 'currency_conversion'
|
3
|
+
require 'currency_conversion/timeframe/timeframe_options'
|
4
|
+
|
5
|
+
# Load Environment Variables
|
6
|
+
Dotenv.load
|
7
|
+
|
8
|
+
begin
|
9
|
+
|
10
|
+
# Declare the Client instance passing in the authentication parameters
|
11
|
+
@client = CurrencyLayer::Client.new(ENV['ACCESS_KEY'])
|
12
|
+
|
13
|
+
# Set the arguments
|
14
|
+
start_date = '2010-03-01'
|
15
|
+
end_date = '2010-04-01'
|
16
|
+
currencies = 'USD,GBP,EUR'
|
17
|
+
|
18
|
+
# We declare the options
|
19
|
+
options = CurrencyLayer::TimeframeOptions.new()
|
20
|
+
|
21
|
+
# We make the call to fetch the live currencies
|
22
|
+
response = @client.timeframe(start_date, end_date, currencies, options)
|
23
|
+
|
24
|
+
# If its a success, we print a message to the user
|
25
|
+
if !response.nil?
|
26
|
+
puts 'SUCCESS : Timeframe Fetched...' << response.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
rescue => e
|
30
|
+
puts e.inspect
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'dotenv'
|
2
|
+
require 'currency_conversion'
|
3
|
+
require 'currency_conversion/timeframe/timeframe_options'
|
4
|
+
|
5
|
+
# Load Environment Variables
|
6
|
+
Dotenv.load
|
7
|
+
|
8
|
+
begin
|
9
|
+
|
10
|
+
# Declare the Client instance passing in the authentication parameters
|
11
|
+
@client = CurrencyLayer::Client.new(ENV['ACCESS_KEY'])
|
12
|
+
|
13
|
+
# Set the arguments
|
14
|
+
start_date = '2010-03-01'
|
15
|
+
end_date = '2010-04-01'
|
16
|
+
currencies = 'USD,GBP,EUR'
|
17
|
+
|
18
|
+
# We declare the options
|
19
|
+
options = CurrencyLayer::TimeframeOptions.new()
|
20
|
+
|
21
|
+
# We make the call to fetch the live currencies
|
22
|
+
response = @client.timeframe(start_date, end_date, currencies, options)
|
23
|
+
|
24
|
+
# If its a success, we print a message to the user
|
25
|
+
if !response.nil?
|
26
|
+
puts 'SUCCESS : Timeframe Fetched...' << response.to_s
|
27
|
+
end
|
28
|
+
|
29
|
+
rescue => e
|
30
|
+
puts e.inspect
|
31
|
+
|
32
|
+
end
|
data/lib/currency_conversion.rb
CHANGED
@@ -3,8 +3,22 @@ require "hashable"
|
|
3
3
|
require "currency_conversion/version"
|
4
4
|
require "currency_conversion/live/live_request"
|
5
5
|
require "currency_conversion/live/live_response"
|
6
|
+
require "currency_conversion/live/live_exception"
|
6
7
|
require "currency_conversion/list/list_request"
|
7
8
|
require "currency_conversion/list/list_response"
|
9
|
+
require "currency_conversion/list/list_exception"
|
10
|
+
require "currency_conversion/historical/historical_request"
|
11
|
+
require "currency_conversion/historical/historical_response"
|
12
|
+
require "currency_conversion/historical/historical_exception"
|
13
|
+
require "currency_conversion/convert/convert_request"
|
14
|
+
require "currency_conversion/convert/convert_response"
|
15
|
+
require "currency_conversion/convert/convert_exception"
|
16
|
+
require "currency_conversion/timeframe/timeframe_request"
|
17
|
+
require "currency_conversion/timeframe/timeframe_response"
|
18
|
+
require "currency_conversion/timeframe/timeframe_exception"
|
19
|
+
require "currency_conversion/change/change_request"
|
20
|
+
require "currency_conversion/change/change_response"
|
21
|
+
require "currency_conversion/change/change_exception"
|
8
22
|
|
9
23
|
module CurrencyLayer
|
10
24
|
|
@@ -102,5 +116,209 @@ module CurrencyLayer
|
|
102
116
|
end
|
103
117
|
end
|
104
118
|
|
119
|
+
def historical(date, options = {})
|
120
|
+
|
121
|
+
if date.nil?
|
122
|
+
raise CurrencyLayer::MissingArgumentException.new 'date'
|
123
|
+
return
|
124
|
+
end
|
125
|
+
|
126
|
+
# Create a shallow copy so we don't manipulate the original reference
|
127
|
+
q = options.dup
|
128
|
+
|
129
|
+
# Populate the Query
|
130
|
+
q.access_key = @access_key
|
131
|
+
q.date = date
|
132
|
+
|
133
|
+
# We then create the Request
|
134
|
+
req = CurrencyLayer::HistoricalRequest.new(q)
|
135
|
+
|
136
|
+
# We create a Hash of the request so we can send it via HTTP
|
137
|
+
req_dto = req.to_dh
|
138
|
+
|
139
|
+
begin
|
140
|
+
|
141
|
+
# We make the actual request
|
142
|
+
res = self.class.get('/historical', req_dto)
|
143
|
+
|
144
|
+
# We ensure that we tap the response so we can use the results
|
145
|
+
res.inspect
|
146
|
+
|
147
|
+
if (res[CurrencyLayer::HistoricalResponse::ERROR_EXPR])
|
148
|
+
raise CurrencyLayer::HistoricalException.new res[CurrencyLayer::HistoricalResponse::ERROR_EXPR]
|
149
|
+
end
|
150
|
+
|
151
|
+
# We just return the parsed binary response
|
152
|
+
return res.parsed_response
|
153
|
+
|
154
|
+
rescue => e
|
155
|
+
puts e.inspect
|
156
|
+
return e
|
157
|
+
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
def convert(from, to, amount, options = {})
|
162
|
+
|
163
|
+
if from.nil?
|
164
|
+
raise CurrencyLayer::MissingArgumentException.new 'from'
|
165
|
+
return
|
166
|
+
end
|
167
|
+
|
168
|
+
if to.nil?
|
169
|
+
raise CurrencyLayer::MissingArgumentException.new 'to'
|
170
|
+
return
|
171
|
+
end
|
172
|
+
|
173
|
+
if amount.nil?
|
174
|
+
raise CurrencyLayer::MissingArgumentException.new 'amount'
|
175
|
+
return
|
176
|
+
end
|
177
|
+
|
178
|
+
# Create a shallow copy so we don't manipulate the original reference
|
179
|
+
q = options.dup
|
180
|
+
|
181
|
+
# Populate the Query
|
182
|
+
q.access_key = @access_key
|
183
|
+
q.from = from
|
184
|
+
q.to = to
|
185
|
+
q.amount = amount
|
186
|
+
|
187
|
+
# We then create the Request
|
188
|
+
req = CurrencyLayer::ConvertRequest.new(q)
|
189
|
+
|
190
|
+
# We create a Hash of the request so we can send it via HTTP
|
191
|
+
req_dto = req.to_dh
|
192
|
+
|
193
|
+
begin
|
194
|
+
|
195
|
+
# We make the actual request
|
196
|
+
res = self.class.get('/convert', req_dto)
|
197
|
+
|
198
|
+
# We ensure that we tap the response so we can use the results
|
199
|
+
res.inspect
|
200
|
+
|
201
|
+
if (res[CurrencyLayer::ConvertResponse::ERROR_EXPR])
|
202
|
+
raise CurrencyLayer::ConvertException.new res[CurrencyLayer::ConvertResponse::ERROR_EXPR]
|
203
|
+
end
|
204
|
+
|
205
|
+
# We just return the parsed binary response
|
206
|
+
return res.parsed_response
|
207
|
+
|
208
|
+
rescue => e
|
209
|
+
puts e.inspect
|
210
|
+
return e
|
211
|
+
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
def timeframe(start_date, end_date, currencies, options = {})
|
216
|
+
|
217
|
+
if start_date.nil?
|
218
|
+
raise CurrencyLayer::MissingArgumentException.new 'start_date'
|
219
|
+
return
|
220
|
+
end
|
221
|
+
|
222
|
+
if end_date.nil?
|
223
|
+
raise CurrencyLayer::MissingArgumentException.new 'end_date'
|
224
|
+
return
|
225
|
+
end
|
226
|
+
|
227
|
+
if currencies.nil?
|
228
|
+
raise CurrencyLayer::MissingArgumentException.new 'currencies'
|
229
|
+
return
|
230
|
+
end
|
231
|
+
|
232
|
+
# Create a shallow copy so we don't manipulate the original reference
|
233
|
+
q = options.dup
|
234
|
+
|
235
|
+
# Populate the Query
|
236
|
+
q.access_key = @access_key
|
237
|
+
q.start_date = start_date
|
238
|
+
q.end_date = end_date
|
239
|
+
q.currencies = currencies
|
240
|
+
|
241
|
+
# We then create the Request
|
242
|
+
req = CurrencyLayer::TimeframeRequest.new(q)
|
243
|
+
|
244
|
+
# We create a Hash of the request so we can send it via HTTP
|
245
|
+
req_dto = req.to_dh
|
246
|
+
|
247
|
+
begin
|
248
|
+
|
249
|
+
# We make the actual request
|
250
|
+
res = self.class.get('/timeframe', req_dto)
|
251
|
+
|
252
|
+
# We ensure that we tap the response so we can use the results
|
253
|
+
res.inspect
|
254
|
+
|
255
|
+
if (res[CurrencyLayer::TimeframeResponse::ERROR_EXPR])
|
256
|
+
raise CurrencyLayer::TimeframeException.new res[CurrencyLayer::TimeframeResponse::ERROR_EXPR]
|
257
|
+
end
|
258
|
+
|
259
|
+
# We just return the parsed binary response
|
260
|
+
return res.parsed_response
|
261
|
+
|
262
|
+
rescue => e
|
263
|
+
puts e.inspect
|
264
|
+
return e
|
265
|
+
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
def change(start_date, end_date, currencies, options = {})
|
270
|
+
|
271
|
+
if start_date.nil?
|
272
|
+
raise CurrencyLayer::MissingArgumentException.new 'start_date'
|
273
|
+
return
|
274
|
+
end
|
275
|
+
|
276
|
+
if end_date.nil?
|
277
|
+
raise CurrencyLayer::MissingArgumentException.new 'end_date'
|
278
|
+
return
|
279
|
+
end
|
280
|
+
|
281
|
+
if currencies.nil?
|
282
|
+
raise CurrencyLayer::MissingArgumentException.new 'currencies'
|
283
|
+
return
|
284
|
+
end
|
285
|
+
|
286
|
+
# Create a shallow copy so we don't manipulate the original reference
|
287
|
+
q = options.dup
|
288
|
+
|
289
|
+
# Populate the Query
|
290
|
+
q.access_key = @access_key
|
291
|
+
q.start_date = start_date
|
292
|
+
q.end_date = end_date
|
293
|
+
q.currencies = currencies
|
294
|
+
|
295
|
+
# We then create the Request
|
296
|
+
req = CurrencyLayer::ChangeRequest.new(q)
|
297
|
+
|
298
|
+
# We create a Hash of the request so we can send it via HTTP
|
299
|
+
req_dto = req.to_dh
|
300
|
+
|
301
|
+
begin
|
302
|
+
|
303
|
+
# We make the actual request
|
304
|
+
res = self.class.get('/change', req_dto)
|
305
|
+
|
306
|
+
# We ensure that we tap the response so we can use the results
|
307
|
+
res.inspect
|
308
|
+
|
309
|
+
if (res[CurrencyLayer::ChangeResponse::ERROR_EXPR])
|
310
|
+
raise CurrencyLayer::ChangeException.new res[CurrencyLayer::ChangeResponse::ERROR_EXPR]
|
311
|
+
end
|
312
|
+
|
313
|
+
# We just return the parsed binary response
|
314
|
+
return res.parsed_response
|
315
|
+
|
316
|
+
rescue => e
|
317
|
+
puts e.inspect
|
318
|
+
return e
|
319
|
+
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
105
323
|
end
|
106
324
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module CurrencyLayer
|
2
|
+
|
3
|
+
class ChangeOptions
|
4
|
+
|
5
|
+
include Hashable
|
6
|
+
|
7
|
+
attr_accessor :access_key
|
8
|
+
|
9
|
+
attr_accessor :start_date
|
10
|
+
attr_accessor :end_date
|
11
|
+
attr_accessor :currencies
|
12
|
+
|
13
|
+
def initialize()
|
14
|
+
@query = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module CurrencyLayer
|
2
|
+
|
3
|
+
class TimeframeOptions
|
4
|
+
|
5
|
+
include Hashable
|
6
|
+
|
7
|
+
attr_accessor :access_key
|
8
|
+
|
9
|
+
attr_accessor :start_date
|
10
|
+
attr_accessor :end_date
|
11
|
+
attr_accessor :currencies
|
12
|
+
|
13
|
+
def initialize()
|
14
|
+
@query = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: currencyconversion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Andreas Moelgaard
|
@@ -126,11 +126,25 @@ files:
|
|
126
126
|
- bin/console
|
127
127
|
- bin/setup
|
128
128
|
- currency_conversion.gemspec
|
129
|
+
- example/example_change.rb
|
129
130
|
- example/example_list.rb
|
130
131
|
- example/example_live.rb
|
131
132
|
- example/example_live_w_currencies_as_array.rb
|
132
133
|
- example/example_live_w_source.rb
|
134
|
+
- example/example_timeframe.rb
|
133
135
|
- lib/currency_conversion.rb
|
136
|
+
- lib/currency_conversion/change/change_exception.rb
|
137
|
+
- lib/currency_conversion/change/change_options.rb
|
138
|
+
- lib/currency_conversion/change/change_request.rb
|
139
|
+
- lib/currency_conversion/change/change_response.rb
|
140
|
+
- lib/currency_conversion/convert/convert_exception.rb
|
141
|
+
- lib/currency_conversion/convert/convert_options.rb
|
142
|
+
- lib/currency_conversion/convert/convert_request.rb
|
143
|
+
- lib/currency_conversion/convert/convert_response.rb
|
144
|
+
- lib/currency_conversion/historical/historical_exception.rb
|
145
|
+
- lib/currency_conversion/historical/historical_options.rb
|
146
|
+
- lib/currency_conversion/historical/historical_request.rb
|
147
|
+
- lib/currency_conversion/historical/historical_response.rb
|
134
148
|
- lib/currency_conversion/list/list_exception.rb
|
135
149
|
- lib/currency_conversion/list/list_options.rb
|
136
150
|
- lib/currency_conversion/list/list_request.rb
|
@@ -140,6 +154,10 @@ files:
|
|
140
154
|
- lib/currency_conversion/live/live_request.rb
|
141
155
|
- lib/currency_conversion/live/live_response.rb
|
142
156
|
- lib/currency_conversion/missing_argument_exception.rb
|
157
|
+
- lib/currency_conversion/timeframe/timeframe_exception.rb
|
158
|
+
- lib/currency_conversion/timeframe/timeframe_options.rb
|
159
|
+
- lib/currency_conversion/timeframe/timeframe_request.rb
|
160
|
+
- lib/currency_conversion/timeframe/timeframe_response.rb
|
143
161
|
- lib/currency_conversion/version.rb
|
144
162
|
homepage: https://github.com/pmoelgaard/currency_conversion
|
145
163
|
licenses:
|