apilayer 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.rdoc +11 -6
  3. data/lib/apilayer/currency.rb +47 -11
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2659b5c043a8d8a4d2a436946ade66aa15abaf2
4
- data.tar.gz: 55ca2767cfde675b299e4e0e72528d80666c9070
3
+ metadata.gz: 4b96da80c728f03b13491f9a4d7f24dc8b445c90
4
+ data.tar.gz: 4ae80aaded90734d72100e480ab120ec25025f05
5
5
  SHA512:
6
- metadata.gz: b315c3af07f87e5e46cffe3f0df6621a95b6e12f6f399846d33de65ea7ea608c73e8dec39e93a16d29a839bebfa0450bce7607458a033072ecdbdd3355fe0d6d
7
- data.tar.gz: ef460e9457bf224fb2f5f2462223a0ba9df83c06697e398d707b240710d09f50363abc38e20358ccfc76fb0defbbac1d864806244f3e8cbe6ee23e09a903072d
6
+ metadata.gz: 7353484a6d9eefc43d098f1853a0bf4c27aa121d0f2785d493f4870b1cde71ecbd429d2da00de0bd568f8870f958a22dfeab4f51244ee8d5f1ed79130a92a3b6
7
+ data.tar.gz: 4a95462f310c84991796fa576558809369ed6f8f74f6d3905c65cf063fb1264bc649d9c9ff6b5c56886cd91d789ab719c25940f5ca178100b05fafc984e8b0d4
@@ -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.0
7
- For this version, only the API-features that are available to the free accounts are supported. See the documentation of http://currencylayer.com and http://vatlayer.com for more details.
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("EUR", "GBP", "CHF")
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", "EUR", "GBP", "CHF")
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")
@@ -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("EUR", "GBP", "CHF")
21
- def self.live(*currencies)
22
- if currencies.any?
23
- currencies_str = join_by_commas(currencies)
24
- params = {:currencies => currencies_str}
25
- get_and_parse("live", params)
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
- get_and_parse("live")
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", "EUR", "GBP", "CHF")
37
- def self.historical(date, *currencies)
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
- params.merge!(:currencies => join_by_commas(currencies)) if currencies.any?
40
- get_and_parse("historical", params)
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.1
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 00:00:00.000000000 Z
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 the free API-functions only. See https://apilayer.com/ for more details.
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: []