google_currency 2.3.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/AUTHORS CHANGED
@@ -1,4 +1,5 @@
1
1
  andersonbrandon
2
+ cover
2
3
  Donald Ball
3
4
  Daniel Doubrovkine
4
5
  James Chen
@@ -1,6 +1,7 @@
1
- master
2
- ======
1
+ 3.0.0
2
+ =====
3
3
 
4
+ - Google closed ig/calculator, so we're now using finance/calculator
4
5
  - fix incorrect parsing of complex rates
5
6
 
6
7
  Google Currency 2.2.0
data/README.md CHANGED
@@ -6,18 +6,16 @@ Google Currency
6
6
  This gem extends Money::Bank::VariableExchange with Money::Bank::GoogleCurrency
7
7
  and gives you access to the current Google Currency exchange rates.
8
8
 
9
- You have to load one of the JSON libraries supported by
10
- [MultiJSON](https://github.com/intridea/multi_json) (`json` for example)
11
- if it's not already loaded by your application. In a Rails application,
12
- ActiveSupport provides a JSON implementation that is automatically recognized.
13
-
14
9
  Usage
15
10
  -----
16
11
 
17
12
  require 'money'
18
13
  require 'money/bank/google_currency'
19
- require 'json'
20
- MultiJson.engine = :json_gem # or :yajl
14
+
15
+ # (optional)
16
+ # set the seconds after than the current rates are automatically expired
17
+ # by default, they never expire
18
+ Money::Bank::GoogleCurrency.ttl_in_seconds = 86400
21
19
 
22
20
  # set default bank to instance of GoogleCurrency
23
21
  Money.default_bank = Money::Bank::GoogleCurrency.new
@@ -32,6 +30,8 @@ that `Money` knows, but Google does not.
32
30
  An `UnknownCurrency` will be thrown if `#exchange_to` is called with a
33
31
  `Currency` that `Money` does not know.
34
32
 
33
+ A `GoogleCurrencyFetchError` will be thrown if there is an unknown issue with the Google Finance Converter API.
34
+
35
35
  Copyright
36
36
  ---------
37
37
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "google_currency"
3
- s.version = "2.3.0"
3
+ s.version = "3.0.0"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ["Shane Emmons"]
6
6
  s.email = ["semmons99@gmail.com"]
@@ -12,11 +12,9 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.add_development_dependency "rspec", ">= 2.0.0"
14
14
  s.add_development_dependency "yard", ">= 0.5.8"
15
- s.add_development_dependency "json", ">= 1.4.0"
16
15
  s.add_development_dependency "ffi"
17
16
 
18
17
  s.add_dependency "money", "~> 5.1.1"
19
- s.add_dependency "multi_json"
20
18
 
21
19
  s.files = Dir.glob("{lib,spec}/**/*")
22
20
  s.files += %w(LICENSE README.md CHANGELOG.md AUTHORS)
@@ -1,18 +1,48 @@
1
1
  require 'money'
2
2
  require 'open-uri'
3
- require 'multi_json'
4
3
 
5
4
  class Money
6
5
  module Bank
6
+ # Raised when there is an unexpected error in extracting exchange rates
7
+ # from Google Finance Calculator
8
+ class GoogleCurrencyFetchError < Error
9
+ end
10
+
7
11
  class GoogleCurrency < Money::Bank::VariableExchange
8
12
 
13
+
9
14
  SERVICE_HOST = "www.google.com"
10
- SERVICE_PATH = "/ig/calculator"
11
- EXPONENT_REGEXP = /10(x3c)?sup(x3e)?(?<exponent>-?\d+)(x3c)?\/sup(x3e)?/
15
+ SERVICE_PATH = "/finance/converter"
12
16
 
13
17
  # @return [Hash] Stores the currently known rates.
14
18
  attr_reader :rates
15
19
 
20
+
21
+ class << self
22
+ # @return [Integer] Returns the Time To Live (TTL) in seconds.
23
+ attr_reader :ttl_in_seconds
24
+
25
+ # @return [Time] Returns the time when the rates expire.
26
+ attr_reader :rates_expiration
27
+
28
+ ##
29
+ # Set the Time To Live (TTL) in seconds.
30
+ #
31
+ # @param [Integer] the seconds between an expiration and another.
32
+ def ttl_in_seconds=(value)
33
+ @ttl_in_seconds = value
34
+ refresh_rates_expiration! if ttl_in_seconds
35
+ end
36
+
37
+ ##
38
+ # Set the rates expiration TTL seconds from the current time.
39
+ #
40
+ # @return [Time] The next expiration.
41
+ def refresh_rates_expiration!
42
+ @rates_expiration = Time.now + ttl_in_seconds
43
+ end
44
+ end
45
+
16
46
  ##
17
47
  # Clears all rates stored in @rates
18
48
  #
@@ -52,6 +82,8 @@ class Money
52
82
  ##
53
83
  # Returns the requested rate.
54
84
  #
85
+ # It also flushes all the rates when and if they are expired.
86
+ #
55
87
  # @param [String, Symbol, Currency] from Currency to convert from
56
88
  # @param [String, Symbol, Currency] to Currency to convert to
57
89
  #
@@ -61,11 +93,27 @@ class Money
61
93
  # @bank = GoogleCurrency.new #=> <Money::Bank::GoogleCurrency...>
62
94
  # @bank.get_rate(:USD, :EUR) #=> 0.776337241
63
95
  def get_rate(from, to)
96
+ expire_rates
97
+
64
98
  @mutex.synchronize{
65
99
  @rates[rate_key_for(from, to)] ||= fetch_rate(from, to)
66
100
  }
67
101
  end
68
102
 
103
+ ##
104
+ # Flushes all the rates if they are expired.
105
+ #
106
+ # @return [Boolean]
107
+ def expire_rates
108
+ if self.class.ttl_in_seconds && self.class.rates_expiration <= Time.now
109
+ flush_rates
110
+ self.class.refresh_rates_expiration!
111
+ true
112
+ else
113
+ false
114
+ end
115
+ end
116
+
69
117
  private
70
118
 
71
119
  ##
@@ -77,13 +125,8 @@ class Money
77
125
  # @return [BigDecimal] The requested rate.
78
126
  def fetch_rate(from, to)
79
127
  from, to = Currency.wrap(from), Currency.wrap(to)
80
-
81
128
  data = build_uri(from, to).read
82
- data = fix_response_json_data(data)
83
-
84
- error = data['error']
85
- raise UnknownRate unless error == '' || error == '0'
86
- decode_rate data['rhs']
129
+ extract_rate(data)
87
130
  end
88
131
 
89
132
  ##
@@ -97,76 +140,26 @@ class Money
97
140
  uri = URI::HTTP.build(
98
141
  :host => SERVICE_HOST,
99
142
  :path => SERVICE_PATH,
100
- :query => "hl=en&q=1#{from.iso_code}%3D%3F#{to.iso_code}"
143
+ :query => "a=1&from=#{from.iso_code}&to=#{to.iso_code}"
101
144
  )
102
145
  end
103
146
 
104
147
  ##
105
- # Takes the invalid JSON returned by Google and fixes it.
106
- #
107
- # @param [String] data The JSON string to fix.
108
- #
109
- # @return [Hash]
110
- def fix_response_json_data(data)
111
- data = data.force_encoding("ISO-8859-1").encode("UTF-8")
112
-
113
- data.gsub!(/lhs:/, '"lhs":')
114
- data.gsub!(/rhs:/, '"rhs":')
115
- data.gsub!(/error:/, '"error":')
116
- data.gsub!(/icc:/, '"icc":')
117
- data.gsub!(Regexp.new("(\\\\x..|\\\\240)"), '')
118
-
119
- MultiJson.decode(data)
120
- end
121
-
122
- ##
123
- # Takes the 'rhs' response from Google and decodes it.
148
+ # Takes the response from Google and extract the rate.
124
149
  #
125
- # @param [String] rhs The google rate string to decode.
150
+ # @param [String] data The google rate string to decode.
126
151
  #
127
152
  # @return [BigDecimal]
128
- def decode_rate(rhs)
129
- if complex_rate?(rhs)
130
- decode_complex_rate(rhs)
153
+ def extract_rate(data)
154
+ case data
155
+ when /<span class=bld>(\d+\.?\d*) [A-Z]{3}<\/span>/
156
+ BigDecimal($1)
157
+ when /Could not convert\./
158
+ raise UnknownRate
131
159
  else
132
- decode_basic_rate(rhs)
160
+ raise GoogleCurrencyFetchError
133
161
  end
134
162
  end
135
-
136
- ##
137
- # Takes the 'rhs' response from Google and decides if it's a complex rate
138
- #
139
- # @param [String] rhs The google rate string to check.
140
- #
141
- # @return [Boolean]
142
- def complex_rate?(rhs)
143
- rhs.match(EXPONENT_REGEXP)
144
- end
145
-
146
- ##
147
- # Takes a complex 'rhs' response from Google and converts it to a numeric
148
- # rate.
149
- #
150
- # @param [String] rhs The complex google rate string to convert.
151
- #
152
- # @return [BigDecimal]
153
- def decode_complex_rate(rhs)
154
- rate = BigDecimal(rhs.match(/\d[\d\s]*\.?\d*/)[0])
155
- power = rhs.match(EXPONENT_REGEXP)
156
-
157
- rate * BigDecimal("1E#{power[:exponent]}")
158
- end
159
-
160
- ##
161
- # Takes a basic 'rhs' response from Google and converts it to a numeric
162
- # rate.
163
- #
164
- # @param [String] rhs The basic google rate string to convert.
165
- #
166
- # @return [BigDecimal]
167
- def decode_basic_rate(rhs)
168
- BigDecimal(rhs.gsub(/[^\d\.]/, ''))
169
- end
170
163
  end
171
164
  end
172
165
  end
@@ -3,15 +3,32 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  require 'money'
4
4
  require 'money/bank/google_currency'
5
5
 
6
- require 'json'
7
- MultiJson.engine = :json_gem
8
-
9
6
  describe "GoogleCurrency" do
10
7
  before :each do
11
8
  @bank = Money::Bank::GoogleCurrency.new
12
9
  end
13
10
 
11
+ it "should accept a ttl_in_seconds option" do
12
+ Money::Bank::GoogleCurrency.ttl_in_seconds = 86400
13
+ Money::Bank::GoogleCurrency.ttl_in_seconds.should eql(86400)
14
+ end
15
+
16
+ describe ".refresh_rates_expiration!" do
17
+ it "set the #rates_expiration using the TTL and the current time" do
18
+ Money::Bank::GoogleCurrency.ttl_in_seconds = 86400
19
+ new_time = Time.now
20
+ Timecop.freeze(new_time)
21
+ Money::Bank::GoogleCurrency.refresh_rates_expiration!
22
+ Money::Bank::GoogleCurrency.rates_expiration.should eql(new_time + 86400)
23
+ end
24
+ end
25
+
14
26
  describe "#get_rate" do
27
+ it "should try to expire the rates" do
28
+ @bank.should_receive(:expire_rates).once
29
+ @bank.get_rate('USD', 'USD')
30
+ end
31
+
15
32
  it "should use #fetch_rate when rate is unknown" do
16
33
  @bank.should_receive(:fetch_rate).once
17
34
  @bank.get_rate('USD', 'USD')
@@ -38,15 +55,23 @@ describe "GoogleCurrency" do
38
55
  @bank.stub(:build_uri){ |from,to| @uri }
39
56
  end
40
57
 
41
- it "Vietnamese Dong" do
42
- # rhs decodes (after html entity decoding) to "4.8 x 10<sup>-5</sup> U.S. dollars"
43
- @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}) }
44
- @bank.get_rate('VND', 'USD').should == BigDecimal("4.8E-5")
58
+ it "should return rate when it is known" do
59
+ @uri.stub(:read) { load_rate_http_response("sgd_to_usd") }
60
+ @bank.get_rate('SGD', 'USD').should == BigDecimal("0.8066")
61
+ end
62
+
63
+ it "should raise UnknownRate error when rate is not known" do
64
+ @uri.stub(:read) { load_rate_http_response("vnd_to_usd") }
65
+ expect {
66
+ @bank.get_rate('VND', 'USD')
67
+ }.to raise_error(Money::Bank::UnknownRate)
45
68
  end
46
69
 
47
- it "Indonesian Rupiah" do
48
- @uri.stub(:read) { "{lhs: \"1 U.S. dollar\",rhs: \"10\xA0000 Indonesian rupiahs\",error: \"\",icc: true}" }
49
- @bank.get_rate('IDR', 'USD').should == BigDecimal("0.1E5")
70
+ it "should raise GoogleCurrencyFetchError there is an unknown issue with extracting the exchange rate" do
71
+ @uri.stub(:read) { load_rate_http_response("error") }
72
+ expect {
73
+ @bank.get_rate('VND', 'USD')
74
+ }.to raise_error(Money::Bank::GoogleCurrencyFetchError)
50
75
  end
51
76
  end
52
77
  end
@@ -68,4 +93,36 @@ describe "GoogleCurrency" do
68
93
  @bank.rates.should_not include('USD_TO_EUR')
69
94
  end
70
95
  end
96
+
97
+ describe "#expire_rates" do
98
+ before do
99
+ Money::Bank::GoogleCurrency.ttl_in_seconds = 1000
100
+ end
101
+
102
+ context "when the ttl has expired" do
103
+ before do
104
+ new_time = Time.now + 1001
105
+ Timecop.freeze(new_time)
106
+ end
107
+
108
+ it "should flush all rates" do
109
+ @bank.should_receive(:flush_rates)
110
+ @bank.expire_rates
111
+ end
112
+
113
+ it "updates the next expiration time" do
114
+ exp_time = Time.now + 1000
115
+
116
+ @bank.expire_rates
117
+ Money::Bank::GoogleCurrency.rates_expiration.should eql(exp_time)
118
+ end
119
+ end
120
+
121
+ context "when the ttl has not expired" do
122
+ it "not should flush all rates" do
123
+ @bank.should_not_receive(:flush_rates)
124
+ @bank.expire_rates
125
+ end
126
+ end
127
+ end
71
128
  end
@@ -0,0 +1 @@
1
+ Something went wrong.
@@ -0,0 +1,222 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html>
3
+ <head>
4
+ <title>Currency Converter - Google Finance</title>
5
+ <meta name="Description" content="Get real-time stock quotes & charts, financial news, currency conversions, or track your portfolio with Google Finance.">
6
+ <link rel="stylesheet" type="text/css" href="/finance/s/Jtl56e5m90s/styles/finance_us.css">
7
+ <link rel="icon"
8
+ type="image/vnd.microsoft.icon" href="/finance/favicon.ico"></head>
9
+ <body style="margin-left: 6px; min-width: 0px;">
10
+ <div class=g-doc>
11
+ <form action="/finance/converter" method="get" name="f">
12
+ <div class=sfe-break-top>
13
+ <input name=a maxlength=12 size=5 autocomplete=off value="1">
14
+ </div>
15
+ <div class=sfe-break-top>
16
+ <select name=from value="SGD">
17
+ <option value="AED">United Arab Emirates Dirham (AED)</option>
18
+ <option value="ANG">Netherlands Antillean Guilder (ANG)</option>
19
+ <option value="ARS">Argentine Peso (ARS)</option>
20
+ <option value="AUD">Australian Dollar (A$)</option>
21
+ <option value="BDT">Bangladeshi Taka (BDT)</option>
22
+ <option value="BGN">Bulgarian Lev (BGN)</option>
23
+ <option value="BHD">Bahraini Dinar (BHD)</option>
24
+ <option value="BND">Brunei Dollar (BND)</option>
25
+ <option value="BOB">Bolivian Boliviano (BOB)</option>
26
+ <option value="BRL">Brazilian Real (R$)</option>
27
+ <option value="BWP">Botswanan Pula (BWP)</option>
28
+ <option value="CAD">Canadian Dollar (CA$)</option>
29
+ <option value="CHF">Swiss Franc (CHF)</option>
30
+ <option value="CLP">Chilean Peso (CLP)</option>
31
+ <option value="CNY">Chinese Yuan (CN�)</option>
32
+ <option value="COP">Colombian Peso (COP)</option>
33
+ <option value="CRC">Costa Rican Col�n (CRC)</option>
34
+ <option value="CZK">Czech Republic Koruna (CZK)</option>
35
+ <option value="DKK">Danish Krone (DKK)</option>
36
+ <option value="DOP">Dominican Peso (DOP)</option>
37
+ <option value="DZD">Algerian Dinar (DZD)</option>
38
+ <option value="EEK">Estonian Kroon (EEK)</option>
39
+ <option value="EGP">Egyptian Pound (EGP)</option>
40
+ <option value="EUR">Euro (�)</option>
41
+ <option value="FJD">Fijian Dollar (FJD)</option>
42
+ <option value="GBP">British Pound Sterling (�)</option>
43
+ <option value="HKD">Hong Kong Dollar (HK$)</option>
44
+ <option value="HNL">Honduran Lempira (HNL)</option>
45
+ <option value="HRK">Croatian Kuna (HRK)</option>
46
+ <option value="HUF">Hungarian Forint (HUF)</option>
47
+ <option value="IDR">Indonesian Rupiah (IDR)</option>
48
+ <option value="ILS">Israeli New Sheqel (&#8362;)</option>
49
+ <option value="INR">Indian Rupee (Rs.)</option>
50
+ <option value="JMD">Jamaican Dollar (JMD)</option>
51
+ <option value="JOD">Jordanian Dinar (JOD)</option>
52
+ <option value="JPY">Japanese Yen (�)</option>
53
+ <option value="KES">Kenyan Shilling (KES)</option>
54
+ <option value="KRW">South Korean Won (&#8361;)</option>
55
+ <option value="KWD">Kuwaiti Dinar (KWD)</option>
56
+ <option value="KYD">Cayman Islands Dollar (KYD)</option>
57
+ <option value="KZT">Kazakhstani Tenge (KZT)</option>
58
+ <option value="LBP">Lebanese Pound (LBP)</option>
59
+ <option value="LKR">Sri Lankan Rupee (LKR)</option>
60
+ <option value="LTL">Lithuanian Litas (LTL)</option>
61
+ <option value="LVL">Latvian Lats (LVL)</option>
62
+ <option value="MAD">Moroccan Dirham (MAD)</option>
63
+ <option value="MDL">Moldovan Leu (MDL)</option>
64
+ <option value="MKD">Macedonian Denar (MKD)</option>
65
+ <option value="MUR">Mauritian Rupee (MUR)</option>
66
+ <option value="MVR">Maldivian Rufiyaa (MVR)</option>
67
+ <option value="MXN">Mexican Peso (MX$)</option>
68
+ <option value="MYR">Malaysian Ringgit (MYR)</option>
69
+ <option value="NAD">Namibian Dollar (NAD)</option>
70
+ <option value="NGN">Nigerian Naira (NGN)</option>
71
+ <option value="NIO">Nicaraguan C�rdoba (NIO)</option>
72
+ <option value="NOK">Norwegian Krone (NOK)</option>
73
+ <option value="NPR">Nepalese Rupee (NPR)</option>
74
+ <option value="NZD">New Zealand Dollar (NZ$)</option>
75
+ <option value="OMR">Omani Rial (OMR)</option>
76
+ <option value="PEN">Peruvian Nuevo Sol (PEN)</option>
77
+ <option value="PGK">Papua New Guinean Kina (PGK)</option>
78
+ <option value="PHP">Philippine Peso (Php)</option>
79
+ <option value="PKR">Pakistani Rupee (PKR)</option>
80
+ <option value="PLN">Polish Zloty (PLN)</option>
81
+ <option value="PYG">Paraguayan Guarani (PYG)</option>
82
+ <option value="QAR">Qatari Rial (QAR)</option>
83
+ <option value="RON">Romanian Leu (RON)</option>
84
+ <option value="RSD">Serbian Dinar (RSD)</option>
85
+ <option value="RUB">Russian Ruble (RUB)</option>
86
+ <option value="SAR">Saudi Riyal (SAR)</option>
87
+ <option value="SCR">Seychellois Rupee (SCR)</option>
88
+ <option value="SEK">Swedish Krona (SEK)</option>
89
+ <option SELECTED value="SGD">Singapore Dollar (SGD)</option>
90
+ <option value="SKK">Slovak Koruna (SKK)</option>
91
+ <option value="SLL">Sierra Leonean Leone (SLL)</option>
92
+ <option value="SVC">Salvadoran Col�n (SVC)</option>
93
+ <option value="THB">Thai Baht (&#3647;)</option>
94
+ <option value="TND">Tunisian Dinar (TND)</option>
95
+ <option value="TRY">Turkish Lira (TRY)</option>
96
+ <option value="TTD">Trinidad and Tobago Dollar (TTD)</option>
97
+ <option value="TWD">New Taiwan Dollar (NT$)</option>
98
+ <option value="TZS">Tanzanian Shilling (TZS)</option>
99
+ <option value="UAH">Ukrainian Hryvnia (UAH)</option>
100
+ <option value="UGX">Ugandan Shilling (UGX)</option>
101
+ <option value="USD">US Dollar ($)</option>
102
+ <option value="UYU">Uruguayan Peso (UYU)</option>
103
+ <option value="UZS">Uzbekistan Som (UZS)</option>
104
+ <option value="VEF">Venezuelan Bol�var (VEF)</option>
105
+ <option value="VND">Vietnamese Dong (&#8363;)</option>
106
+ <option value="XAF">CFA Franc BEAC (FCFA)</option>
107
+ <option value="XOF">CFA Franc BCEAO (CFA)</option>
108
+ <option value="YER">Yemeni Rial (YER)</option>
109
+ <option value="ZAR">South African Rand (ZAR)</option>
110
+ <option value="ZMK">Zambian Kwacha (1968-2012) (ZMK)</option>
111
+ <option value="ZMW">Zambian Kwacha (ZMW)</option>
112
+ </select>
113
+ </div>
114
+ <div style="padding: 6px 8px">to</div>
115
+ <div>
116
+ <select name=to value="USD">
117
+ <option value="AED">United Arab Emirates Dirham (AED)</option>
118
+ <option value="ANG">Netherlands Antillean Guilder (ANG)</option>
119
+ <option value="ARS">Argentine Peso (ARS)</option>
120
+ <option value="AUD">Australian Dollar (A$)</option>
121
+ <option value="BDT">Bangladeshi Taka (BDT)</option>
122
+ <option value="BGN">Bulgarian Lev (BGN)</option>
123
+ <option value="BHD">Bahraini Dinar (BHD)</option>
124
+ <option value="BND">Brunei Dollar (BND)</option>
125
+ <option value="BOB">Bolivian Boliviano (BOB)</option>
126
+ <option value="BRL">Brazilian Real (R$)</option>
127
+ <option value="BWP">Botswanan Pula (BWP)</option>
128
+ <option value="CAD">Canadian Dollar (CA$)</option>
129
+ <option value="CHF">Swiss Franc (CHF)</option>
130
+ <option value="CLP">Chilean Peso (CLP)</option>
131
+ <option value="CNY">Chinese Yuan (CN�)</option>
132
+ <option value="COP">Colombian Peso (COP)</option>
133
+ <option value="CRC">Costa Rican Col�n (CRC)</option>
134
+ <option value="CZK">Czech Republic Koruna (CZK)</option>
135
+ <option value="DKK">Danish Krone (DKK)</option>
136
+ <option value="DOP">Dominican Peso (DOP)</option>
137
+ <option value="DZD">Algerian Dinar (DZD)</option>
138
+ <option value="EEK">Estonian Kroon (EEK)</option>
139
+ <option value="EGP">Egyptian Pound (EGP)</option>
140
+ <option value="EUR">Euro (�)</option>
141
+ <option value="FJD">Fijian Dollar (FJD)</option>
142
+ <option value="GBP">British Pound Sterling (�)</option>
143
+ <option value="HKD">Hong Kong Dollar (HK$)</option>
144
+ <option value="HNL">Honduran Lempira (HNL)</option>
145
+ <option value="HRK">Croatian Kuna (HRK)</option>
146
+ <option value="HUF">Hungarian Forint (HUF)</option>
147
+ <option value="IDR">Indonesian Rupiah (IDR)</option>
148
+ <option value="ILS">Israeli New Sheqel (&#8362;)</option>
149
+ <option value="INR">Indian Rupee (Rs.)</option>
150
+ <option value="JMD">Jamaican Dollar (JMD)</option>
151
+ <option value="JOD">Jordanian Dinar (JOD)</option>
152
+ <option value="JPY">Japanese Yen (�)</option>
153
+ <option value="KES">Kenyan Shilling (KES)</option>
154
+ <option value="KRW">South Korean Won (&#8361;)</option>
155
+ <option value="KWD">Kuwaiti Dinar (KWD)</option>
156
+ <option value="KYD">Cayman Islands Dollar (KYD)</option>
157
+ <option value="KZT">Kazakhstani Tenge (KZT)</option>
158
+ <option value="LBP">Lebanese Pound (LBP)</option>
159
+ <option value="LKR">Sri Lankan Rupee (LKR)</option>
160
+ <option value="LTL">Lithuanian Litas (LTL)</option>
161
+ <option value="LVL">Latvian Lats (LVL)</option>
162
+ <option value="MAD">Moroccan Dirham (MAD)</option>
163
+ <option value="MDL">Moldovan Leu (MDL)</option>
164
+ <option value="MKD">Macedonian Denar (MKD)</option>
165
+ <option value="MUR">Mauritian Rupee (MUR)</option>
166
+ <option value="MVR">Maldivian Rufiyaa (MVR)</option>
167
+ <option value="MXN">Mexican Peso (MX$)</option>
168
+ <option value="MYR">Malaysian Ringgit (MYR)</option>
169
+ <option value="NAD">Namibian Dollar (NAD)</option>
170
+ <option value="NGN">Nigerian Naira (NGN)</option>
171
+ <option value="NIO">Nicaraguan C�rdoba (NIO)</option>
172
+ <option value="NOK">Norwegian Krone (NOK)</option>
173
+ <option value="NPR">Nepalese Rupee (NPR)</option>
174
+ <option value="NZD">New Zealand Dollar (NZ$)</option>
175
+ <option value="OMR">Omani Rial (OMR)</option>
176
+ <option value="PEN">Peruvian Nuevo Sol (PEN)</option>
177
+ <option value="PGK">Papua New Guinean Kina (PGK)</option>
178
+ <option value="PHP">Philippine Peso (Php)</option>
179
+ <option value="PKR">Pakistani Rupee (PKR)</option>
180
+ <option value="PLN">Polish Zloty (PLN)</option>
181
+ <option value="PYG">Paraguayan Guarani (PYG)</option>
182
+ <option value="QAR">Qatari Rial (QAR)</option>
183
+ <option value="RON">Romanian Leu (RON)</option>
184
+ <option value="RSD">Serbian Dinar (RSD)</option>
185
+ <option value="RUB">Russian Ruble (RUB)</option>
186
+ <option value="SAR">Saudi Riyal (SAR)</option>
187
+ <option value="SCR">Seychellois Rupee (SCR)</option>
188
+ <option value="SEK">Swedish Krona (SEK)</option>
189
+ <option value="SGD">Singapore Dollar (SGD)</option>
190
+ <option value="SKK">Slovak Koruna (SKK)</option>
191
+ <option value="SLL">Sierra Leonean Leone (SLL)</option>
192
+ <option value="SVC">Salvadoran Col�n (SVC)</option>
193
+ <option value="THB">Thai Baht (&#3647;)</option>
194
+ <option value="TND">Tunisian Dinar (TND)</option>
195
+ <option value="TRY">Turkish Lira (TRY)</option>
196
+ <option value="TTD">Trinidad and Tobago Dollar (TTD)</option>
197
+ <option value="TWD">New Taiwan Dollar (NT$)</option>
198
+ <option value="TZS">Tanzanian Shilling (TZS)</option>
199
+ <option value="UAH">Ukrainian Hryvnia (UAH)</option>
200
+ <option value="UGX">Ugandan Shilling (UGX)</option>
201
+ <option SELECTED value="USD">US Dollar ($)</option>
202
+ <option value="UYU">Uruguayan Peso (UYU)</option>
203
+ <option value="UZS">Uzbekistan Som (UZS)</option>
204
+ <option value="VEF">Venezuelan Bol�var (VEF)</option>
205
+ <option value="VND">Vietnamese Dong (&#8363;)</option>
206
+ <option value="XAF">CFA Franc BEAC (FCFA)</option>
207
+ <option value="XOF">CFA Franc BCEAO (CFA)</option>
208
+ <option value="YER">Yemeni Rial (YER)</option>
209
+ <option value="ZAR">South African Rand (ZAR)</option>
210
+ <option value="ZMK">Zambian Kwacha (1968-2012) (ZMK)</option>
211
+ <option value="ZMW">Zambian Kwacha (ZMW)</option>
212
+ </select>
213
+ </div>
214
+ &nbsp;
215
+ <div id=currency_converter_result>1 SGD = <span class=bld>0.8066 USD</span>
216
+ <input type=submit value="Convert">
217
+ </div>
218
+ <input type=hidden name=meta value=ei&#61;QAtyUrDYB8mMkgXJ3QE>
219
+ </form>
220
+ </body>
221
+ </div>
222
+ </html>
@@ -0,0 +1,223 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html>
3
+ <head>
4
+ <title>Currency Converter - Google Finance</title>
5
+ <meta name="Description" content="Get real-time stock quotes & charts, financial news, currency conversions, or track your portfolio with Google Finance.">
6
+ <link rel="stylesheet" type="text/css" href="/finance/s/Jtl56e5m90s/styles/finance_us.css">
7
+ <link rel="icon"
8
+ type="image/vnd.microsoft.icon" href="/finance/favicon.ico"></head>
9
+ <body style="margin-left: 6px; min-width: 0px;">
10
+ <div class=g-doc>
11
+ <form action="/finance/converter" method="get" name="f">
12
+ <div class=sfe-break-top>
13
+ <input name=a maxlength=12 size=5 autocomplete=off value="1">
14
+ </div>
15
+ <div class=sfe-break-top>
16
+ <select name=from value="VND">
17
+ <option value="AED">United Arab Emirates Dirham (AED)</option>
18
+ <option value="ANG">Netherlands Antillean Guilder (ANG)</option>
19
+ <option value="ARS">Argentine Peso (ARS)</option>
20
+ <option value="AUD">Australian Dollar (A$)</option>
21
+ <option value="BDT">Bangladeshi Taka (BDT)</option>
22
+ <option value="BGN">Bulgarian Lev (BGN)</option>
23
+ <option value="BHD">Bahraini Dinar (BHD)</option>
24
+ <option value="BND">Brunei Dollar (BND)</option>
25
+ <option value="BOB">Bolivian Boliviano (BOB)</option>
26
+ <option value="BRL">Brazilian Real (R$)</option>
27
+ <option value="BWP">Botswanan Pula (BWP)</option>
28
+ <option value="CAD">Canadian Dollar (CA$)</option>
29
+ <option value="CHF">Swiss Franc (CHF)</option>
30
+ <option value="CLP">Chilean Peso (CLP)</option>
31
+ <option value="CNY">Chinese Yuan (CN�)</option>
32
+ <option value="COP">Colombian Peso (COP)</option>
33
+ <option value="CRC">Costa Rican Col�n (CRC)</option>
34
+ <option value="CZK">Czech Republic Koruna (CZK)</option>
35
+ <option value="DKK">Danish Krone (DKK)</option>
36
+ <option value="DOP">Dominican Peso (DOP)</option>
37
+ <option value="DZD">Algerian Dinar (DZD)</option>
38
+ <option value="EEK">Estonian Kroon (EEK)</option>
39
+ <option value="EGP">Egyptian Pound (EGP)</option>
40
+ <option value="EUR">Euro (�)</option>
41
+ <option value="FJD">Fijian Dollar (FJD)</option>
42
+ <option value="GBP">British Pound Sterling (�)</option>
43
+ <option value="HKD">Hong Kong Dollar (HK$)</option>
44
+ <option value="HNL">Honduran Lempira (HNL)</option>
45
+ <option value="HRK">Croatian Kuna (HRK)</option>
46
+ <option value="HUF">Hungarian Forint (HUF)</option>
47
+ <option value="IDR">Indonesian Rupiah (IDR)</option>
48
+ <option value="ILS">Israeli New Sheqel (&#8362;)</option>
49
+ <option value="INR">Indian Rupee (Rs.)</option>
50
+ <option value="JMD">Jamaican Dollar (JMD)</option>
51
+ <option value="JOD">Jordanian Dinar (JOD)</option>
52
+ <option value="JPY">Japanese Yen (�)</option>
53
+ <option value="KES">Kenyan Shilling (KES)</option>
54
+ <option value="KRW">South Korean Won (&#8361;)</option>
55
+ <option value="KWD">Kuwaiti Dinar (KWD)</option>
56
+ <option value="KYD">Cayman Islands Dollar (KYD)</option>
57
+ <option value="KZT">Kazakhstani Tenge (KZT)</option>
58
+ <option value="LBP">Lebanese Pound (LBP)</option>
59
+ <option value="LKR">Sri Lankan Rupee (LKR)</option>
60
+ <option value="LTL">Lithuanian Litas (LTL)</option>
61
+ <option value="LVL">Latvian Lats (LVL)</option>
62
+ <option value="MAD">Moroccan Dirham (MAD)</option>
63
+ <option value="MDL">Moldovan Leu (MDL)</option>
64
+ <option value="MKD">Macedonian Denar (MKD)</option>
65
+ <option value="MUR">Mauritian Rupee (MUR)</option>
66
+ <option value="MVR">Maldivian Rufiyaa (MVR)</option>
67
+ <option value="MXN">Mexican Peso (MX$)</option>
68
+ <option value="MYR">Malaysian Ringgit (MYR)</option>
69
+ <option value="NAD">Namibian Dollar (NAD)</option>
70
+ <option value="NGN">Nigerian Naira (NGN)</option>
71
+ <option value="NIO">Nicaraguan C�rdoba (NIO)</option>
72
+ <option value="NOK">Norwegian Krone (NOK)</option>
73
+ <option value="NPR">Nepalese Rupee (NPR)</option>
74
+ <option value="NZD">New Zealand Dollar (NZ$)</option>
75
+ <option value="OMR">Omani Rial (OMR)</option>
76
+ <option value="PEN">Peruvian Nuevo Sol (PEN)</option>
77
+ <option value="PGK">Papua New Guinean Kina (PGK)</option>
78
+ <option value="PHP">Philippine Peso (Php)</option>
79
+ <option value="PKR">Pakistani Rupee (PKR)</option>
80
+ <option value="PLN">Polish Zloty (PLN)</option>
81
+ <option value="PYG">Paraguayan Guarani (PYG)</option>
82
+ <option value="QAR">Qatari Rial (QAR)</option>
83
+ <option value="RON">Romanian Leu (RON)</option>
84
+ <option value="RSD">Serbian Dinar (RSD)</option>
85
+ <option value="RUB">Russian Ruble (RUB)</option>
86
+ <option value="SAR">Saudi Riyal (SAR)</option>
87
+ <option value="SCR">Seychellois Rupee (SCR)</option>
88
+ <option value="SEK">Swedish Krona (SEK)</option>
89
+ <option value="SGD">Singapore Dollar (SGD)</option>
90
+ <option value="SKK">Slovak Koruna (SKK)</option>
91
+ <option value="SLL">Sierra Leonean Leone (SLL)</option>
92
+ <option value="SVC">Salvadoran Col�n (SVC)</option>
93
+ <option value="THB">Thai Baht (&#3647;)</option>
94
+ <option value="TND">Tunisian Dinar (TND)</option>
95
+ <option value="TRY">Turkish Lira (TRY)</option>
96
+ <option value="TTD">Trinidad and Tobago Dollar (TTD)</option>
97
+ <option value="TWD">New Taiwan Dollar (NT$)</option>
98
+ <option value="TZS">Tanzanian Shilling (TZS)</option>
99
+ <option value="UAH">Ukrainian Hryvnia (UAH)</option>
100
+ <option value="UGX">Ugandan Shilling (UGX)</option>
101
+ <option value="USD">US Dollar ($)</option>
102
+ <option value="UYU">Uruguayan Peso (UYU)</option>
103
+ <option value="UZS">Uzbekistan Som (UZS)</option>
104
+ <option value="VEF">Venezuelan Bol�var (VEF)</option>
105
+ <option SELECTED value="VND">Vietnamese Dong (&#8363;)</option>
106
+ <option value="XAF">CFA Franc BEAC (FCFA)</option>
107
+ <option value="XOF">CFA Franc BCEAO (CFA)</option>
108
+ <option value="YER">Yemeni Rial (YER)</option>
109
+ <option value="ZAR">South African Rand (ZAR)</option>
110
+ <option value="ZMK">Zambian Kwacha (1968-2012) (ZMK)</option>
111
+ <option value="ZMW">Zambian Kwacha (ZMW)</option>
112
+ </select>
113
+ </div>
114
+ <div style="padding: 6px 8px">to</div>
115
+ <div>
116
+ <select name=to value="USD">
117
+ <option value="AED">United Arab Emirates Dirham (AED)</option>
118
+ <option value="ANG">Netherlands Antillean Guilder (ANG)</option>
119
+ <option value="ARS">Argentine Peso (ARS)</option>
120
+ <option value="AUD">Australian Dollar (A$)</option>
121
+ <option value="BDT">Bangladeshi Taka (BDT)</option>
122
+ <option value="BGN">Bulgarian Lev (BGN)</option>
123
+ <option value="BHD">Bahraini Dinar (BHD)</option>
124
+ <option value="BND">Brunei Dollar (BND)</option>
125
+ <option value="BOB">Bolivian Boliviano (BOB)</option>
126
+ <option value="BRL">Brazilian Real (R$)</option>
127
+ <option value="BWP">Botswanan Pula (BWP)</option>
128
+ <option value="CAD">Canadian Dollar (CA$)</option>
129
+ <option value="CHF">Swiss Franc (CHF)</option>
130
+ <option value="CLP">Chilean Peso (CLP)</option>
131
+ <option value="CNY">Chinese Yuan (CN�)</option>
132
+ <option value="COP">Colombian Peso (COP)</option>
133
+ <option value="CRC">Costa Rican Col�n (CRC)</option>
134
+ <option value="CZK">Czech Republic Koruna (CZK)</option>
135
+ <option value="DKK">Danish Krone (DKK)</option>
136
+ <option value="DOP">Dominican Peso (DOP)</option>
137
+ <option value="DZD">Algerian Dinar (DZD)</option>
138
+ <option value="EEK">Estonian Kroon (EEK)</option>
139
+ <option value="EGP">Egyptian Pound (EGP)</option>
140
+ <option value="EUR">Euro (�)</option>
141
+ <option value="FJD">Fijian Dollar (FJD)</option>
142
+ <option value="GBP">British Pound Sterling (�)</option>
143
+ <option value="HKD">Hong Kong Dollar (HK$)</option>
144
+ <option value="HNL">Honduran Lempira (HNL)</option>
145
+ <option value="HRK">Croatian Kuna (HRK)</option>
146
+ <option value="HUF">Hungarian Forint (HUF)</option>
147
+ <option value="IDR">Indonesian Rupiah (IDR)</option>
148
+ <option value="ILS">Israeli New Sheqel (&#8362;)</option>
149
+ <option value="INR">Indian Rupee (Rs.)</option>
150
+ <option value="JMD">Jamaican Dollar (JMD)</option>
151
+ <option value="JOD">Jordanian Dinar (JOD)</option>
152
+ <option value="JPY">Japanese Yen (�)</option>
153
+ <option value="KES">Kenyan Shilling (KES)</option>
154
+ <option value="KRW">South Korean Won (&#8361;)</option>
155
+ <option value="KWD">Kuwaiti Dinar (KWD)</option>
156
+ <option value="KYD">Cayman Islands Dollar (KYD)</option>
157
+ <option value="KZT">Kazakhstani Tenge (KZT)</option>
158
+ <option value="LBP">Lebanese Pound (LBP)</option>
159
+ <option value="LKR">Sri Lankan Rupee (LKR)</option>
160
+ <option value="LTL">Lithuanian Litas (LTL)</option>
161
+ <option value="LVL">Latvian Lats (LVL)</option>
162
+ <option value="MAD">Moroccan Dirham (MAD)</option>
163
+ <option value="MDL">Moldovan Leu (MDL)</option>
164
+ <option value="MKD">Macedonian Denar (MKD)</option>
165
+ <option value="MUR">Mauritian Rupee (MUR)</option>
166
+ <option value="MVR">Maldivian Rufiyaa (MVR)</option>
167
+ <option value="MXN">Mexican Peso (MX$)</option>
168
+ <option value="MYR">Malaysian Ringgit (MYR)</option>
169
+ <option value="NAD">Namibian Dollar (NAD)</option>
170
+ <option value="NGN">Nigerian Naira (NGN)</option>
171
+ <option value="NIO">Nicaraguan C�rdoba (NIO)</option>
172
+ <option value="NOK">Norwegian Krone (NOK)</option>
173
+ <option value="NPR">Nepalese Rupee (NPR)</option>
174
+ <option value="NZD">New Zealand Dollar (NZ$)</option>
175
+ <option value="OMR">Omani Rial (OMR)</option>
176
+ <option value="PEN">Peruvian Nuevo Sol (PEN)</option>
177
+ <option value="PGK">Papua New Guinean Kina (PGK)</option>
178
+ <option value="PHP">Philippine Peso (Php)</option>
179
+ <option value="PKR">Pakistani Rupee (PKR)</option>
180
+ <option value="PLN">Polish Zloty (PLN)</option>
181
+ <option value="PYG">Paraguayan Guarani (PYG)</option>
182
+ <option value="QAR">Qatari Rial (QAR)</option>
183
+ <option value="RON">Romanian Leu (RON)</option>
184
+ <option value="RSD">Serbian Dinar (RSD)</option>
185
+ <option value="RUB">Russian Ruble (RUB)</option>
186
+ <option value="SAR">Saudi Riyal (SAR)</option>
187
+ <option value="SCR">Seychellois Rupee (SCR)</option>
188
+ <option value="SEK">Swedish Krona (SEK)</option>
189
+ <option value="SGD">Singapore Dollar (SGD)</option>
190
+ <option value="SKK">Slovak Koruna (SKK)</option>
191
+ <option value="SLL">Sierra Leonean Leone (SLL)</option>
192
+ <option value="SVC">Salvadoran Col�n (SVC)</option>
193
+ <option value="THB">Thai Baht (&#3647;)</option>
194
+ <option value="TND">Tunisian Dinar (TND)</option>
195
+ <option value="TRY">Turkish Lira (TRY)</option>
196
+ <option value="TTD">Trinidad and Tobago Dollar (TTD)</option>
197
+ <option value="TWD">New Taiwan Dollar (NT$)</option>
198
+ <option value="TZS">Tanzanian Shilling (TZS)</option>
199
+ <option value="UAH">Ukrainian Hryvnia (UAH)</option>
200
+ <option value="UGX">Ugandan Shilling (UGX)</option>
201
+ <option SELECTED value="USD">US Dollar ($)</option>
202
+ <option value="UYU">Uruguayan Peso (UYU)</option>
203
+ <option value="UZS">Uzbekistan Som (UZS)</option>
204
+ <option value="VEF">Venezuelan Bol�var (VEF)</option>
205
+ <option value="VND">Vietnamese Dong (&#8363;)</option>
206
+ <option value="XAF">CFA Franc BEAC (FCFA)</option>
207
+ <option value="XOF">CFA Franc BCEAO (CFA)</option>
208
+ <option value="YER">Yemeni Rial (YER)</option>
209
+ <option value="ZAR">South African Rand (ZAR)</option>
210
+ <option value="ZMK">Zambian Kwacha (1968-2012) (ZMK)</option>
211
+ <option value="ZMW">Zambian Kwacha (ZMW)</option>
212
+ </select>
213
+ </div>
214
+ &nbsp;
215
+ <div id=currency_converter_result>
216
+ Could not convert.
217
+ <input type=submit value="Convert">
218
+ </div>
219
+ <input type=hidden name=meta value=ei&#61;UAtyUrC2PInckgWt8QE>
220
+ </form>
221
+ </body>
222
+ </div>
223
+ </html>
@@ -1,2 +1,9 @@
1
+ require 'timecop'
2
+
1
3
  RSpec.configure do |config|
2
4
  end
5
+
6
+ def load_rate_http_response(name)
7
+ f = File.expand_path("../rates/#{name}.html", __FILE__)
8
+ File.read(f, :encoding => 'iso-8859-1')
9
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_currency
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 3.0.0
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: 2013-10-01 00:00:00.000000000 Z
12
+ date: 2013-11-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -43,22 +43,6 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: 0.5.8
46
- - !ruby/object:Gem::Dependency
47
- name: json
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: 1.4.0
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: 1.4.0
62
46
  - !ruby/object:Gem::Dependency
63
47
  name: ffi
64
48
  requirement: !ruby/object:Gem::Requirement
@@ -91,22 +75,6 @@ dependencies:
91
75
  - - ~>
92
76
  - !ruby/object:Gem::Version
93
77
  version: 5.1.1
94
- - !ruby/object:Gem::Dependency
95
- name: multi_json
96
- requirement: !ruby/object:Gem::Requirement
97
- none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
102
- type: :runtime
103
- prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
78
  description: GoogleCurrency extends Money::Bank::Base and gives you access to the
111
79
  current Google Currency exchange rates.
112
80
  email:
@@ -117,6 +85,9 @@ extra_rdoc_files: []
117
85
  files:
118
86
  - lib/money/bank/google_currency.rb
119
87
  - spec/google_currency_with_json_spec.rb
88
+ - spec/rates/sgd_to_usd.html
89
+ - spec/rates/error.html
90
+ - spec/rates/vnd_to_usd.html
120
91
  - spec/spec_helper.rb
121
92
  - LICENSE
122
93
  - README.md