google_currency 3.3.0 → 3.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +24 -15
- data/google_currency.gemspec +1 -1
- data/lib/money/bank/google_currency.rb +7 -1
- data/spec/google_currency_with_json_spec.rb +7 -0
- data/spec/rates/captcha.html +87 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8965d9cb15aaf014c5b9ae2a70f163f43743cf3
|
4
|
+
data.tar.gz: 5fe6ef5793cd5b9defd1654ceb4003fedd97a18f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22c338a754cdd998b7bbcf3d70b26182942ef7d4fc311fb6c68aed93aca4d20e02909dfadc44483f506a98049a19841c83c76c77eca5ac79a75a0a7f98e61216
|
7
|
+
data.tar.gz: 6ed9ef16e15b44aac44a08225358cd23f004781c66ac42d1378cc79f75d0a2b937c2ced08f658e9a6365c269b4732934bad1cd23b2a37c2a2976160342707d0b
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -9,25 +9,29 @@ and gives you access to the current Google Currency exchange rates.
|
|
9
9
|
Usage
|
10
10
|
-----
|
11
11
|
|
12
|
-
|
13
|
-
require 'money/bank/google_currency'
|
12
|
+
```ruby
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
# by default, they never expire
|
18
|
-
Money::Bank::GoogleCurrency.ttl_in_seconds = 86400
|
14
|
+
require 'money'
|
15
|
+
require 'money/bank/google_currency'
|
19
16
|
|
20
|
-
|
21
|
-
|
17
|
+
# (optional)
|
18
|
+
# set the seconds after than the current rates are automatically expired
|
19
|
+
# by default, they never expire
|
20
|
+
Money::Bank::GoogleCurrency.ttl_in_seconds = 86400
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
money.exchange_to(:EUR)
|
22
|
+
# set default bank to instance of GoogleCurrency
|
23
|
+
Money.default_bank = Money::Bank::GoogleCurrency.new
|
26
24
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
# create a new money object, and use the standard #exchange_to method
|
26
|
+
money = Money.new(1_00, "USD") # amount is in cents
|
27
|
+
money.exchange_to(:EUR)
|
28
|
+
|
29
|
+
# or install and use the 'monetize' gem
|
30
|
+
require 'monetize'
|
31
|
+
money = 1.to_money(:USD)
|
32
|
+
money.exchange_to(:EUR)
|
33
|
+
|
34
|
+
```
|
31
35
|
|
32
36
|
An `UnknownRate` will be thrown if `#exchange_to` is called with a `Currency`
|
33
37
|
that `Money` knows, but Google does not.
|
@@ -35,6 +39,8 @@ that `Money` knows, but Google does not.
|
|
35
39
|
An `UnknownCurrency` will be thrown if `#exchange_to` is called with a
|
36
40
|
`Currency` that `Money` does not know.
|
37
41
|
|
42
|
+
A `GoogleCurrencyCaptchaError` will be thrown if the Google Finance Converter API page responds with a Captcha instead of a rate (#52).
|
43
|
+
|
38
44
|
A `GoogleCurrencyFetchError` will be thrown if there is an unknown issue with the Google Finance Converter API.
|
39
45
|
|
40
46
|
Caveats
|
@@ -55,6 +61,9 @@ Consequently, this means that small exchange rates will be imprecise.
|
|
55
61
|
For example, if the IDR to USD exchange rate were 0.00007761, Google will report it as 0.0001.
|
56
62
|
This means 100000 IDR would exchange to 10 USD instead of 7.76 USD.
|
57
63
|
|
64
|
+
To accommodate for this, the reverse rate will be obtained if the rate is small
|
65
|
+
(below 0.1) and the reciprocal of this reverse rate is used.
|
66
|
+
|
58
67
|
Copyright
|
59
68
|
---------
|
60
69
|
|
data/google_currency.gemspec
CHANGED
@@ -8,11 +8,15 @@ class Money
|
|
8
8
|
# from Google Finance Calculator
|
9
9
|
class GoogleCurrencyFetchError < Error
|
10
10
|
end
|
11
|
+
# Raised when there is a captcha form request in extracting exchange rates
|
12
|
+
# from Google Finance Calculator
|
13
|
+
class GoogleCurrencyCaptchaError < Error
|
14
|
+
end
|
11
15
|
|
12
16
|
class GoogleCurrency < Money::Bank::VariableExchange
|
13
17
|
|
14
18
|
|
15
|
-
SERVICE_HOST = "
|
19
|
+
SERVICE_HOST = "finance.google.com"
|
16
20
|
SERVICE_PATH = "/finance/converter"
|
17
21
|
|
18
22
|
|
@@ -164,6 +168,8 @@ class Money
|
|
164
168
|
BigDecimal($1)
|
165
169
|
when /Could not convert\./
|
166
170
|
raise UnknownRate
|
171
|
+
when /captcha-form/
|
172
|
+
raise GoogleCurrencyCaptchaError
|
167
173
|
else
|
168
174
|
raise GoogleCurrencyFetchError
|
169
175
|
end
|
@@ -73,6 +73,13 @@ describe "GoogleCurrency" do
|
|
73
73
|
@bank.get_rate('VND', 'USD')
|
74
74
|
}.to raise_error(Money::Bank::GoogleCurrencyFetchError)
|
75
75
|
end
|
76
|
+
|
77
|
+
it "should raise GoogleCurrencyCaptchaError when the page sends a Captcha form" do
|
78
|
+
allow(@uri).to receive(:read) { load_rate_http_response("captcha") }
|
79
|
+
expect {
|
80
|
+
@bank.get_rate('VND', 'USD')
|
81
|
+
}.to raise_error(Money::Bank::GoogleCurrencyCaptchaError)
|
82
|
+
end
|
76
83
|
end
|
77
84
|
end
|
78
85
|
|
@@ -0,0 +1,87 @@
|
|
1
|
+
<!DOCTYPE html><html><head><script>(function(){(function(){function e(a){this.t={};this.tick=function(a,c,b){var d=void 0!=b?b:(new Date).getTime();this.t[a]=[d,c];if(void 0==b)try{window.console.timeStamp("CSI/"+a)}catch(h){}};this.tick("start",null,a)}var a,d;window.performance&&(d=(a=window.performance.timing)&&a.responseStart);var f=0<d?new e(d):new e;window.jstiming={Timer:e,load:f};if(a){var c=a.navigationStart;0<c&&d>=c&&(window.jstiming.srt=d-c)}if(a){var b=window.jstiming.load;0<c&&d>=c&&(b.tick("_wtsrt",void 0,c),b.tick("wtsrt_","_wtsrt",
|
2
|
+
d),b.tick("tbsd_","wtsrt_"))}try{a=null,window.chrome&&window.chrome.csi&&(a=Math.floor(window.chrome.csi().pageT),b&&0<c&&(b.tick("_tbnd",void 0,window.chrome.csi().startE),b.tick("tbnd_","_tbnd",c))),null==a&&window.gtbExternal&&(a=window.gtbExternal.pageT()),null==a&&window.external&&(a=window.external.pageT,b&&0<c&&(b.tick("_tbnd",void 0,window.external.startE),b.tick("tbnd_","_tbnd",c))),a&&(window.jstiming.pt=a)}catch(g){}})();}).call(this);
|
3
|
+
</script><title> - Google Finance Search</title><meta name="Description" content="Get real-time stock quotes & charts, financial news, currency conversions, or track your portfolio with Google Finance."><meta name="robots" content="noindex"><meta http-equiv="X-UA-Compatible" content="IE=10"><link rel="stylesheet" type="text/css" href="/finance/f/finance_us-1489929081.css"><link rel="stylesheet" type="text/css" href="/_/scs/finance-static/_/ss/k=finance.a.x7heix82rby5.L.X.O/d=0/rs=AGHGApGGyMTYIG0S-XdTFFcL0gvZpAxOZg"><link rel="icon" type="image/vnd.microsoft.icon" href="/finance/favicon.ico"><style>#gbar,#guser{font-size:13px;padding-right:8px;padding-top:4px !important;}#gbar{padding-left:8px;height:22px}#guser{padding-bottom:7px !important;text-align:right}.gbh,.gbd{border-top:1px solid #c9d7f1;font-size:1px}.gbh{height:0;position:absolute;top:24px;width:100%}@media all{.gb1{height:22px;margin-right:.5em;vertical-align:top}#gbar{float:left}}a.gb1,a.gb4{text-decoration:underline !important}a.gb1,a.gb4{color:#00c !important}.gbi .gb4{color:#dd8e27 !important}.gbf .gb4{color:#900 !important}
|
4
|
+
</style><script></script><script async="" defer="" src="//www.google.com/insights/consumersurveys/async_survey?site=xusttduenzseze54mcajwbd6sq"></script><script>
|
5
|
+
function _rpt() {}
|
6
|
+
function _tck() {}
|
7
|
+
</script><script>
|
8
|
+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
9
|
+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
10
|
+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
11
|
+
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
|
12
|
+
|
13
|
+
ga('create', 'UA-40765809-1', {
|
14
|
+
'allowLinker': true,
|
15
|
+
'cookiePath': '/finance'
|
16
|
+
});
|
17
|
+
ga('send', 'pageview');
|
18
|
+
</script></head><body><div class=fjfe-bodywrapper><div id=fjfe-real-body class=g-doc><input type="text" name="hist_state" id="hist_state" style="display:none;"><iframe id="hist_frame" name="hist_frame" class=invfr tabindex="-1"></iframe><iframe src="/_/scs/finance-static/_/js/k=finance.a.en_US.9R147Dhnn8c.O/m=b/rt=h/d=0/rs=AGHGApGszSEHbMoXAq0_ObWO6zwfX-urUw" class=invfr tabindex="-1"></iframe><div id=gbar><nobr><a class=gb1 href="https://www.google.com/webhp?tab=ew">Search</a> <a class=gb1 href="http://www.google.com/imghp?hl=en&tab=ei">Images</a> <a class=gb1 href="http://maps.google.com/maps?hl=en&tab=el">Maps</a> <a class=gb1 href="https://play.google.com/?hl=en&tab=e8">Play</a> <a class=gb1 href="http://www.youtube.com/?tab=e1">YouTube</a> <a class=gb1 href="http://news.google.com/nwshp?hl=en&tab=en">News</a> <a class=gb1 href="https://mail.google.com/mail/?tab=em">Gmail</a> <a class=gb1 href="https://drive.google.com/?tab=eo">Drive</a> <a class=gb1 style="text-decoration:none" href="https://www.google.com/intl/en/options/"><u>More</u> »</a></nobr></div><div id=guser width=100%><nobr><span id=gbn class=gbi></span><span id=gbf class=gbf></span><span id=gbe></span><a href="http://www.google.com/support/finance?hl=en" class=gb4>Help</a> | <a target=_top id=gb_70 href="https://accounts.google.com/ServiceLogin?service=finance&passive=1209600&continue=http://www.google.com/finance/captcha&followup=http://www.google.com/finance/captcha" class=gb4>Sign in</a></nobr></div><div class=gbh style=left:0></div><div class=gbh style=right:0></div><div id=fjfe-click-wrapper><script>
|
19
|
+
(function() {
|
20
|
+
var l = window.location;
|
21
|
+
var q = l.search ? l.search.substr(1) : '';
|
22
|
+
var h = l.hash ? l.hash.substr(1) : '';
|
23
|
+
var p = '/finance';
|
24
|
+
var ss = 'stockscreener';
|
25
|
+
var conn = window.history && window.history.pushState ? '/' : '#';
|
26
|
+
if (l.pathname == p + '/' + ss) {
|
27
|
+
if (h) l.href = p + conn + ss + '?' + q + '&' + h;
|
28
|
+
} else if (l.pathname != p && h) {
|
29
|
+
l.href = p + l.hash;
|
30
|
+
}
|
31
|
+
if (h) {
|
32
|
+
document.getElementById('fjfe-click-wrapper').style.display = 'none';
|
33
|
+
}
|
34
|
+
})();
|
35
|
+
</script><div id=gf-head class="g-section g-tpl-75-25 g-split"><div class="g-unit g-first"><div class=fjfe-logo><a href="/finance/?ei=J3BzWOCmPNWQswH67ou4Dw"><img src="/finance/f/logo_material-4224265490.png" alt="Google Finance"></a></div><div id=gf-search class=fjfe-search><form method="get" action="/finance" autocomplete="off"><input class=fjfe-searchbox-input name=q type=text tabindex=1 value=""></input><span class=fjfe-searchbox-button-wrapper><span class=fjfe-searchbox-button-wrapper2><input class=fjfe-searchbox-button type=submit tabindex=2 value="Get quotes"></input></span></span><input type=hidden name="ei" value="J3BzWOCmPNWQswH67ou4Dw"></input></form></div></div><div class="g-unit fjfe-promo"><div id="ad2-target" class="id-ad2-target"></div></div></div><div class=elastic><div id=app class="g-section g-tpl-left-11p4em"><div class="g-unit g-first"><div id=gf-nav><div class=fjfe-nav-nav><ul class=fjfe-nav id=navmenu><li class=fjfe-nav-item><a href="/finance?ei=J3BzWOCmPNWQswH67ou4Dw"><div>Markets</div></a><li class=fjfe-nav-item><a href="/finance/market_news?ei=J3BzWOCmPNWQswH67ou4Dw"><div>News</div></a><li class=fjfe-nav-item><a href="/finance/portfolio?action=view&ei=J3BzWOCmPNWQswH67ou4Dw"><div>Portfolios</div></a><li class=fjfe-nav-item><a href="/finance/stockscreener?ei=J3BzWOCmPNWQswH67ou4Dw"><div>Stock screener</div></a><li class=fjfe-nav-item><a href="/finance/domestic_trends?ei=J3BzWOCmPNWQswH67ou4Dw"><div>Google Domestic Trends</div></a></ul></div><div class="fjfe-recentquotes fjfe-recentquotes-noquote"><h4>Recent Quotes <span class="fjfe-recentquotes-duration">(<a href="//www.google.com/history/optout?hl=en">30 days</a>)</span></h4><div class=fjfe-recentquotes-noquote-notification>You have no recent quotes</div><div class=fjfe-recentquotes-quotes><div class="fjfe-toggle fjfe-toggle-button"><span class=fjfe-chg-toggle>chg</span> | <span class=fjfe-perc-toggle>%</span></div><div class=fjfe-table-div><table class=fjfe-recentquotes-table id=rq width=100%></table></div></div></div></div></div><div class=g-unit id=gf-viewc><div class=fjfe-content>
|
36
|
+
<form id="captcha-form" action="/finance/captcha" method="get">
|
37
|
+
<input type=hidden name=ctoken value="AIPim9iQSVMWeMs67Od2GF12I55XhMuifTl6_yyQgq7nJcGjohgibhsURlPuFcOGcNuKIjDYl2OlkiTY8y0xQgqpW57uZ7LClA">
|
38
|
+
<table cellspacing="0" cellpadding="5" border="0">
|
39
|
+
<tbody>
|
40
|
+
<tr>
|
41
|
+
<td>To continue your request, type the numbers you see
|
42
|
+
in the picture below:
|
43
|
+
</td>
|
44
|
+
</tr>
|
45
|
+
<tr>
|
46
|
+
<td>
|
47
|
+
<img src="/finance/captcha?ctoken=AIPim9iQSVMWeMs67Od2GF12I55XhMuifTl6_yyQgq7nJcGjohgibhsURlPuFcOGcNuKIjDYl2OlkiTY8y0xQgqpW57uZ7LClA&ei=J3BzWOCmPNWQswH67ou4Dw" width=200 height=70 />
|
48
|
+
</td>
|
49
|
+
</tr>
|
50
|
+
<tr>
|
51
|
+
<td align="left">
|
52
|
+
<input type=text title="Type the numbers you see"
|
53
|
+
size=30 name="canswer" id="canswer" value="">
|
54
|
+
</td>
|
55
|
+
</tr>
|
56
|
+
<tr>
|
57
|
+
<td align="left">
|
58
|
+
<input value="OK" name="button" type="submit" id="submit_captcha">
|
59
|
+
|
60
|
+
<input value="Cancel" name="button" type="submit" id="cancel">
|
61
|
+
</td>
|
62
|
+
</tr>
|
63
|
+
</tbody>
|
64
|
+
</table>
|
65
|
+
</form>
|
66
|
+
</div></div></div></div></div><div id=gf-foot><div id=fjfe-edition-links class=fjfe-footer-links>Google Finance Beta available in: <a href="http://www.google.com.hk/finance?ei=J3BzWOCmPNWQswH67ou4Dw" class="fjfe-edition-link">Hong Kong</a> - <a href="http://www.google.ca/finance?ei=J3BzWOCmPNWQswH67ou4Dw" class="fjfe-edition-link">Canada</a> - <a href="http://www.google.com/finance?ei=J3BzWOCmPNWQswH67ou4Dw" class="fjfe-edition-link">U.S.</a> - <a href="http://www.google.com.hk/finance?hl=zh-CN&ei=J3BzWOCmPNWQswH67ou4Dw" class="fjfe-edition-link">China</a> - <a href="http://www.google.co.uk/finance?ei=J3BzWOCmPNWQswH67ou4Dw" class="fjfe-edition-link">U.K.</a></div><p class=fjfe-footer-disclaimer>Information is provided "as is" and solely for informational purposes, not for trading purposes or advice, and may be delayed.<br>To see all exchange delays, please <a href="http://www.google.com/intl/en/googlefinance/disclaimer/?ei=J3BzWOCmPNWQswH67ou4Dw" class="fjfe-secondary-link fjfe-no-sticky-params"> see disclaimer</a>.</p><div class=fjfe-footer-links>©2017 Google - <a href="http://www.google.com?hl=en&ei=J3BzWOCmPNWQswH67ou4Dw">Google Home</a> - <a href="http://googlefinanceblog.blogspot.com?ei=J3BzWOCmPNWQswH67ou4Dw">Blog</a> - <a href="http://support.google.com/finance?hl=en&ei=J3BzWOCmPNWQswH67ou4Dw">Help</a> - <a href="http://support.google.com/finance?ctx=report&hl=en&ei=J3BzWOCmPNWQswH67ou4Dw">Report a Problem</a> - <a href="http://www.google.com/intl/en/policies/privacy/?ei=J3BzWOCmPNWQswH67ou4Dw">Privacy Policy</a> - <a href="http://www.google.com/intl/en/policies/terms/?ei=J3BzWOCmPNWQswH67ou4Dw">Terms of Service</a></div></div><script>var _cleardot = 'data:image\/gif;base64,R0lGODlhAQABAIAAAP\/\/\/\/\/\/\/yH5BAEKAAEALAAAAAABAAEAAAICTAEAOw\x3d\x3d';
|
67
|
+
var google = google || {};
|
68
|
+
google.finance = google.finance || {};
|
69
|
+
google.finance.gce = false ;</script><script src="/finance/f/sfe-opt-1767485581.js"></script><script>
|
70
|
+
_regOnLoad = function(f) {
|
71
|
+
if (document.readyState == 'complete') {
|
72
|
+
f && f();
|
73
|
+
} else {
|
74
|
+
// Window.attachEvent() for IE8 and below compatability.
|
75
|
+
var addEventFunction = window.attachEvent ||
|
76
|
+
window.addEventListener || function(ignored, f) { f(); };
|
77
|
+
var event = window.attachEvent ? 'onload' : 'load';
|
78
|
+
f && addEventFunction(event, f);
|
79
|
+
}
|
80
|
+
};
|
81
|
+
|
82
|
+
google.finance.renderRecentQuotes = function() {};
|
83
|
+
</script>
|
84
|
+
<script>
|
85
|
+
google.finance.common.listenToForm('captcha-form');
|
86
|
+
</script>
|
87
|
+
</div></div><script>var googlefinance = {i: ["f.b.id","",null,0,"",0,null,["f.b.cf","9R147Dhnn8c.en_US.",0],[],1,[],"J3BzWOCmPNWQswH67ou4Dw","www.google.com","xcenueYTtfa1Z01KurF2Be31bD4:1483960360021",1]}; GF_domReady = 1;</script></body></html>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: google_currency
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Emmons
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/money/bank/google_currency.rb
|
85
85
|
- lib/money/rates_store/rate_removal_support.rb
|
86
86
|
- spec/google_currency_with_json_spec.rb
|
87
|
+
- spec/rates/captcha.html
|
87
88
|
- spec/rates/error.html
|
88
89
|
- spec/rates/sgd_to_usd.html
|
89
90
|
- spec/rates/vnd_to_usd.html
|
@@ -108,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
108
109
|
version: '0'
|
109
110
|
requirements: []
|
110
111
|
rubyforge_project:
|
111
|
-
rubygems_version: 2.
|
112
|
+
rubygems_version: 2.6.8
|
112
113
|
signing_key:
|
113
114
|
specification_version: 4
|
114
115
|
summary: Access the Google Currency exchange rate data.
|