currencyconversion 0.0.1 → 0.1.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/currency_conversion.gemspec +9 -2
- data/example/example_live.rb +30 -0
- data/example/example_live_w_currencies_as_array.rb +35 -0
- data/example/example_live_w_source.rb +34 -0
- data/lib/currency_conversion/live/live_exception.rb +13 -0
- data/lib/currency_conversion/live/live_options.rb +18 -0
- data/lib/currency_conversion/live/live_request.rb +21 -0
- data/lib/currency_conversion/live/live_response.rb +15 -0
- data/lib/currency_conversion/missing_argument_exception.rb +13 -0
- data/lib/currency_conversion/version.rb +1 -1
- data/lib/currency_conversion.rb +64 -1
- metadata +70 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1f1d4f491e70656b3d318aafb32206d79a20b52
|
4
|
+
data.tar.gz: 1505c844a7bf804c90a85faead45c9f51ed3c695
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17fd0b7b3a393485b6149d1c309310e45981388e77c03959bf5fde429302661de60994d3eab64e6d25033188eb18645799e619831437ef7ed6262f4ce37bdec4
|
7
|
+
data.tar.gz: b0577d35d7c3c6c743c732d1a2e5171129b5afc15024ddffcb1a3022c8977030947a431f8c3fb8af5d77c158fda0bd61ddc04e8cc4d90320fc0ab38d185ba211
|
data/currency_conversion.gemspec
CHANGED
@@ -12,8 +12,8 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.authors = ["Peter Andreas Moelgaard"]
|
13
13
|
spec.email = ["github@petermolgaard.com"]
|
14
14
|
|
15
|
-
spec.
|
16
|
-
spec.
|
15
|
+
spec.description = "Ruby Library for the currencylayer API, Reliable Exchange Rates & Currency Conversion, https://currencylayer.com/"
|
16
|
+
spec.summary = "Free and startup-friendly currency converter JSON API for real-time and historical exchange rates - reliable and accurate, supporting 168 world currencies."
|
17
17
|
spec.homepage = "https://github.com/pmoelgaard/currency_conversion"
|
18
18
|
spec.license = "MIT"
|
19
19
|
|
@@ -22,7 +22,14 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
|
+
spec.required_ruby_version = '>= 2.0.0'
|
26
|
+
|
27
|
+
spec.add_runtime_dependency "httparty"
|
28
|
+
spec.add_runtime_dependency "hashable"
|
29
|
+
|
25
30
|
spec.add_development_dependency "bundler", "~> 1.11"
|
26
31
|
spec.add_development_dependency "rake", "~> 10.0"
|
27
32
|
spec.add_development_dependency "rspec", "~> 3.0"
|
33
|
+
spec.add_development_dependency "dotenv"
|
34
|
+
spec.add_development_dependency "bump"
|
28
35
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'dotenv'
|
2
|
+
require 'currency_conversion'
|
3
|
+
require 'currency_conversion/live/live_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 currencies to fetch
|
14
|
+
currencies = 'AUD,EUR,GBP,PLN'
|
15
|
+
|
16
|
+
# We declare the options
|
17
|
+
options = CurrencyLayer::LiveOptions.new()
|
18
|
+
|
19
|
+
# We make the call to fetch the live currencies
|
20
|
+
response = @client.live(currencies, options)
|
21
|
+
|
22
|
+
# If its a success, we print a message to the user
|
23
|
+
if !response.nil?
|
24
|
+
puts 'SUCCESS : Live Currencies Fetched...' << response.to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
rescue => e
|
28
|
+
puts e.inspect
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'dotenv'
|
2
|
+
require 'currency_conversion'
|
3
|
+
require 'currency_conversion/live/live_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 currencies to fetch
|
14
|
+
currencies = [
|
15
|
+
'AUD',
|
16
|
+
'EUR',
|
17
|
+
'GBP',
|
18
|
+
'PLN'
|
19
|
+
]
|
20
|
+
|
21
|
+
# We declare the options
|
22
|
+
options = CurrencyLayer::LiveOptions.new()
|
23
|
+
|
24
|
+
# We make the call to fetch the live currencies
|
25
|
+
response = @client.live(currencies, options)
|
26
|
+
|
27
|
+
# If its a success, we print a message to the user
|
28
|
+
if !response.nil?
|
29
|
+
puts 'SUCCESS : Live Currencies Fetched...' << response.to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
rescue => e
|
33
|
+
puts e.inspect
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'dotenv'
|
2
|
+
require 'currency_conversion'
|
3
|
+
require 'currency_conversion/live/live_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 currencies to fetch
|
14
|
+
currencies = 'AUD,EUR,GBP,PLN'
|
15
|
+
|
16
|
+
# Set the source of the conversion
|
17
|
+
source = 'SGD'
|
18
|
+
|
19
|
+
# We declare the options
|
20
|
+
options = CurrencyLayer::LiveOptions.new()
|
21
|
+
options.source = source
|
22
|
+
|
23
|
+
# We make the call to fetch the live currencies
|
24
|
+
response = @client.live(currencies, options)
|
25
|
+
|
26
|
+
# If its a success, we print a message to the user
|
27
|
+
if !response.nil?
|
28
|
+
puts 'SUCCESS : Live Currencies Fetched w. source...' << response.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
rescue => e
|
32
|
+
puts e.inspect
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require "hashable"
|
2
|
+
|
3
|
+
module CurrencyLayer
|
4
|
+
|
5
|
+
class LiveRequest
|
6
|
+
|
7
|
+
include Hashable
|
8
|
+
|
9
|
+
attr_accessor :query
|
10
|
+
|
11
|
+
def initialize(query = {})
|
12
|
+
|
13
|
+
# Ruby passes by reference, so we can manipulate the object, and we check if the currencies is an array, and if so, we convert to string according to API
|
14
|
+
query.currencies = query.currencies.kind_of?(String) ? query.currencies : query.currencies.join(',')
|
15
|
+
|
16
|
+
self.query = query
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/currency_conversion.rb
CHANGED
@@ -1,5 +1,68 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "hashable"
|
1
3
|
require "currency_conversion/version"
|
4
|
+
require "currency_conversion/live/live_request"
|
5
|
+
require "currency_conversion/live/live_response"
|
2
6
|
|
3
7
|
module CurrencyLayer
|
4
|
-
|
8
|
+
|
9
|
+
class Client
|
10
|
+
|
11
|
+
include HTTParty
|
12
|
+
|
13
|
+
base_uri 'apilayer.net/api'
|
14
|
+
|
15
|
+
def initialize(access_key)
|
16
|
+
|
17
|
+
if access_key.nil?
|
18
|
+
raise CurrencyLayer::MissingArgumentException.new 'access_key'
|
19
|
+
end
|
20
|
+
|
21
|
+
@access_key = access_key
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def live(currencies, options = {})
|
26
|
+
|
27
|
+
if currencies.nil?
|
28
|
+
raise CurrencyLayer::MissingArgumentException.new 'currencies'
|
29
|
+
return
|
30
|
+
end
|
31
|
+
|
32
|
+
# Create a shallow copy so we don't manipulate the original reference
|
33
|
+
q = options.dup
|
34
|
+
|
35
|
+
# Populate the Query
|
36
|
+
q.access_key = @access_key
|
37
|
+
q.currencies = currencies
|
38
|
+
|
39
|
+
# We then create the Request
|
40
|
+
req = CurrencyLayer::LiveRequest.new(q)
|
41
|
+
|
42
|
+
# We create a Hash of the request so we can send it via HTTP
|
43
|
+
req_dto = req.to_dh
|
44
|
+
|
45
|
+
begin
|
46
|
+
|
47
|
+
# We make the actual request
|
48
|
+
res = self.class.get('/live', req_dto)
|
49
|
+
|
50
|
+
# We ensure that we tap the response so we can use the results
|
51
|
+
res.inspect
|
52
|
+
|
53
|
+
if (res[CurrencyLayer::LiveResponse::ERROR_EXPR])
|
54
|
+
raise CurrencyLayer::LiveException.new res[CurrencyLayer::LiveResponse::ERROR_EXPR]
|
55
|
+
end
|
56
|
+
|
57
|
+
# We just return the parsed binary response
|
58
|
+
return res.parsed_response
|
59
|
+
|
60
|
+
rescue => e
|
61
|
+
puts e.inspect
|
62
|
+
return e
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
5
68
|
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Andreas Moelgaard
|
@@ -10,6 +10,34 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2016-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hashable
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
13
41
|
- !ruby/object:Gem::Dependency
|
14
42
|
name: bundler
|
15
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -52,7 +80,36 @@ dependencies:
|
|
52
80
|
- - ~>
|
53
81
|
- !ruby/object:Gem::Version
|
54
82
|
version: '3.0'
|
55
|
-
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: dotenv
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: bump
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Ruby Library for the currencylayer API, Reliable Exchange Rates & Currency
|
112
|
+
Conversion, https://currencylayer.com/
|
56
113
|
email:
|
57
114
|
- github@petermolgaard.com
|
58
115
|
executables: []
|
@@ -69,7 +126,15 @@ files:
|
|
69
126
|
- bin/console
|
70
127
|
- bin/setup
|
71
128
|
- currency_conversion.gemspec
|
129
|
+
- example/example_live.rb
|
130
|
+
- example/example_live_w_currencies_as_array.rb
|
131
|
+
- example/example_live_w_source.rb
|
72
132
|
- lib/currency_conversion.rb
|
133
|
+
- lib/currency_conversion/live/live_exception.rb
|
134
|
+
- lib/currency_conversion/live/live_options.rb
|
135
|
+
- lib/currency_conversion/live/live_request.rb
|
136
|
+
- lib/currency_conversion/live/live_response.rb
|
137
|
+
- lib/currency_conversion/missing_argument_exception.rb
|
73
138
|
- lib/currency_conversion/version.rb
|
74
139
|
homepage: https://github.com/pmoelgaard/currency_conversion
|
75
140
|
licenses:
|
@@ -83,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
148
|
requirements:
|
84
149
|
- - '>='
|
85
150
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
151
|
+
version: 2.0.0
|
87
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
153
|
requirements:
|
89
154
|
- - '>='
|
@@ -94,5 +159,6 @@ rubyforge_project:
|
|
94
159
|
rubygems_version: 2.0.14
|
95
160
|
signing_key:
|
96
161
|
specification_version: 4
|
97
|
-
summary:
|
162
|
+
summary: Free and startup-friendly currency converter JSON API for real-time and historical
|
163
|
+
exchange rates - reliable and accurate, supporting 168 world currencies.
|
98
164
|
test_files: []
|