currencyconversion 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4d6706dc2b6be7510db89b46a566b1ad90ea384
4
- data.tar.gz: 51abba7ca76ff4c5b98ba5482b38ff019acca66f
3
+ metadata.gz: 23f88ea545e7e270059fc20236b07b749f9d9a1c
4
+ data.tar.gz: 1b764bda6dcbbf85bc673536dac419df2145eecf
5
5
  SHA512:
6
- metadata.gz: 65e046b53545d6e75ad441f1670d4a6021689e7bf07be8d4ec005ce057bc0fe9ee4015ef365dcfa43c5f2a9ccbb0cc8a72a4f134b6b0b3b3887dd94cab4c5940
7
- data.tar.gz: 9f556b29ae6e4745ecbca16a46589524f89c3a4e4ccbd40de2bb0bbb90bd9d2a78a34fbffcb2b04cb03727a197980cdeb978e120300bad098f8f4d8c95d67ec6
6
+ metadata.gz: 13bed63f674dde2fbd4a1c55f2dd096dc03f88d31768be7e6f65a1ecf11f5dcf27010538dba3087d9d0201f7a2c93023d4de225fbc292deeffc3765680c71e1f
7
+ data.tar.gz: 591cebb8a6bc80647c35d847726b110f23baa8d4d04db99a0686a552e14ec185c4d32f469ebcd10fe9c92383832a1e1feac1c83093f4af5df397074b374c5c9e
data/README.md CHANGED
@@ -95,6 +95,10 @@ options = CurrencyLayer::LiveOptions.new()
95
95
  response = @client.live(currencies, options)
96
96
 
97
97
  ```
98
+ ### Etag & Date (If-None-Match, If-Modified-Since)
99
+ The ```live``` endpoint supports these headers to minimise unnecessary traffic and load on systems.
100
+ This library internally sets these headers and manages a local cache, so whenever the library receives a 304 (no changes) response from the server, it will return the last response it received. This way this library will always return a response.
101
+
98
102
 
99
103
  ## List
100
104
  Fetches the list of currencies.
@@ -0,0 +1,36 @@
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
+ while true
20
+
21
+ # We make the call to fetch the live currencies
22
+ response = @client.live(currencies, options)
23
+
24
+ # If its a success, we print a message to the user
25
+ if !response.nil?
26
+ puts 'SUCCESS : Live Currencies Fetched...' << response.to_s
27
+ end
28
+
29
+ sleep 5
30
+
31
+ end
32
+
33
+ rescue => e
34
+ puts e.inspect
35
+
36
+ end
@@ -6,9 +6,12 @@ module CurrencyLayer
6
6
 
7
7
  include Hashable
8
8
 
9
+ attr_accessor :headers
9
10
  attr_accessor :query
10
11
 
11
- def initialize(query = {})
12
+ def initialize(query = {}, headers = {})
13
+
14
+ self.headers = headers
12
15
 
13
16
  # 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
17
  query.currencies = query.currencies.kind_of?(String) ? query.currencies : query.currencies.join(',')
@@ -1,3 +1,3 @@
1
1
  module CurrencyLayer
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -38,7 +38,11 @@ module CurrencyLayer
38
38
 
39
39
  end
40
40
 
41
- def live(currencies, options = {})
41
+
42
+ attr_accessor :live_last_response
43
+ attr_accessor :live_last_response_headers
44
+
45
+ def live(currencies, options = {}, headers = {})
42
46
 
43
47
  if currencies.nil?
44
48
  raise CurrencyLayer::MissingArgumentException.new 'currencies'
@@ -52,8 +56,14 @@ module CurrencyLayer
52
56
  q.access_key = @access_key
53
57
  q.currencies = currencies
54
58
 
59
+ # Set the cache options
60
+ if (self.live_last_response_headers)
61
+ headers['If-None-Match'] = self.live_last_response_headers['etag']
62
+ headers['If-Modified-Since'] = self.live_last_response_headers['date']
63
+ end
64
+
55
65
  # We then create the Request
56
- req = CurrencyLayer::LiveRequest.new(q)
66
+ req = CurrencyLayer::LiveRequest.new(q, headers)
57
67
 
58
68
  # We create a Hash of the request so we can send it via HTTP
59
69
  req_dto = req.to_dh
@@ -66,10 +76,19 @@ module CurrencyLayer
66
76
  # We ensure that we tap the response so we can use the results
67
77
  res.inspect
68
78
 
79
+ # We have struck a 304, and we just return the last_response
80
+ if(res.nil? && ! self.live_last_response.nil?)
81
+ return self.live_last_response
82
+ end
83
+
69
84
  if (res[CurrencyLayer::LiveResponse::ERROR_EXPR])
70
85
  raise CurrencyLayer::LiveException.new res[CurrencyLayer::LiveResponse::ERROR_EXPR]
71
86
  end
72
87
 
88
+ # To facilitate we set the cache arguments
89
+ self.live_last_response = res.parsed_response
90
+ self.live_last_response_headers = res.headers
91
+
73
92
  # We just return the parsed binary response
74
93
  return res.parsed_response
75
94
 
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: currencyconversion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Andreas Moelgaard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-02-20 00:00:00.000000000 Z
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hashable
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '1.11'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.11'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '10.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '3.0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '3.0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: dotenv
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: bump
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: Ruby Library for the currencylayer API, Reliable Exchange Rates & Currency
@@ -116,8 +116,8 @@ executables: []
116
116
  extensions: []
117
117
  extra_rdoc_files: []
118
118
  files:
119
- - .rspec
120
- - .travis.yml
119
+ - ".rspec"
120
+ - ".travis.yml"
121
121
  - CODE_OF_CONDUCT.md
122
122
  - Gemfile
123
123
  - LICENSE.txt
@@ -130,6 +130,7 @@ files:
130
130
  - example/example_list.rb
131
131
  - example/example_live.rb
132
132
  - example/example_live_w_currencies_as_array.rb
133
+ - example/example_live_w_interval.rb
133
134
  - example/example_live_w_source.rb
134
135
  - example/example_timeframe.rb
135
136
  - lib/currency_conversion.rb
@@ -169,12 +170,12 @@ require_paths:
169
170
  - lib
170
171
  required_ruby_version: !ruby/object:Gem::Requirement
171
172
  requirements:
172
- - - '>='
173
+ - - ">="
173
174
  - !ruby/object:Gem::Version
174
175
  version: 2.0.0
175
176
  required_rubygems_version: !ruby/object:Gem::Requirement
176
177
  requirements:
177
- - - '>='
178
+ - - ">="
178
179
  - !ruby/object:Gem::Version
179
180
  version: '0'
180
181
  requirements: []