apilayer 1.0.1 → 1.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/README.rdoc +11 -6
- data/lib/apilayer/currency.rb +47 -11
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b96da80c728f03b13491f9a4d7f24dc8b445c90
|
4
|
+
data.tar.gz: 4ae80aaded90734d72100e480ab120ec25025f05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7353484a6d9eefc43d098f1853a0bf4c27aa121d0f2785d493f4870b1cde71ecbd429d2da00de0bd568f8870f958a22dfeab4f51244ee8d5f1ed79130a92a3b6
|
7
|
+
data.tar.gz: 4a95462f310c84991796fa576558809369ed6f8f74f6d3905c65cf063fb1264bc649d9c9ff6b5c56886cd91d789ab719c25940f5ca178100b05fafc984e8b0d4
|
data/README.rdoc
CHANGED
@@ -3,8 +3,10 @@
|
|
3
3
|
Ruby wrapper for various services of apilayer.
|
4
4
|
See http://apilayer.com for more details.
|
5
5
|
|
6
|
-
=== Version 1.
|
7
|
-
|
6
|
+
=== Version 1.1
|
7
|
+
- Major change to how .live and .historical in Apilayer::Currency are invoked.
|
8
|
+
- Added :source option to Apilayer::Currency.live and Apilayer::Currency.historical methods. This option is only available to paid users of currencylayer.
|
9
|
+
|
8
10
|
|
9
11
|
=== Installation
|
10
12
|
|
@@ -37,13 +39,16 @@ Once that is done, you are ready to go
|
|
37
39
|
==== currencylayer
|
38
40
|
After setting the access_key for *currencylayer*, you can use Apilayer::Currency to call *currencylayer*'s API
|
39
41
|
Apilayer::Currency.live
|
40
|
-
Apilayer::Currency.live(
|
41
|
-
|
42
|
+
Apilayer::Currency.live(:currencies => %w[GBP, CHF])
|
43
|
+
Apilayer::Currency.live(:source => "EUR") # source-currency is USD by default
|
44
|
+
Apilayer::Currency.live(:source => "EUR", :currencies => %w[GBP, CHF])
|
45
|
+
|
42
46
|
Apilayer::Currency.historical("2016-01-01")
|
43
|
-
Apilayer::Currency.historical("2016-01-01",
|
47
|
+
Apilayer::Currency.historical("2016-01-01", :currencies => %w[GBP CHF])
|
48
|
+
Apilayer::Currency.historical(:source => "EUR") # source-currency is USD by default
|
49
|
+
Apilayer::Currency.historical("2016-01-01", :currencies => %w[GBP CHF], :source => "EUR")
|
44
50
|
|
45
51
|
==== vatlayer
|
46
|
-
|
47
52
|
After setting the access_key for *vatlayer*, you can use Apilayer::Vat to call *vatlayer*'s API
|
48
53
|
|
49
54
|
Apilayer::Vat.validate("LU26375245")
|
data/lib/apilayer/currency.rb
CHANGED
@@ -8,6 +8,19 @@ module Apilayer
|
|
8
8
|
# Determines which access_key in Apilayer.configs to use
|
9
9
|
# in order to to make a connection to currencylayer
|
10
10
|
APILAYER_CONFIG_KEY = :currency_key
|
11
|
+
INVALID_OPTIONS_MSG = "You have provided an invalid option. Allowed options are :currencies and :source"
|
12
|
+
LIVE_SLUG = "live"
|
13
|
+
HISTORICAL_SLUG = "historical"
|
14
|
+
|
15
|
+
## Validations
|
16
|
+
#
|
17
|
+
def self.validate_options(options)
|
18
|
+
options.keys.each do |key|
|
19
|
+
unless [:currencies, :source].include? key
|
20
|
+
raise Apilayer::Error.new(INVALID_OPTIONS_MSG)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
11
24
|
|
12
25
|
### API methods
|
13
26
|
#
|
@@ -17,14 +30,16 @@ module Apilayer
|
|
17
30
|
# When no currency-codes are specified, it will return all exchange rates for your source-currency.
|
18
31
|
# Example:
|
19
32
|
# Apilayer::Currency.live
|
20
|
-
# Apilayer::Currency.live(
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
33
|
+
# Apilayer::Currency.live(:currencies => %w[GBP, CHF])
|
34
|
+
# Apilayer::Currency.live(:source => "EUR")
|
35
|
+
# Apilayer::Currency.live(:source => "EUR", :currencies => %w[GBP, CHF])
|
36
|
+
def self.live(opts={})
|
37
|
+
validate_options(opts)
|
38
|
+
|
39
|
+
if opts.empty?
|
40
|
+
get_and_parse LIVE_SLUG
|
26
41
|
else
|
27
|
-
|
42
|
+
get_and_parse_with_options(LIVE_SLUG, opts)
|
28
43
|
end
|
29
44
|
end
|
30
45
|
|
@@ -33,13 +48,34 @@ module Apilayer
|
|
33
48
|
# When no currency-codes are specified, it will return all exchange rates for your source-currency.
|
34
49
|
# Example:
|
35
50
|
# Apilayer::Currency.historical("2016-01-01")
|
36
|
-
# Apilayer::Currency.historical("2016-01-01",
|
37
|
-
|
51
|
+
# Apilayer::Currency.historical("2016-01-01", :currencies => %w[GBP CHF])
|
52
|
+
# Apilayer::Currency.historical(:source => "EUR")
|
53
|
+
# Apilayer::Currency.historical("2016-01-01", :currencies => %w[GBP CHF], :source => "EUR")
|
54
|
+
def self.historical(date, opts={})
|
55
|
+
validate_options(opts)
|
38
56
|
params = {:date => date}
|
39
|
-
|
40
|
-
|
57
|
+
|
58
|
+
if opts.empty?
|
59
|
+
get_and_parse(HISTORICAL_SLUG, params)
|
60
|
+
else
|
61
|
+
get_and_parse_with_options(HISTORICAL_SLUG, opts, params)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.get_and_parse_with_options(slug, opts, params={})
|
66
|
+
params = add_options_to_params(opts, params)
|
67
|
+
get_and_parse(slug, params)
|
41
68
|
end
|
42
69
|
|
70
|
+
def self.add_options_to_params(opts, params)
|
71
|
+
if opts[:currencies] && opts[:currencies].any?
|
72
|
+
params[:currencies] = join_by_commas(opts[:currencies])
|
73
|
+
end
|
74
|
+
if opts[:source]
|
75
|
+
params[:source] = opts[:source]
|
76
|
+
end
|
77
|
+
params
|
78
|
+
end
|
43
79
|
##
|
44
80
|
# Joins currencies in an array as a comma-separated-string
|
45
81
|
def self.join_by_commas(currencies)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apilayer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Fong
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -191,7 +191,7 @@ dependencies:
|
|
191
191
|
- !ruby/object:Gem::Version
|
192
192
|
version: 2.0.1
|
193
193
|
description: Ruby wrapper for currencylayer and vatlayer from apilayer.com. Currently
|
194
|
-
supporting
|
194
|
+
not supporting all paid-features yet. See https://apilayer.com/ for more details.
|
195
195
|
email:
|
196
196
|
- actfong@gmail.com
|
197
197
|
executables: []
|