exchange 0.4.4 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,18 @@
2
2
 
3
3
  The Exchange Gem gives you easy access to currency functions directly on your Numbers. It has been tested against ruby 1.8.7, ree, ruby 1.9.2 and 1.9.3. You can use it with just plain ruby projects, in Rails 2 and 3, Sinatra, Padrino or whatever Framework you like.
4
4
 
5
+ === Important Note
6
+
7
+ Since The Currency Bot API, now renamed to Open Exchange Rates API at openexchangerates.org (http://openexchangerates.org), requires an APP ID now, you should configure it using the Exchange::Configuration
8
+
9
+ Exchange::Configuration.define do |c|
10
+ c.api_app_id = 'YOUR_APP_ID'
11
+ end
12
+
13
+ Also, since it is not my intention to support paid APIs with this gem, the default API has been moved to use the Xavier Media API at xaviermedia.org. However, since Open Exchange Rates (Currency Bot) still supports a free plan, I updated the gem to be able to use it.
14
+
15
+ As a sidenote: Please be reasonable when using the APIs provided, and be sure to enable caching and mock out any http calls in your specs.
16
+
5
17
  === Easy Conversion
6
18
 
7
19
  Imagine a conversion as easy as
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.4
1
+ 0.5.1
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "exchange"
8
- s.version = "0.4.4"
8
+ s.version = "0.5.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Beat Richartz"]
12
- s.date = "2012-08-27"
12
+ s.date = "2012-10-02"
13
13
  s.description = "The Exchange Gem gives you easy access to currency functions directly on your Numbers. Imagine a conversion as easy as \n 1.eur.to_usd\n or even better \n 1.eur.to_usd(:at => Time.now - 84600)\n which gets you an exchange at the rates of yesterday."
14
14
  s.email = "exchange_gem@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -1,4 +1,4 @@
1
- EXCHANGE_GEM_ROOT_PATH = File.dirname(__FILE__).sub(/\/lib/, '') if __FILE__.is_a?(String)
1
+ EXCHANGE_GEM_ROOT_PATH = File.dirname(__FILE__).sub(/\/lib$/, '') if __FILE__.is_a?(String)
2
2
 
3
3
  require 'bigdecimal'
4
4
  require 'open-uri'
@@ -7,7 +7,7 @@ module Exchange
7
7
  # @since 0.1
8
8
  class Configuration
9
9
  class << self
10
- @@config ||= {:api => :currency_bot, :retries => 5, :filestore_path => File.expand_path('exchange_filestore'), :allow_mixed_operations => true, :cache => :memcached, :cache_host => 'localhost', :cache_port => 11211, :update => :daily}
10
+ @@config ||= {:api => :xavier_media, :retries => 5, :filestore_path => File.expand_path('exchange_filestore'), :allow_mixed_operations => true, :cache => :memcached, :cache_host => 'localhost', :cache_port => 11211, :update => :daily}
11
11
 
12
12
  # A configuration method that stores the configuration of the gem. It allows to set the api from which the data gets retrieved,
13
13
  # the cache in which the data gets cached, the regularity of updates for the currency rates, how many times the api calls should be
@@ -41,7 +41,7 @@ module Exchange
41
41
  self.instance_eval(&blk)
42
42
  end
43
43
 
44
- [:api, :retries, :cache, :cache_host, :cache_port, :filestore_path, :update, :allow_mixed_operations].each do |m|
44
+ [:api, :api_app_id, :retries, :cache, :cache_host, :cache_port, :filestore_path, :update, :allow_mixed_operations].each do |m|
45
45
  define_method m do
46
46
  @@config[m]
47
47
  end
@@ -8,7 +8,7 @@ module Exchange
8
8
 
9
9
  class CurrencyBot < Base
10
10
  # The base of the Currency Bot exchange API
11
- API_URL = 'https://raw.github.com/currencybot/open-exchange-rates/master'
11
+ API_URL = 'http://openexchangerates.org/api'
12
12
  # The currencies the Currency Bot API can convert
13
13
  CURRENCIES = %W(xcd usd sar rub nio lak nok omr amd cdf kpw cny kes zwd khr pln mvr gtq clp inr bzd myr hkd sek cop dkk byr lyd ron dzd bif ars gip bob xof std ngn pgk aed mwk cup gmd zwl tzs cve btn xaf ugx syp mad mnt lsl top shp rsd htg mga mzn lvl fkp bwp hnl eur egp chf ils pyg lbp ang kzt wst gyd thb npr kmf irr uyu srd jpy brl szl mop bmd xpf etb jod idr mdl mro yer bam awg nzd pen vef try sll aoa tnd tjs sgd scr lkr mxn ltl huf djf bsd gnf isk vuv sdg gel fjd dop xdr mur php mmk krw lrd bbd zmk zar vnd uah tmt iqd bgn gbp kgs ttd hrk rwf clf bhd uzs twd crc aud mkd pkr afn nad bdt azn czk sos iep pab qar svc sbd all jmd bnd cad kwd ghs)
14
14
 
@@ -39,7 +39,7 @@ module Exchange
39
39
 
40
40
  def api_url(time=nil)
41
41
  today = Time.now
42
- [API_URL, time && (time.year != today.year || time.yday != today.yday) ? "historical/#{time.strftime("%Y-%m-%d")}.json" : 'latest.json'].join('/')
42
+ [API_URL, time && (time.year != today.year || time.yday != today.yday) ? "historical/#{time.strftime("%Y-%m-%d")}.json?app_id=#{Exchange::Configuration.api_app_id}" : "latest.json?app_id=#{Exchange::Configuration.api_app_id}"].join('/')
43
43
  end
44
44
 
45
45
  end
@@ -4,6 +4,10 @@ describe "Exchange::Conversability" do
4
4
  before(:all) do
5
5
  Exchange::Configuration.cache = false
6
6
  end
7
+ before(:each) do
8
+ @time = Time.gm(2012,8,27)
9
+ Time.stub! :now => @time
10
+ end
7
11
  after(:all) do
8
12
  Exchange::Configuration.cache = :memcached
9
13
  end
@@ -24,15 +28,15 @@ describe "Exchange::Conversability" do
24
28
  -3.eur.value.should == -3
25
29
  end
26
30
  it "should allow to do full conversions" do
27
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 3)
31
+ mock_api("http://api.finance.xaviermedia.com/api/2012/08/27.xml", fixture('api_responses/example_xml_api.xml'), 3)
28
32
  3.eur.to_chf.should be_kind_of Exchange::Currency
29
- 3.eur.to_chf.value.round(2).should == 3.62
33
+ 3.eur.to_chf.value.round(2).should == 3.68
30
34
  3.eur.to_chf.currency.should == 'chf'
31
35
  end
32
36
  it "should allow to do full conversions with negative numbers" do
33
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 3)
37
+ mock_api("http://api.finance.xaviermedia.com/api/2012/08/27.xml", fixture('api_responses/example_xml_api.xml'), 3)
34
38
  -3.eur.to_chf.should be_kind_of Exchange::Currency
35
- -3.eur.to_chf.value.round(2).should == -3.62
39
+ -3.eur.to_chf.value.round(2).should == -3.68
36
40
  -3.eur.to_chf.currency.should == 'chf'
37
41
  end
38
42
  it "should allow to define a historic time in which the currency should be interpreted" do
@@ -51,15 +55,15 @@ describe "Exchange::Conversability" do
51
55
  -3.25.eur.value.round(2).should == -3.25
52
56
  end
53
57
  it "should allow to do full conversions" do
54
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 3)
58
+ mock_api("http://api.finance.xaviermedia.com/api/2012/08/27.xml", fixture('api_responses/example_xml_api.xml'), 3)
55
59
  3.25.eur.to_chf.should be_kind_of Exchange::Currency
56
- 3.25.eur.to_chf.value.round(2).should == 3.92
60
+ 3.25.eur.to_chf.value.round(2).should == 3.99
57
61
  3.25.eur.to_chf.currency.should == 'chf'
58
62
  end
59
63
  it "should allow to do full conversions with negative numbers" do
60
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 3)
64
+ mock_api("http://api.finance.xaviermedia.com/api/2012/08/27.xml", fixture('api_responses/example_xml_api.xml'), 3)
61
65
  -3.25.eur.to_chf.should be_kind_of Exchange::Currency
62
- -3.25.eur.to_chf.value.round(2).should == -3.92
66
+ -3.25.eur.to_chf.value.round(2).should == -3.99
63
67
  -3.25.eur.to_chf.currency.should == 'chf'
64
68
  end
65
69
  it "should allow to define a historic time in which the currency should be interpreted" do
@@ -78,15 +82,15 @@ describe "Exchange::Conversability" do
78
82
  BigDecimal.new("-3.25").eur.value.round(2).should == -3.25
79
83
  end
80
84
  it "should allow to do full conversions" do
81
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 3)
85
+ mock_api("http://api.finance.xaviermedia.com/api/2012/08/27.xml", fixture('api_responses/example_xml_api.xml'), 3)
82
86
  BigDecimal.new("3.25").eur.to_chf.should be_kind_of Exchange::Currency
83
- BigDecimal.new("3.25").eur.to_chf.value.round(2).should == 3.92
87
+ BigDecimal.new("3.25").eur.to_chf.value.round(2).should == 3.99
84
88
  BigDecimal.new("3.25").eur.to_chf.currency.should == 'chf'
85
89
  end
86
90
  it "should allow to do full conversions with negative numbers" do
87
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 3)
91
+ mock_api("http://api.finance.xaviermedia.com/api/2012/08/27.xml", fixture('api_responses/example_xml_api.xml'), 3)
88
92
  BigDecimal.new("-3.25").eur.to_chf.should be_kind_of Exchange::Currency
89
- BigDecimal.new("-3.25").eur.to_chf.value.round(2).should == -3.92
93
+ BigDecimal.new("-3.25").eur.to_chf.value.round(2).should == -3.99
90
94
  BigDecimal.new("-3.25").eur.to_chf.currency.should == 'chf'
91
95
  end
92
96
  it "should allow to define a historic time in which the currency should be interpreted" do
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe "Exchange::Configuration" do
4
4
  let(:subject) { Exchange::Configuration }
5
5
  it "should have a standard configuration" do
6
- subject.api.should == :currency_bot
7
- subject.api_class.should == Exchange::ExternalAPI::CurrencyBot
6
+ subject.api.should == :xavier_media
7
+ subject.api_class.should == Exchange::ExternalAPI::XavierMedia
8
8
  subject.cache.should == :memcached
9
9
  subject.cache_class.should == Exchange::Cache::Memcached
10
10
  subject.cache_host.should == 'localhost'
@@ -17,7 +17,7 @@ describe "Exchange::Currency" do
17
17
  end
18
18
  describe "convert_to" do
19
19
  it "should be able to convert itself to other currencies" do
20
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 3)
20
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 3)
21
21
  subject.convert_to(:chf).value.round(2).should == 36.5
22
22
  subject.convert_to(:chf).currency.should == :chf
23
23
  subject.convert_to(:chf).should be_kind_of Exchange::Currency
@@ -32,7 +32,7 @@ describe "Exchange::Currency" do
32
32
  (subject + 40.5).value.should == 80.5
33
33
  end
34
34
  it "should be able to add another currency value" do
35
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 2)
35
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
36
36
  (subject + Exchange::Currency.new(30, :chf)).value.round(2).should == 72.87
37
37
  (subject + Exchange::Currency.new(30, :sek)).currency.should == :usd
38
38
  end
@@ -43,7 +43,7 @@ describe "Exchange::Currency" do
43
43
  end
44
44
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
45
45
  Exchange::Configuration.allow_mixed_operations = false
46
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 2)
46
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
47
47
  lambda { subject + Exchange::Currency.new(30, :usd) }.should_not raise_error
48
48
  Exchange::Configuration.allow_mixed_operations = true
49
49
  end
@@ -56,7 +56,7 @@ describe "Exchange::Currency" do
56
56
  (subject + 40.5).value.should == 80.5
57
57
  end
58
58
  it "should be able to subtract another currency value" do
59
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 2)
59
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
60
60
  (subject + Exchange::Currency.new(10, :chf)).value.round(2).should == 50.96
61
61
  (subject + Exchange::Currency.new(23.3, :eur)).currency.should == :usd
62
62
  end
@@ -67,7 +67,7 @@ describe "Exchange::Currency" do
67
67
  end
68
68
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
69
69
  Exchange::Configuration.allow_mixed_operations = false
70
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 2)
70
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
71
71
  lambda { subject - Exchange::Currency.new(30, :usd) }.should_not raise_error
72
72
  Exchange::Configuration.allow_mixed_operations = true
73
73
  end
@@ -80,7 +80,7 @@ describe "Exchange::Currency" do
80
80
  (subject * 40.5).value.should == 1620
81
81
  end
82
82
  it "should be able to multiply by another currency value" do
83
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 2)
83
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
84
84
  (subject * Exchange::Currency.new(10, :chf)).value.round(1).should == 438.3
85
85
  (subject * Exchange::Currency.new(23.3, :eur)).currency.should == :usd
86
86
  end
@@ -91,7 +91,7 @@ describe "Exchange::Currency" do
91
91
  end
92
92
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
93
93
  Exchange::Configuration.allow_mixed_operations = false
94
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 2)
94
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
95
95
  lambda { subject * Exchange::Currency.new(30, :usd) }.should_not raise_error
96
96
  Exchange::Configuration.allow_mixed_operations = true
97
97
  end
@@ -104,7 +104,7 @@ describe "Exchange::Currency" do
104
104
  BigDecimal.new((subject / 40.5).value.to_s).round(4).should == 0.9877
105
105
  end
106
106
  it "should be able to multiply by another currency value" do
107
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 2)
107
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
108
108
  (subject / Exchange::Currency.new(10, :chf)).value.round(2).should == BigDecimal.new("3.65")
109
109
  (subject / Exchange::Currency.new(23.3, :eur)).currency.should == :usd
110
110
  end
@@ -115,7 +115,7 @@ describe "Exchange::Currency" do
115
115
  end
116
116
  it "should not raise when currencies get mixed and the configuration does not allow if the other currency is the same" do
117
117
  Exchange::Configuration.allow_mixed_operations = false
118
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 2)
118
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
119
119
  lambda { subject / Exchange::Currency.new(30, :usd) }.should_not raise_error
120
120
  Exchange::Configuration.allow_mixed_operations = true
121
121
  end
@@ -129,7 +129,7 @@ describe "Exchange::Currency" do
129
129
  let(:comp5) { Exchange::Currency.new(50, :eur).to_usd }
130
130
  let(:comp6) { Exchange::Currency.new(66.1, :usd, :at => Time.gm(2011,1,1)) }
131
131
  before(:each) do
132
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 2)
132
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
133
133
  end
134
134
  context "with identical currencies" do
135
135
  it "should be true if the currency and the value is the same" do
@@ -147,7 +147,7 @@ describe "Exchange::Currency" do
147
147
  (subject == comp4).should be_false
148
148
  end
149
149
  it "should be false if the currency is defined historic and the converted value is different" do
150
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/historical/2011-01-01.json", fixture('api_responses/example_historic_json.json'), 2)
150
+ mock_api("http://openexchangerates.org/api/historical/2011-01-01.json?app_id=", fixture('api_responses/example_historic_json.json'), 2)
151
151
  (comp3 == comp6).should be_false
152
152
  end
153
153
  end
@@ -159,7 +159,7 @@ describe "Exchange::Currency" do
159
159
  let(:comp3) { Exchange::Currency.new(50, :eur) }
160
160
  let(:comp4) { Exchange::Currency.new(45, :eur) }
161
161
  before(:each) do
162
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 6)
162
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 6)
163
163
  end
164
164
  it "should sort and by doing conversions" do
165
165
  [subject, comp1, comp2, comp3, comp4].sort.should == [comp2, subject, comp1, comp4, comp3]
@@ -252,7 +252,7 @@ describe "Exchange::Currency" do
252
252
  end
253
253
  describe "methods via method missing" do
254
254
  it "should be able to convert via to_currency to other currencies" do
255
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'), 6)
255
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'), 6)
256
256
  {'chf' => 36.5, 'usd' => 40.0, 'dkk' => 225.12, 'sek' => 269.85, 'nok' => 232.06, 'rub' => 1205.24}.each do |currency, value|
257
257
  c = subject.send(:"to_#{currency}")
258
258
  c.value.round(2).should == value
@@ -260,7 +260,7 @@ describe "Exchange::Currency" do
260
260
  end
261
261
  end
262
262
  it "should be able to convert via to_currency to other currencies and use historic data" do
263
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/historical/2011-10-09.json", fixture('api_responses/example_json_api.json'), 6)
263
+ mock_api("http://openexchangerates.org/api/historical/2011-10-09.json?app_id=", fixture('api_responses/example_json_api.json'), 6)
264
264
  {'chf' => 36.5, 'usd' => 40.0, 'dkk' => 225.12, 'sek' => 269.85, 'nok' => 232.06, 'rub' => 1205.24}.each do |currency, value|
265
265
  c = subject.send(:"to_#{currency}", :at => Time.gm(2011,10,9))
266
266
  c.value.round(2).should == value
@@ -268,7 +268,7 @@ describe "Exchange::Currency" do
268
268
  end
269
269
  end
270
270
  it "should use the own time if defined as historic to convert" do
271
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/historical/2011-01-01.json", fixture('api_responses/example_json_api.json'), 2)
271
+ mock_api("http://openexchangerates.org/api/historical/2011-01-01.json?app_id=", fixture('api_responses/example_json_api.json'), 2)
272
272
  5.eur(:at => Time.gm(2011,1,1)).to_usd.value.should == 5.eur.to_usd(:at => Time.gm(2011,1,1)).value
273
273
  end
274
274
  it "should raise errors for currency conversions it does not have rates for" do
@@ -7,7 +7,7 @@ describe "Exchange::ExternalAPI::CurrencyBot" do
7
7
  describe "updating rates" do
8
8
  subject { Exchange::ExternalAPI::CurrencyBot.new }
9
9
  before(:each) do
10
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'))
10
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'))
11
11
  end
12
12
  it "should call the api and yield a block with the result" do
13
13
  subject.update
@@ -21,7 +21,7 @@ describe "Exchange::ExternalAPI::CurrencyBot" do
21
21
  describe "conversion" do
22
22
  subject { Exchange::ExternalAPI::CurrencyBot.new }
23
23
  before(:each) do
24
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/latest.json", fixture('api_responses/example_json_api.json'))
24
+ mock_api("http://openexchangerates.org/api/latest.json?app_id=", fixture('api_responses/example_json_api.json'))
25
25
  end
26
26
  it "should convert right" do
27
27
  subject.convert(78, 'eur', 'usd').round(2).should == BigDecimal.new("103.12")
@@ -36,23 +36,23 @@ describe "Exchange::ExternalAPI::CurrencyBot" do
36
36
  describe "historic conversion" do
37
37
  subject { Exchange::ExternalAPI::CurrencyBot.new }
38
38
  it "should convert and be able to use history" do
39
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/historical/2011-09-09.json", fixture('api_responses/example_json_api.json'))
39
+ mock_api("http://openexchangerates.org/api/historical/2011-09-09.json?app_id=", fixture('api_responses/example_json_api.json'))
40
40
  subject.convert(72, 'eur', 'usd', :at => Time.gm(2011,9,9)).round(2).should == BigDecimal.new("95.19")
41
41
  end
42
42
  it "should convert negative numbers right" do
43
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/historical/2011-09-09.json", fixture('api_responses/example_json_api.json'))
43
+ mock_api("http://openexchangerates.org/api/historical/2011-09-09.json?app_id=", fixture('api_responses/example_json_api.json'))
44
44
  subject.convert(-70, 'chf', 'usd', :at => Time.gm(2011,9,9)).round(2).should == BigDecimal.new("-76.71")
45
45
  end
46
46
  it "should convert when given symbols" do
47
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/historical/2011-09-09.json", fixture('api_responses/example_json_api.json'))
47
+ mock_api("http://openexchangerates.org/api/historical/2011-09-09.json?app_id=", fixture('api_responses/example_json_api.json'))
48
48
  subject.convert(70, :sek, :usd, :at => Time.gm(2011,9,9)).round(2).should == 10.38
49
49
  end
50
50
  it "should convert right when the year is the same, but the yearday is not" do
51
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/historical/#{Time.now.year}-0#{Time.now.month > 10 ? Time.now.month - 1 : Time.now.month + 1}-01.json", fixture('api_responses/example_json_api.json'))
51
+ mock_api("http://openexchangerates.org/api/historical/#{Time.now.year}-0#{Time.now.month > 9 ? Time.now.month - 1 : Time.now.month + 1}-01.json?app_id=", fixture('api_responses/example_json_api.json'))
52
52
  subject.convert(70, :sek, :usd, :at => Time.gm(Time.now.year,Time.now.month > 9 ? Time.now.month - 1 : Time.now.month + 1,1)).round(2).should == 10.38
53
53
  end
54
54
  it "should convert right when the yearday is the same, but the year is not" do
55
- mock_api("https://raw.github.com/currencybot/open-exchange-rates/master/historical/#{Time.now.year-1}-03-01.json", fixture('api_responses/example_json_api.json'))
55
+ mock_api("http://openexchangerates.org/api/historical/#{Time.now.year-1}-03-01.json?app_id=", fixture('api_responses/example_json_api.json'))
56
56
  subject.convert(70, :sek, :usd, :at => Time.gm(Time.now.year - 1,3,1)).round(2).should == 10.38
57
57
  end
58
58
  end
@@ -48,7 +48,7 @@ describe "Exchange::ExternalAPI::XavierMedia" do
48
48
  subject.convert(70, :sek, :usd, :at => Time.gm(2011,9,9)).round(2).should == 10.35
49
49
  end
50
50
  it "should convert right when the year is the same, but the yearday is not" do
51
- mock_api("http://api.finance.xaviermedia.com/api/#{Time.now.year}/0#{Time.now.month > 10 ? Time.now.month - 1 : Time.now.month + 1}/01.xml", fixture('api_responses/example_xml_api.xml'))
51
+ mock_api("http://api.finance.xaviermedia.com/api/#{Time.now.year}/0#{Time.now.month > 9 ? Time.now.month - 1 : Time.now.month + 1}/01.xml", fixture('api_responses/example_xml_api.xml'))
52
52
  subject.convert(70, :sek, :usd, :at => Time.gm(Time.now.year,Time.now.month > 9 ? Time.now.month - 1 : Time.now.month + 1,1)).round(2).should == 10.35
53
53
  end
54
54
  it "should convert right when the yearday is the same, but the year is not" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: exchange
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-27 00:00:00.000000000 Z
12
+ date: 2012-10-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -235,7 +235,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
235
235
  version: '0'
236
236
  segments:
237
237
  - 0
238
- hash: -3799841316475885558
238
+ hash: -1271993619830329119
239
239
  required_rubygems_version: !ruby/object:Gem::Requirement
240
240
  none: false
241
241
  requirements: