simple_currency 1.1.2 → 1.2.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/Gemfile CHANGED
@@ -3,7 +3,7 @@ source :gemcutter
3
3
  gem "crack"
4
4
 
5
5
  group :test do
6
- gem "rspec", ">= 2.0.0.beta.20"
6
+ gem "rspec", ">= 2.0.0.beta.22"
7
7
  gem "fakeweb"
8
8
  gem "rails"
9
9
  end
data/Gemfile.lock CHANGED
@@ -62,14 +62,16 @@ GEM
62
62
  rake (>= 0.8.4)
63
63
  thor (~> 0.14.0)
64
64
  rake (0.8.7)
65
- rspec (2.0.0.beta.20)
66
- rspec-core (= 2.0.0.beta.20)
67
- rspec-expectations (= 2.0.0.beta.20)
68
- rspec-mocks (= 2.0.0.beta.20)
69
- rspec-core (2.0.0.beta.20)
70
- rspec-expectations (2.0.0.beta.20)
65
+ rspec (2.0.0.beta.22)
66
+ rspec-core (= 2.0.0.beta.22)
67
+ rspec-expectations (= 2.0.0.beta.22)
68
+ rspec-mocks (= 2.0.0.beta.22)
69
+ rspec-core (2.0.0.beta.22)
70
+ rspec-expectations (2.0.0.beta.22)
71
71
  diff-lcs (>= 1.1.2)
72
- rspec-mocks (2.0.0.beta.20)
72
+ rspec-mocks (2.0.0.beta.22)
73
+ rspec-core (= 2.0.0.beta.22)
74
+ rspec-expectations (= 2.0.0.beta.22)
73
75
  thor (0.14.0)
74
76
  treetop (1.4.8)
75
77
  polyglot (>= 0.3.1)
@@ -83,4 +85,4 @@ DEPENDENCIES
83
85
  crack
84
86
  fakeweb
85
87
  rails
86
- rspec (>= 2.0.0.beta.20)
88
+ rspec (>= 2.0.0.beta.22)
data/README.rdoc CHANGED
@@ -1,9 +1,17 @@
1
- = simple_currency
1
+ # simple_currency
2
2
 
3
- A really simple currency converter using Xurrency and XavierMedia APIs.
3
+ A really simple currency converter using XavierMedia API.
4
4
  Compatible with Ruby 1.8, 1.9 and JRuby.
5
5
 
6
- == Usage
6
+ ## Notes
7
+
8
+ Since version 1.2, simple_currency no longer uses Xurrency API in its
9
+ background, due to restrictions on the number of daily requests. If you
10
+ would like to use it, please use the [fork by Alfonso
11
+ Jiménez](http://github.com/alfonsojimenez/simple_currency), author and
12
+ maintainer of xurrency.com service.
13
+
14
+ ## Usage
7
15
 
8
16
  Just require it and all your numeric stuff gets this fancy DSL for free:
9
17
 
@@ -29,15 +37,15 @@ in the past? Just do this:
29
37
  42.eur.at(Time.parse('2009-09-01')).to_usd
30
38
  # => 60.12
31
39
 
32
- == Installation
40
+ ## Installation
33
41
 
34
- === Rails 3
42
+ ### Rails 3
35
43
 
36
44
  In your Gemfile:
37
45
 
38
46
  gem "simple_currency"
39
47
 
40
- === Not using Rails?
48
+ ### Not using Rails?
41
49
 
42
50
  Then you have to manually install the gem:
43
51
 
@@ -47,7 +55,7 @@ And manually require it as well:
47
55
 
48
56
  require "simple_currency"
49
57
 
50
- == Note on Patches/Pull Requests
58
+ ## Note on Patches/Pull Requests
51
59
 
52
60
  * Fork the project.
53
61
  * Make your feature addition or bug fix.
@@ -58,6 +66,6 @@ And manually require it as well:
58
66
  in a commit by itself I can ignore when I pull.
59
67
  * Send me a pull request. Bonus points for topic branches.
60
68
 
61
- == Copyright
69
+ ## Copyright
62
70
 
63
71
  Copyright (c) 2010 Codegram. See LICENSE for details.
data/Rakefile CHANGED
@@ -6,8 +6,8 @@ begin
6
6
  require 'jeweler'
7
7
  Jeweler::Tasks.new do |gem|
8
8
  gem.name = "simple_currency"
9
- gem.summary = "A really simple currency converter using the Xurrency and XavierMedia APIs."
10
- gem.description = "A really simple currency converter using the Xurrency and XavierMedia APIs. It's Ruby 1.8, 1.9 and JRuby compatible, and it also takes advantage of Rails cache when available."
9
+ gem.summary = "A really simple currency converter using XavierMedia API."
10
+ gem.description = "A really simple currency converter using XavierMedia API. It's Ruby 1.8, 1.9 and JRuby compatible, and it also takes advantage of Rails cache when available."
11
11
  gem.email = "info@codegram.com"
12
12
  gem.homepage = "http://github.com/codegram/simple_currency"
13
13
  gem.authors = ["Oriol Gual", "Josep M. Bach", "Josep Jaume Rey"]
@@ -15,7 +15,7 @@ begin
15
15
  gem.add_dependency 'crack', ">= 0.1.8"
16
16
 
17
17
  gem.add_development_dependency "jeweler", '>= 1.4.0'
18
- gem.add_development_dependency "rspec", '>= 2.0.0.beta.20'
18
+ gem.add_development_dependency "rspec", '>= 2.0.0.beta.22'
19
19
  gem.add_development_dependency "fakeweb", '>= 1.3.0'
20
20
  gem.add_development_dependency "rails", '>= 3.0.0'
21
21
  gem.add_development_dependency "bundler", '>= 1.0.0'
@@ -26,7 +26,7 @@ rescue LoadError
26
26
  end
27
27
 
28
28
  # Rake RSpec2 task stuff
29
- gem 'rspec', '>= 2.0.0.beta.20'
29
+ gem 'rspec', '>= 2.0.0.beta.22'
30
30
  gem 'rspec-expectations'
31
31
 
32
32
  require 'rspec/core/rake_task'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.2
1
+ 1.2.0
@@ -1,6 +1,6 @@
1
1
  require 'open-uri'
2
2
  require 'timeout'
3
- require 'crack'
3
+ require 'crack/xml'
4
4
 
5
5
  module CurrencyConvertible
6
6
 
@@ -33,7 +33,7 @@ module CurrencyConvertible
33
33
  # 30.eur # => Calls _from and sets @original to 'eur'
34
34
  #
35
35
  def _from(currency)
36
- @exchange_date = nil
36
+ @exchange_date = Time.now.send(:to_date)
37
37
  @original = currency
38
38
  self
39
39
  end
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{simple_currency}
8
- s.version = "1.1.2"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Oriol Gual", "Josep M. Bach", "Josep Jaume Rey"]
12
- s.date = %q{2010-09-01}
13
- s.description = %q{A really simple currency converter using the Xurrency and XavierMedia APIs. It's Ruby 1.8, 1.9 and JRuby compatible, and it also takes advantage of Rails cache when available.}
12
+ s.date = %q{2010-10-03}
13
+ s.description = %q{A really simple currency converter using XavierMedia API. It's Ruby 1.8, 1.9 and JRuby compatible, and it also takes advantage of Rails cache when available.}
14
14
  s.email = %q{info@codegram.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
41
41
  s.rdoc_options = ["--charset=UTF-8"]
42
42
  s.require_paths = ["lib"]
43
43
  s.rubygems_version = %q{1.3.7}
44
- s.summary = %q{A really simple currency converter using the Xurrency and XavierMedia APIs.}
44
+ s.summary = %q{A really simple currency converter using XavierMedia API.}
45
45
  s.test_files = [
46
46
  "spec/simple_currency_spec.rb",
47
47
  "spec/spec_helper.rb"
@@ -54,14 +54,14 @@ Gem::Specification.new do |s|
54
54
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
55
  s.add_runtime_dependency(%q<crack>, [">= 0.1.8"])
56
56
  s.add_development_dependency(%q<jeweler>, [">= 1.4.0"])
57
- s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.20"])
57
+ s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.22"])
58
58
  s.add_development_dependency(%q<fakeweb>, [">= 1.3.0"])
59
59
  s.add_development_dependency(%q<rails>, [">= 3.0.0"])
60
60
  s.add_development_dependency(%q<bundler>, [">= 1.0.0"])
61
61
  else
62
62
  s.add_dependency(%q<crack>, [">= 0.1.8"])
63
63
  s.add_dependency(%q<jeweler>, [">= 1.4.0"])
64
- s.add_dependency(%q<rspec>, [">= 2.0.0.beta.20"])
64
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.22"])
65
65
  s.add_dependency(%q<fakeweb>, [">= 1.3.0"])
66
66
  s.add_dependency(%q<rails>, [">= 3.0.0"])
67
67
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
@@ -69,7 +69,7 @@ Gem::Specification.new do |s|
69
69
  else
70
70
  s.add_dependency(%q<crack>, [">= 0.1.8"])
71
71
  s.add_dependency(%q<jeweler>, [">= 1.4.0"])
72
- s.add_dependency(%q<rspec>, [">= 2.0.0.beta.20"])
72
+ s.add_dependency(%q<rspec>, [">= 2.0.0.beta.22"])
73
73
  s.add_dependency(%q<fakeweb>, [">= 1.3.0"])
74
74
  s.add_dependency(%q<rails>, [">= 3.0.0"])
75
75
  s.add_dependency(%q<bundler>, [">= 1.0.0"])
@@ -2,179 +2,82 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
3
  describe "SimpleCurrency" do
4
4
 
5
- describe "in its basic behavior" do
6
-
7
- it "enhances instances of Numeric with currency methods" do
8
- expect { 30.eur && 30.usd && 30.gbp }.to_not raise_error
9
- end
10
-
11
- it "handles zero values (by returning them straight away)" do
12
- 0.usd.to_eur.should == 0.0
13
- end
14
-
5
+ it "enhances instances of Numeric with currency methods" do
6
+ expect { 30.eur && 30.usd && 30.gbp }.to_not raise_error
15
7
  end
16
8
 
17
- context "using Xurrency API for right-now exchange" do
18
-
19
- it "returns a converted amount from one currency to another" do
20
- mock_xurrency_api('eur', 'usd', 2, 1.542)
21
- 2.eur.to_usd.should == 1.54
22
-
23
- mock_xurrency_api('gbp', 'chf', 2, 3.4874)
24
- 2.gbp.to_chf.should == 3.49
25
- end
26
-
27
- it "caches methods for faster reuse" do
28
- mock_xurrency_api('usd', 'eur', 1, 1.5)
29
-
30
- 1.usd.to_eur.should == 1.5
31
-
32
- 8.should respond_to(:usd)
33
- 8.should respond_to(:to_eur)
34
- end
35
-
36
- it "raises any error returned by the api call" do
37
- mock_xurrency_api('usd', 'xxx', 1, 1.5, :fail_with => "The currencies are not valid")
38
- mock_xurrency_api('usd', 'eur', 1_000_000_000, 1.5, :fail_with => "The amount should be between 0 and 999999999")
39
-
40
- expect {1.usd.to_xxx}.to raise_error(CurrencyNotFoundException)
41
- expect {1_000_000_000.usd.to_eur}.to_not raise_error
42
- end
43
-
44
- it "handles a negative value returning a negative as well" do
45
- mock_xurrency_api('usd', 'eur', 1, 1.5)
46
-
47
- -1.usd.to_eur.should == -1.5
48
- end
49
-
50
- it "handles big amounts" do
51
- mock_xurrency_api('usd', 'eur', 1, 1.5)
52
-
53
- 1_000_000_000.usd.to_eur.should == 1_500_000_000
54
- end
55
-
9
+ it "handles zero values (by returning them straight away)" do
10
+ 0.usd.to_eur.should == 0.0
56
11
  end
57
12
 
58
- context "using XavierMedia API for exchange with historical date" do
13
+ context "using XavierMedia API for exchange" do
59
14
 
60
- let(:the_past) { Time.parse('2010-08-25')}
61
- let(:the_ancient_past) { Time.parse('1964-08-25')}
62
-
63
- it "enhances instances of Numeric with :at method" do
64
- expect { 30.eur.at(Time.now) }.to_not raise_error
65
- expect { 30.usd.at("no date")}.to raise_error("Must use 'at' with a time or date object")
66
- expect { 30.gbp.at(:whatever_arg) }.to raise_error("Must use 'at' with a time or date object")
67
- end
15
+ let(:today) { Time.now }
68
16
 
69
17
  it "returns a converted amount from one currency to another" do
70
- mock_xavier_api(the_past)
71
- 2.eur.at(the_past).to_usd.should == 2.54
72
- 2.usd.at(the_past).to_eur.should == 1.58
73
- 2.gbp.at(the_past).to_usd.should == 3.07
74
- end
75
-
76
- it "retries yesterday and two days ago if no data found (could be a holiday)" do
77
- mock_xavier_api(the_past, :fail => true) # It's a holiday
78
- mock_xavier_api(the_past - 86400, :fail => true) # It's a holiday
79
- mock_xavier_api(the_past - 86400 - 86400) # It's a holiday
80
-
81
- 2.eur.at(the_past).to_usd.should == 2.54
82
- end
83
-
84
- it "raises an error when no data available" do
85
- mock_xavier_api(the_past, :fail => true) # It's a holiday
86
- mock_xavier_api(the_past - 86400, :fail => true) # It's a holiday
87
- mock_xavier_api(the_past - 86400 - 86400, :fail => true) # It's a holiday
88
-
89
- expect {1.usd.at(the_past).to_eur}.to raise_error("404 Not Found")
18
+ mock_xavier_api(today)
19
+ 2.eur.to_usd.should == 2.54
20
+ 2.usd.to_eur.should == 1.58
21
+ 2.gbp.to_usd.should == 3.07
90
22
  end
91
23
 
92
24
  it "raises a CurrencyNotFoundException given an invalid currency" do
93
- mock_xavier_api(the_past)
25
+ mock_xavier_api(today)
94
26
 
95
- expect {1.usd.at(the_past).to_xxx}.to raise_error(CurrencyNotFoundException)
27
+ expect {1.usd.to_xxx}.to raise_error(CurrencyNotFoundException)
96
28
  end
97
29
 
98
30
  it "raises a NoRatesFoundException if rate is 0.0 or non-existant" do
99
- mock_xavier_api(the_past)
100
-
101
- expect {1.eur.at(the_past).to_rol}.to raise_error(NoRatesFoundException)
102
- end
103
-
104
- end
105
-
106
- context "when Rails (and its cache goodness) is present" do
31
+ mock_xavier_api(today)
107
32
 
108
- let(:now) { Time.parse('2010-08-30') }
109
-
110
- before(:all) do
111
- require 'rails'
33
+ expect {1.eur.to_rol}.to raise_error(NoRatesFoundException)
112
34
  end
113
35
 
114
- context "using Xurrency API for right-now exchange" do
115
-
116
- before(:each) do
117
- Time.stub(:now).and_return(now)
118
-
119
- Rails.stub_chain("cache.read").and_return(false)
120
- Rails.stub_chain("cache.write").and_return(true)
121
- end
122
-
123
- it "reads the exchange rate from the cache" do
124
- Rails.stub_chain("cache.read").and_return(1.5)
36
+ context "in a particular historical date" do
125
37
 
126
- mock_xurrency_api('usd', 'eur', 1, 1.5)
127
- 1.usd.to_eur.should == 1.5
38
+ let(:the_past) { Time.parse('2010-08-25')}
39
+ let(:the_ancient_past) { Time.parse('1964-08-25')}
128
40
 
129
- URI.should_not_receive(:parse)
130
- 2.usd.to_eur.should == 3
41
+ it "enhances instances of Numeric with :at method" do
42
+ expect { 30.eur.at(Time.now) }.to_not raise_error
43
+ expect { 30.usd.at("no date")}.to raise_error("Must use 'at' with a time or date object")
44
+ expect { 30.gbp.at(:whatever_arg) }.to raise_error("Must use 'at' with a time or date object")
131
45
  end
132
46
 
133
- it "reads the inverse exchange rate from the cache" do
134
- Rails.stub_chain("cache.read").with('usd_eur_30-8-2010').and_return(1.5)
135
- Rails.stub_chain("cache.read").with('gbp_eur_30-8-2010').and_return(3)
136
- Rails.stub_chain("cache.read").with('gbp_usd_30-8-2010').and_return(false)
137
-
138
- mock_xurrency_api('usd', 'eur', 1, 1.5)
139
- mock_xurrency_api('gbp', 'eur', 1, 3)
140
-
141
- 1.usd.to_eur.should == 1.5
142
- 1.gbp.to_eur.should == 3
143
-
144
- URI.should_not_receive(:parse)
145
- 3.eur.to_usd.should == 2
146
- 3.eur.to_gbp.should == 1
47
+ it "returns a converted amount from one currency to another in that particular date" do
48
+ mock_xavier_api(the_past)
49
+ 2.eur.at(the_past).to_usd.should == 2.54
50
+ 2.usd.at(the_past).to_eur.should == 1.58
51
+ 2.gbp.at(the_past).to_usd.should == 3.07
147
52
  end
148
53
 
149
- it "caches the exchange rate" do
150
- Rails.stub_chain("cache.read").with('usd_eur_30-8-2010').and_return(false)
151
-
152
- Rails.cache.should_receive(:write).with('usd_eur_30-8-2010', 1.5)
54
+ it "retries yesterday and two days ago if no data found (could be a holiday)" do
55
+ mock_xavier_api(the_past, :fail => true) # It's a holiday
56
+ mock_xavier_api(the_past - 86400, :fail => true) # It's a holiday
57
+ mock_xavier_api(the_past - 86400 - 86400) # It's a holiday
153
58
 
154
- mock_xurrency_api('usd', 'eur', 1, 1.5)
155
- 1.usd.to_eur.should == 1.5
59
+ 2.eur.at(the_past).to_usd.should == 2.54
156
60
  end
157
61
 
158
- it "ensures the cache is valid only for today" do
159
- Rails.stub_chain("cache.read").with('usd_eur_30-8-2010').and_return(1.5)
62
+ it "raises an error when no data available" do
63
+ mock_xavier_api(the_past, :fail => true) # It's a holiday
64
+ mock_xavier_api(the_past - 86400, :fail => true) # It's a holiday
65
+ mock_xavier_api(the_past - 86400 - 86400, :fail => true) # It's a holiday
160
66
 
161
- mock_xurrency_api('usd', 'eur', 1, 1.5)
162
- 1.usd.to_eur.should == 1.5
163
-
164
- Time.stub(:now).and_return(now + 86400) # One day later
165
- Rails.stub_chain("cache.read").with('usd_eur_31-8-2010').and_return(nil)
166
-
167
- # Exchange rate has changed next day, so forget cache rate!
168
- mock_xurrency_api('usd', 'eur', 2, 4)
169
- 2.usd.to_eur.should == 4
67
+ expect {1.usd.at(the_past).to_eur}.to raise_error("404 Not Found")
170
68
  end
171
69
 
172
70
  end
173
71
 
174
- context "using XavierMedia API for exchange with historical date" do
72
+ context "when Rails (and its cache goodness) is present" do
175
73
 
74
+ let(:now) { Time.parse('2010-08-30') }
176
75
  let(:the_past) { Time.parse('2010-08-25') }
177
76
 
77
+ before(:all) do
78
+ require 'rails'
79
+ end
80
+
178
81
  before(:each) do
179
82
  Rails.stub_chain("cache.read").and_return(false)
180
83
  Rails.stub_chain("cache.write").and_return(true)
@@ -217,6 +120,9 @@ describe "SimpleCurrency" do
217
120
  1.eur.at(the_past).to_gbp.should == 0.82
218
121
  2.gbp.at(the_past).to_usd.should == 3.07
219
122
  end
123
+
220
124
  end
125
+
221
126
  end
127
+
222
128
  end
data/spec/spec_helper.rb CHANGED
@@ -6,7 +6,7 @@ require 'fakeweb'
6
6
 
7
7
  require 'simple_currency'
8
8
  require 'rspec'
9
- require 'rspec/autorun'
9
+ # require 'rspec/autorun' => require it back in beta.23
10
10
 
11
11
  module HelperMethods
12
12
  def fixture(name)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_currency
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 1
9
8
  - 2
10
- version: 1.1.2
9
+ - 0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Oriol Gual
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2010-09-01 00:00:00 +02:00
20
+ date: 2010-10-03 00:00:00 +02:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency
@@ -60,14 +60,14 @@ dependencies:
60
60
  requirements:
61
61
  - - ">="
62
62
  - !ruby/object:Gem::Version
63
- hash: 62196427
63
+ hash: 62196431
64
64
  segments:
65
65
  - 2
66
66
  - 0
67
67
  - 0
68
68
  - beta
69
- - 20
70
- version: 2.0.0.beta.20
69
+ - 22
70
+ version: 2.0.0.beta.22
71
71
  type: :development
72
72
  version_requirements: *id003
73
73
  - !ruby/object:Gem::Dependency
@@ -118,7 +118,7 @@ dependencies:
118
118
  version: 1.0.0
119
119
  type: :development
120
120
  version_requirements: *id006
121
- description: A really simple currency converter using the Xurrency and XavierMedia APIs. It's Ruby 1.8, 1.9 and JRuby compatible, and it also takes advantage of Rails cache when available.
121
+ description: A really simple currency converter using XavierMedia API. It's Ruby 1.8, 1.9 and JRuby compatible, and it also takes advantage of Rails cache when available.
122
122
  email: info@codegram.com
123
123
  executables: []
124
124
 
@@ -180,7 +180,7 @@ rubyforge_project:
180
180
  rubygems_version: 1.3.7
181
181
  signing_key:
182
182
  specification_version: 3
183
- summary: A really simple currency converter using the Xurrency and XavierMedia APIs.
183
+ summary: A really simple currency converter using XavierMedia API.
184
184
  test_files:
185
185
  - spec/simple_currency_spec.rb
186
186
  - spec/spec_helper.rb