currencyconversion 0.1.1 → 0.1.3

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
  SHA1:
3
- metadata.gz: 4b2d7f9ecefcbf39109cc55ee03f3c7576d8d779
4
- data.tar.gz: 60409d19ba7f1ebcfdfc73d6813db329d098827d
3
+ metadata.gz: c7da06db9b4adfa274c28d4e9a3111d32f8fff7e
4
+ data.tar.gz: e037e6b63c7b7500bfcd9bd5ead2879fc44120b7
5
5
  SHA512:
6
- metadata.gz: 205551930ad949e14ae0bb7e4f0a768903bc9aa4dd4ad918d24d99dfdc360af80099119c405f0ada7804534e1451e4a0c0cd53cead6a72bc2d663121a9fdaa49
7
- data.tar.gz: 38b836900d17f9528a1c6d1cc98ed55ed7caca3ed1188195488fde65e670931d4200fcae4dcb1813ceadc9c01853a2ac44a1fcb9a64421ea14b39f75936590b7
6
+ metadata.gz: 631387c053ed47dc9d698280908414102bd9cac64194ef380db9657978879a6b22a967db0742d5bfb41e125ed26653220e8f04a9a99868e14d7f12d4fd8483cc
7
+ data.tar.gz: 7278ed992900ec32dcf760446f27b4ccf0401986aebc87b36ad887562131e83ef620c3a3f4f8080b6a93db54dd1818186385d57f40d5a8766442cb4c026651a8
@@ -0,0 +1,27 @@
1
+ require 'dotenv'
2
+ require 'currency_conversion'
3
+ require 'currency_conversion/list/list_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
+ # We declare the options
14
+ options = CurrencyLayer::ListOptions.new()
15
+
16
+ # We make the call to fetch the list of currencies
17
+ response = @client.list(options)
18
+
19
+ # If its a success, we print a message to the user
20
+ if !response.nil?
21
+ puts 'SUCCESS : List of Currencies Fetched...' << response.to_s
22
+ end
23
+
24
+ rescue => e
25
+ puts e.inspect
26
+
27
+ end
@@ -0,0 +1,13 @@
1
+ module CurrencyLayer
2
+
3
+ class ListException < Exception
4
+
5
+ attr_accessor :error
6
+
7
+ def initialize(error)
8
+ self.error = error
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,15 @@
1
+ module CurrencyLayer
2
+
3
+ class ListOptions
4
+
5
+ include Hashable
6
+
7
+ attr_accessor :access_key
8
+
9
+ def initialize()
10
+ @query = nil
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,18 @@
1
+ require "hashable"
2
+
3
+ module CurrencyLayer
4
+
5
+ class ListRequest
6
+
7
+ include Hashable
8
+
9
+ attr_accessor :query
10
+
11
+ def initialize(query = {})
12
+
13
+ self.query = query
14
+
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ module CurrencyLayer
2
+
3
+ class ListResponse
4
+
5
+ SUCCESS_EXPR = 'success'
6
+ ERROR_EXPR = 'error'
7
+
8
+ def bar
9
+ SUCCESS_EXPR
10
+ ERROR_EXPR
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -1,3 +1,3 @@
1
1
  module CurrencyLayer
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -3,6 +3,8 @@ 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/list/list_request"
7
+ require "currency_conversion/list/list_response"
6
8
 
7
9
  module CurrencyLayer
8
10
 
@@ -64,5 +66,41 @@ module CurrencyLayer
64
66
  end
65
67
  end
66
68
 
69
+ def list(options = {})
70
+
71
+ # Create a shallow copy so we don't manipulate the original reference
72
+ q = options.dup
73
+
74
+ # Populate the Query
75
+ q.access_key = @access_key
76
+
77
+ # We then create the Request
78
+ req = CurrencyLayer::ListRequest.new(q)
79
+
80
+ # We create a Hash of the request so we can send it via HTTP
81
+ req_dto = req.to_dh
82
+
83
+ begin
84
+
85
+ # We make the actual request
86
+ res = self.class.get('/list', req_dto)
87
+
88
+ # We ensure that we tap the response so we can use the results
89
+ res.inspect
90
+
91
+ if (res[CurrencyLayer::ListResponse::ERROR_EXPR])
92
+ raise CurrencyLayer::ListException.new res[CurrencyLayer::ListResponse::ERROR_EXPR]
93
+ end
94
+
95
+ # We just return the parsed binary response
96
+ return res.parsed_response
97
+
98
+ rescue => e
99
+ puts e.inspect
100
+ return e
101
+
102
+ end
103
+ end
104
+
67
105
  end
68
106
  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.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Andreas Moelgaard
@@ -126,10 +126,15 @@ files:
126
126
  - bin/console
127
127
  - bin/setup
128
128
  - currency_conversion.gemspec
129
+ - example/example_list.rb
129
130
  - example/example_live.rb
130
131
  - example/example_live_w_currencies_as_array.rb
131
132
  - example/example_live_w_source.rb
132
133
  - lib/currency_conversion.rb
134
+ - lib/currency_conversion/list/list_exception.rb
135
+ - lib/currency_conversion/list/list_options.rb
136
+ - lib/currency_conversion/list/list_request.rb
137
+ - lib/currency_conversion/list/list_response.rb
133
138
  - lib/currency_conversion/live/live_exception.rb
134
139
  - lib/currency_conversion/live/live_options.rb
135
140
  - lib/currency_conversion/live/live_request.rb