google_currency_rails_cache 1.0.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.
- data/.gemtest +0 -0
- data/AUTHORS +8 -0
- data/CHANGELOG.md +107 -0
- data/LICENSE +20 -0
- data/README.md +39 -0
- data/Rakefile +49 -0
- data/google_currency_rails_cache.gemspec +28 -0
- data/lib/money/bank/google_currency_rails_cache.rb +169 -0
- data/spec/google_currency_with_json_spec.rb +64 -0
- data/spec/google_currency_with_yajl_spec.rb +63 -0
- data/spec/spec_helper.rb +2 -0
- metadata +189 -0
data/.gemtest
ADDED
File without changes
|
data/AUTHORS
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
Google Currency 2.2.0
|
2
|
+
=====================
|
3
|
+
|
4
|
+
- Update money dependency to ~> 5.1.0
|
5
|
+
|
6
|
+
Google Currency 2.1.0
|
7
|
+
=====================
|
8
|
+
|
9
|
+
- Update money dependency to ~> 5.0.0
|
10
|
+
|
11
|
+
Google Currency 2.0.2
|
12
|
+
=====================
|
13
|
+
|
14
|
+
Bugfixes
|
15
|
+
--------
|
16
|
+
- Fix encoding issue
|
17
|
+
|
18
|
+
Google Currency 2.0.1
|
19
|
+
=====================
|
20
|
+
|
21
|
+
Features
|
22
|
+
--------
|
23
|
+
- Handles funky exchange rates (Arnaud Joubay)
|
24
|
+
|
25
|
+
Bugfixes
|
26
|
+
--------
|
27
|
+
- Fix for running under 1.9.2 in TextMate (larspind)
|
28
|
+
|
29
|
+
Google Currency 2.0.0
|
30
|
+
=====================
|
31
|
+
|
32
|
+
Features
|
33
|
+
--------
|
34
|
+
- Added multi_json to allow users to select their own JSON parsing engine.
|
35
|
+
- Removed deprecated method #get_google_rate.
|
36
|
+
|
37
|
+
Bugfixes
|
38
|
+
--------
|
39
|
+
- Updated deprecated rake tasks
|
40
|
+
|
41
|
+
Google Currency 1.1.1
|
42
|
+
=====================
|
43
|
+
|
44
|
+
Bugfixes
|
45
|
+
--------
|
46
|
+
- Built gem using Ruby 1.8.7 to bypass a known error with RubyGems 1.5.0 and
|
47
|
+
Ruby 1.9.2
|
48
|
+
|
49
|
+
Google Currency 1.1.0
|
50
|
+
=====================
|
51
|
+
|
52
|
+
Features
|
53
|
+
--------
|
54
|
+
- Deprecated #get_google_rate, use #get_rate (thanks RMU Alumni)
|
55
|
+
|
56
|
+
Bugfixes
|
57
|
+
---------
|
58
|
+
- Fixed an issue when rates over 1000 did not parse correctly (thanks Brandon
|
59
|
+
Anderson)
|
60
|
+
|
61
|
+
Google Currency 1.0.3
|
62
|
+
=====================
|
63
|
+
|
64
|
+
Features
|
65
|
+
--------
|
66
|
+
- Update `money` requirement to `~> 3.5`
|
67
|
+
|
68
|
+
Google Currency 1.0.2
|
69
|
+
=====================
|
70
|
+
|
71
|
+
Features
|
72
|
+
--------
|
73
|
+
- Replace `eval` with `JSON.parse`
|
74
|
+
- Use BigDecimal instead of Float
|
75
|
+
|
76
|
+
Bugfixes
|
77
|
+
--------
|
78
|
+
- Quell parenthetical warnings in specs
|
79
|
+
|
80
|
+
Google Currency 1.0.1
|
81
|
+
=====================
|
82
|
+
|
83
|
+
Features
|
84
|
+
--------
|
85
|
+
- Update `money` requirement to `~> 3.1.5`
|
86
|
+
|
87
|
+
Google Currency 1.0.0
|
88
|
+
=====================
|
89
|
+
|
90
|
+
Features
|
91
|
+
--------
|
92
|
+
- Updated `money` requirement to `~> 3.1.0`
|
93
|
+
|
94
|
+
Google Currency 0.1.1
|
95
|
+
=====================
|
96
|
+
|
97
|
+
Features
|
98
|
+
--------
|
99
|
+
- Added #flush_rates
|
100
|
+
- Added #flush_rate
|
101
|
+
|
102
|
+
Google Currency 0.1.0
|
103
|
+
=====================
|
104
|
+
|
105
|
+
Features
|
106
|
+
--------
|
107
|
+
- Initial release
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Shane Emmons
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
Google Currency with Rails Cache
|
2
|
+
================================
|
3
|
+
|
4
|
+
This gem extends Money::Bank::VariableExchange with Money::Bank::GoogleCurrency
|
5
|
+
and gives you access to the current Google Currency exchange rates.
|
6
|
+
|
7
|
+
You have to load one of the JSON libraries supported by
|
8
|
+
[MultiJSON](https://github.com/intridea/multi_json) (`json` for example)
|
9
|
+
if it's not already loaded by your application. In a Rails application,
|
10
|
+
ActiveSupport provides a JSON implementation that is automatically recognized.
|
11
|
+
|
12
|
+
This fork of the original GoogleCurrency library uses the Rails.cache for exchange rate
|
13
|
+
storage instead of a Mutex. It is designed for multiple application server environments.
|
14
|
+
|
15
|
+
Usage
|
16
|
+
-----
|
17
|
+
|
18
|
+
require 'money'
|
19
|
+
require 'money/bank/google_currency'
|
20
|
+
require 'json'
|
21
|
+
MultiJson.engine = :json_gem # or :yajl
|
22
|
+
|
23
|
+
# set default bank to instance of GoogleCurrency
|
24
|
+
Money.default_bank = Money::Bank::GoogleCurrency.new
|
25
|
+
|
26
|
+
# create a new money object, and use the standard #exchange_to method
|
27
|
+
n = 1.to_money(:USD)
|
28
|
+
n.exchange_to(:EUR)
|
29
|
+
|
30
|
+
An `UnknownRate` will be thrown if `#exchange_to` is called with a `Currency`
|
31
|
+
that `Money` knows, but Google does not.
|
32
|
+
|
33
|
+
An `UnknownCurrency` will be thrown if `#exchange_to` is called with a
|
34
|
+
`Currency` that `Money` does not know.
|
35
|
+
|
36
|
+
Copyright
|
37
|
+
---------
|
38
|
+
|
39
|
+
Original Google Currency work is Copyright (c) 2011 Shane Emmons. See {file:LICENSE} for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake/clean'
|
3
|
+
|
4
|
+
CLOBBER.include('.yardoc', 'doc')
|
5
|
+
|
6
|
+
def gemspec
|
7
|
+
@gemspec ||= begin
|
8
|
+
file = File.expand_path("../google_currency.gemspec", __FILE__)
|
9
|
+
eval(File.read(file), binding, file)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'rspec/core/rake_task'
|
15
|
+
RSpec::Core::RakeTask.new
|
16
|
+
rescue LoadError
|
17
|
+
task(:spec){abort "`gem install rspec` to run specs"}
|
18
|
+
end
|
19
|
+
task :default => :spec
|
20
|
+
task :test => :spec
|
21
|
+
|
22
|
+
begin
|
23
|
+
require 'yard'
|
24
|
+
YARD::Rake::YardocTask.new do |t|
|
25
|
+
t.options << "--files" << "CHANGELOG.md,LICENSE"
|
26
|
+
end
|
27
|
+
rescue LoadError
|
28
|
+
task(:yard){abort "`gem install yard` to generate documentation"}
|
29
|
+
end
|
30
|
+
|
31
|
+
begin
|
32
|
+
require 'rubygems/package_task'
|
33
|
+
Gem::PackageTask.new(gemspec) do |pkg|
|
34
|
+
pkg.gem_spec = gemspec
|
35
|
+
end
|
36
|
+
task :gem => :gemspec
|
37
|
+
rescue LoadError
|
38
|
+
task(:gem){abort "`gem install rake` to package gems"}
|
39
|
+
end
|
40
|
+
|
41
|
+
desc "Install the gem locally"
|
42
|
+
task :install => :gem do
|
43
|
+
sh "gem install pkg/#{gemspec.full_name}.gem"
|
44
|
+
end
|
45
|
+
|
46
|
+
desc "Validate the gemspec"
|
47
|
+
task :gemspec do
|
48
|
+
gemspec.validate
|
49
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "google_currency_rails_cache"
|
3
|
+
s.version = "1.0.0"
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.authors = ["Shane Emmons", "Alex Kremer"]
|
6
|
+
s.email = ["semmons99@gmail.com", "alex@flextrip.com"]
|
7
|
+
s.homepage = "http://github.com/flextrip/google_currency_rails_cache"
|
8
|
+
s.summary = "Access the Google Currency exchange rate data."
|
9
|
+
s.description = "GoogleCurrency extends Money::Bank::Base and gives you access to the current Google Currency exchange rates. This fork allows caching of exchange rate data in Rails.cache and removes the necessity for the Mutex."
|
10
|
+
|
11
|
+
s.required_rubygems_version = ">= 1.3.6"
|
12
|
+
|
13
|
+
s.add_development_dependency "rspec", ">= 2.0.0"
|
14
|
+
s.add_development_dependency "yard", ">= 0.5.8"
|
15
|
+
s.add_development_dependency "json", ">= 1.4.0"
|
16
|
+
s.add_development_dependency "yajl-ruby", ">= 1.0.0"
|
17
|
+
s.add_development_dependency "ffi"
|
18
|
+
|
19
|
+
s.add_dependency "money", "~> 5.1.0"
|
20
|
+
s.add_dependency "multi_json", ">= 1.0.0"
|
21
|
+
s.add_dependency "rails", "> 3.2"
|
22
|
+
|
23
|
+
s.files = Dir.glob("{lib,spec}/**/*")
|
24
|
+
s.files += %w(LICENSE README.md CHANGELOG.md AUTHORS)
|
25
|
+
s.files += %w(Rakefile .gemtest google_currency_rails_cache.gemspec)
|
26
|
+
|
27
|
+
s.require_path = "lib"
|
28
|
+
end
|
@@ -0,0 +1,169 @@
|
|
1
|
+
require 'money'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'multi_json'
|
4
|
+
|
5
|
+
class Money
|
6
|
+
module Bank
|
7
|
+
class GoogleCurrencyRailsCache < Money::Bank::VariableExchange
|
8
|
+
|
9
|
+
SERVICE_HOST = "www.google.com"
|
10
|
+
SERVICE_PATH = "/ig/calculator"
|
11
|
+
|
12
|
+
# @return [Hash] Stores the currently known rates.
|
13
|
+
attr_reader :rates
|
14
|
+
|
15
|
+
##
|
16
|
+
# Clears all rates stored in @rates
|
17
|
+
#
|
18
|
+
# @return [Hash] The empty @rates Hash.
|
19
|
+
#
|
20
|
+
# @example
|
21
|
+
# @bank = GoogleCurrency.new #=> <Money::Bank::GoogleCurrency...>
|
22
|
+
# @bank.get_rate(:USD, :EUR) #=> 0.776337241
|
23
|
+
# @bank.flush_rates #=> {}
|
24
|
+
def flush_rates
|
25
|
+
@rates.keys.each do |rate_key|
|
26
|
+
Rails.cache.delete "exchange_rate/#{rate_key}"
|
27
|
+
end
|
28
|
+
@rates.clear
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# Clears the specified rate stored in @rates.
|
33
|
+
#
|
34
|
+
# @param [String, Symbol, Currency] from Currency to convert from (used
|
35
|
+
# for key into @rates).
|
36
|
+
# @param [String, Symbol, Currency] to Currency to convert to (used for
|
37
|
+
# key into @rates).
|
38
|
+
#
|
39
|
+
# @return [Float] The flushed rate.
|
40
|
+
#
|
41
|
+
# @example
|
42
|
+
# @bank = GoogleCurrency.new #=> <Money::Bank::GoogleCurrency...>
|
43
|
+
# @bank.get_rate(:USD, :EUR) #=> 0.776337241
|
44
|
+
# @bank.flush_rate(:USD, :EUR) #=> 0.776337241
|
45
|
+
def flush_rate(from, to)
|
46
|
+
rate_key = rate_key_for(from, to)
|
47
|
+
Rails.cache.delete "exchange_rate/#{rate_key}"
|
48
|
+
@rates.delete(rate_key)
|
49
|
+
end
|
50
|
+
|
51
|
+
##
|
52
|
+
# Returns the requested rate.
|
53
|
+
#
|
54
|
+
# @param [String, Symbol, Currency] from Currency to convert from
|
55
|
+
# @param [String, Symbol, Currency] to Currency to convert to
|
56
|
+
#
|
57
|
+
# @return [Float] The requested rate.
|
58
|
+
#
|
59
|
+
# @example
|
60
|
+
# @bank = GoogleCurrency.new #=> <Money::Bank::GoogleCurrency...>
|
61
|
+
# @bank.get_rate(:USD, :EUR) #=> 0.776337241
|
62
|
+
def get_rate(from, to)
|
63
|
+
@rates[rate_key_for(from, to)] ||= Rails.cache.fetch("exchange_rate/#{rate_key_for(from, to)}", :expires_in => 12.hours ) {
|
64
|
+
fetch_rate(from, to)
|
65
|
+
}
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
##
|
71
|
+
# Queries for the requested rate and returns it.
|
72
|
+
#
|
73
|
+
# @param [String, Symbol, Currency] from Currency to convert from
|
74
|
+
# @param [String, Symbol, Currency] to Currency to convert to
|
75
|
+
#
|
76
|
+
# @return [BigDecimal] The requested rate.
|
77
|
+
def fetch_rate(from, to)
|
78
|
+
from, to = Currency.wrap(from), Currency.wrap(to)
|
79
|
+
|
80
|
+
data = build_uri(from, to).read
|
81
|
+
data = fix_response_json_data(data)
|
82
|
+
|
83
|
+
error = data['error']
|
84
|
+
raise UnknownRate unless error == '' || error == '0'
|
85
|
+
decode_rate data['rhs']
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# Build a URI for the given arguments.
|
90
|
+
#
|
91
|
+
# @param [Currency] from The currency to convert from.
|
92
|
+
# @param [Currency] to The currency to convert to.
|
93
|
+
#
|
94
|
+
# @return [URI::HTTP]
|
95
|
+
def build_uri(from, to)
|
96
|
+
uri = URI::HTTP.build(
|
97
|
+
:host => SERVICE_HOST,
|
98
|
+
:path => SERVICE_PATH,
|
99
|
+
:query => "hl=en&q=1#{from.iso_code}%3D%3F#{to.iso_code}"
|
100
|
+
)
|
101
|
+
end
|
102
|
+
|
103
|
+
##
|
104
|
+
# Takes the invalid JSON returned by Google and fixes it.
|
105
|
+
#
|
106
|
+
# @param [String] data The JSON string to fix.
|
107
|
+
#
|
108
|
+
# @return [Hash]
|
109
|
+
def fix_response_json_data(data)
|
110
|
+
data.gsub!(/lhs:/, '"lhs":')
|
111
|
+
data.gsub!(/rhs:/, '"rhs":')
|
112
|
+
data.gsub!(/error:/, '"error":')
|
113
|
+
data.gsub!(/icc:/, '"icc":')
|
114
|
+
data.gsub!(Regexp.new("(\\\\x..|\\\\240)"), '')
|
115
|
+
|
116
|
+
MultiJson.decode(data)
|
117
|
+
end
|
118
|
+
|
119
|
+
##
|
120
|
+
# Takes the 'rhs' response from Google and decodes it.
|
121
|
+
#
|
122
|
+
# @param [String] rhs The google rate string to decode.
|
123
|
+
#
|
124
|
+
# @return [BigDecimal]
|
125
|
+
def decode_rate(rhs)
|
126
|
+
if complex_rate?(rhs)
|
127
|
+
decode_complex_rate(rhs)
|
128
|
+
else
|
129
|
+
decode_basic_rate(rhs)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
##
|
134
|
+
# Takes the 'rhs' response from Google and decides if it's a complex rate
|
135
|
+
#
|
136
|
+
# @param [String] rhs The google rate string to check.
|
137
|
+
#
|
138
|
+
# @return [Boolean]
|
139
|
+
def complex_rate?(rhs)
|
140
|
+
rhs.match(/10x3csupx3e(-?\d+)x3c\/supx3e/)
|
141
|
+
end
|
142
|
+
|
143
|
+
##
|
144
|
+
# Takes a complex 'rhs' response from Google and converts it to a numeric
|
145
|
+
# rate.
|
146
|
+
#
|
147
|
+
# @param [String] rhs The complex google rate string to convert.
|
148
|
+
#
|
149
|
+
# @return [BigDecimal]
|
150
|
+
def decode_complex_rate(rhs)
|
151
|
+
rate = BigDecimal(rhs.match(/\d[\d\s]*\.?\d*/)[0])
|
152
|
+
power = rhs.match(/10x3csupx3e(-?\d+)x3c\/supx3e/)
|
153
|
+
|
154
|
+
rate * 10**power[1].to_i
|
155
|
+
end
|
156
|
+
|
157
|
+
##
|
158
|
+
# Takes a basic 'rhs' response from Google and converts it to a numeric
|
159
|
+
# rate.
|
160
|
+
#
|
161
|
+
# @param [String] rhs The basic google rate string to convert.
|
162
|
+
#
|
163
|
+
# @return [BigDecimal]
|
164
|
+
def decode_basic_rate(rhs)
|
165
|
+
BigDecimal(rhs.gsub(/[^\d\.]/, ''))
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
require 'money'
|
4
|
+
require 'money/bank/google_currency_rails_cache'
|
5
|
+
require 'rails'
|
6
|
+
|
7
|
+
require 'json'
|
8
|
+
MultiJson.engine = :json_gem
|
9
|
+
|
10
|
+
describe "GoogleCurrency" do
|
11
|
+
|
12
|
+
before :each do
|
13
|
+
Rails.stub(:cache).and_return(ActiveSupport::Cache::MemoryStore.new)
|
14
|
+
@bank = Money::Bank::GoogleCurrencyRailsCache.new
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#get_rate" do
|
18
|
+
it "should use #fetch_rate when rate is unknown" do
|
19
|
+
@bank.should_receive(:fetch_rate).once
|
20
|
+
@bank.get_rate('USD', 'USD')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not use #fetch_rate when rate is known" do
|
24
|
+
@bank.get_rate('USD', 'USD')
|
25
|
+
@bank.should_not_receive(:fetch_rate)
|
26
|
+
@bank.get_rate('USD', 'USD')
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return the correct rate" do
|
30
|
+
@bank.get_rate('USD', 'USD').should == 1.0
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should store the rate for faster retreival" do
|
34
|
+
@bank.get_rate('USD', 'EUR')
|
35
|
+
@bank.rates.should include('USD_TO_EUR')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should handle complex rates" do
|
39
|
+
uri = double('uri')
|
40
|
+
@bank.stub(:build_uri){|from,to| uri }
|
41
|
+
uri.stub(:read) { %q({lhs: "1 Vietnamese dong",rhs: "4.8 \x26#215; 10\x3csup\x3e-5\x3c/sup\x3e U.S. dollars",error: "",icc: true}) }
|
42
|
+
|
43
|
+
@bank.get_rate('VND', 'USD').should == BigDecimal("0.48215105E1")
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe "#flush_rates" do
|
48
|
+
it "should empty @rates" do
|
49
|
+
@bank.get_rate('USD', 'EUR')
|
50
|
+
@bank.flush_rates
|
51
|
+
@bank.rates.should == {}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#flush_rate" do
|
56
|
+
it "should remove a specific rate from @rates" do
|
57
|
+
@bank.get_rate('USD', 'EUR')
|
58
|
+
@bank.get_rate('USD', 'JPY')
|
59
|
+
@bank.flush_rate('USD', 'EUR')
|
60
|
+
@bank.rates.should include('USD_TO_JPY')
|
61
|
+
@bank.rates.should_not include('USD_TO_EUR')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
require 'money'
|
4
|
+
require 'money/bank/google_currency_rails_cache'
|
5
|
+
|
6
|
+
require 'rails'
|
7
|
+
|
8
|
+
require 'yajl'
|
9
|
+
MultiJson.engine = :yajl
|
10
|
+
|
11
|
+
describe "GoogleCurrency" do
|
12
|
+
before :each do
|
13
|
+
Rails.stub(:cache).and_return(ActiveSupport::Cache::MemoryStore.new)
|
14
|
+
@bank = Money::Bank::GoogleCurrencyRailsCache.new
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "#get_rate" do
|
18
|
+
it "should use #fetch_rate when rate is unknown" do
|
19
|
+
@bank.should_receive(:fetch_rate).once
|
20
|
+
@bank.get_rate('USD', 'USD')
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not use #fetch_rate when rate is known" do
|
24
|
+
@bank.get_rate('USD', 'USD')
|
25
|
+
@bank.should_not_receive(:fetch_rate)
|
26
|
+
@bank.get_rate('USD', 'USD')
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return the correct rate" do
|
30
|
+
@bank.get_rate('USD', 'USD').should == 1.0
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should store the rate for faster retreival" do
|
34
|
+
@bank.get_rate('USD', 'EUR')
|
35
|
+
@bank.rates.should include('USD_TO_EUR')
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should handle complex rates" do
|
39
|
+
uri = double('uri')
|
40
|
+
@bank.stub(:build_uri){|from,to| uri }
|
41
|
+
uri.stub(:read) { %q({lhs: "1 Vietnamese dong",rhs: "4.8 \x26#215; 10\x3csup\x3e-5\x3c/sup\x3e U.S. dollars",error: "",icc: true}) }
|
42
|
+
@bank.get_rate('VND', 'USD').should == BigDecimal("0.48215105E1")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#flush_rates" do
|
47
|
+
it "should empty @rates" do
|
48
|
+
@bank.get_rate('USD', 'EUR')
|
49
|
+
@bank.flush_rates
|
50
|
+
@bank.rates.should == {}
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe "#flush_rate" do
|
55
|
+
it "should remove a specific rate from @rates" do
|
56
|
+
@bank.get_rate('USD', 'EUR')
|
57
|
+
@bank.get_rate('USD', 'JPY')
|
58
|
+
@bank.flush_rate('USD', 'EUR')
|
59
|
+
@bank.rates.should include('USD_TO_JPY')
|
60
|
+
@bank.rates.should_not include('USD_TO_EUR')
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,189 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google_currency_rails_cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Shane Emmons
|
9
|
+
- Alex Kremer
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-06-29 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.0.0
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 2.0.0
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: yard
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 0.5.8
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.5.8
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: json
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.4.0
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.4.0
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: yajl-ruby
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.0.0
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 1.0.0
|
79
|
+
- !ruby/object:Gem::Dependency
|
80
|
+
name: ffi
|
81
|
+
requirement: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
83
|
+
requirements:
|
84
|
+
- - ! '>='
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
87
|
+
type: :development
|
88
|
+
prerelease: false
|
89
|
+
version_requirements: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: money
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ~>
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: 5.1.0
|
103
|
+
type: :runtime
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
none: false
|
107
|
+
requirements:
|
108
|
+
- - ~>
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 5.1.0
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: multi_json
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ! '>='
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: 1.0.0
|
119
|
+
type: :runtime
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: 1.0.0
|
127
|
+
- !ruby/object:Gem::Dependency
|
128
|
+
name: rails
|
129
|
+
requirement: !ruby/object:Gem::Requirement
|
130
|
+
none: false
|
131
|
+
requirements:
|
132
|
+
- - ! '>'
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '3.2'
|
135
|
+
type: :runtime
|
136
|
+
prerelease: false
|
137
|
+
version_requirements: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>'
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '3.2'
|
143
|
+
description: GoogleCurrency extends Money::Bank::Base and gives you access to the
|
144
|
+
current Google Currency exchange rates. This fork allows caching of exchange rate
|
145
|
+
data in Rails.cache and removes the necessity for the Mutex.
|
146
|
+
email:
|
147
|
+
- semmons99@gmail.com
|
148
|
+
- alex@flextrip.com
|
149
|
+
executables: []
|
150
|
+
extensions: []
|
151
|
+
extra_rdoc_files: []
|
152
|
+
files:
|
153
|
+
- lib/money/bank/google_currency_rails_cache.rb
|
154
|
+
- spec/google_currency_with_json_spec.rb
|
155
|
+
- spec/google_currency_with_yajl_spec.rb
|
156
|
+
- spec/spec_helper.rb
|
157
|
+
- LICENSE
|
158
|
+
- README.md
|
159
|
+
- CHANGELOG.md
|
160
|
+
- AUTHORS
|
161
|
+
- Rakefile
|
162
|
+
- .gemtest
|
163
|
+
- google_currency_rails_cache.gemspec
|
164
|
+
homepage: http://github.com/flextrip/google_currency_rails_cache
|
165
|
+
licenses: []
|
166
|
+
post_install_message:
|
167
|
+
rdoc_options: []
|
168
|
+
require_paths:
|
169
|
+
- lib
|
170
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
171
|
+
none: false
|
172
|
+
requirements:
|
173
|
+
- - ! '>='
|
174
|
+
- !ruby/object:Gem::Version
|
175
|
+
version: '0'
|
176
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ! '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: 1.3.6
|
182
|
+
requirements: []
|
183
|
+
rubyforge_project:
|
184
|
+
rubygems_version: 1.8.25
|
185
|
+
signing_key:
|
186
|
+
specification_version: 3
|
187
|
+
summary: Access the Google Currency exchange rate data.
|
188
|
+
test_files: []
|
189
|
+
has_rdoc:
|