lita-stocks 0.0.4 → 0.0.5
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/lib/lita/handlers/stocks.rb +8 -1
- data/lita-stocks.gemspec +1 -1
- data/spec/lita/handlers/stocks_spec.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2edfa8a6699523b19368601afd6fdc5d3b796f5
|
4
|
+
data.tar.gz: 94b38e0879f0c9e266d6d5752cf9050825e6c612
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 132d3588c35830c04c832da7f521c24b071685117453636b3dfad141f222090ce4e4bce40e748961816895be290b67df11dbeee25089a755bd2a24c9ef116f8e
|
7
|
+
data.tar.gz: 165cbb80f63c91f2bd809459767d38d06ee5d9d9331b765ccc0855ad2627cae012e88315dc6501cf680d685448c7b71e7c2b69669b45c6e5a7de5071dfd670b9
|
data/lib/lita/handlers/stocks.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require "lita"
|
2
|
+
require "cgi"
|
2
3
|
|
3
4
|
module Lita
|
4
5
|
module Handlers
|
@@ -26,7 +27,13 @@ module Lita
|
|
26
27
|
def get_stock_data(symbol)
|
27
28
|
resp = http.get("https://www.google.com/finance/info?infotype=infoquoteall&q=#{symbol}")
|
28
29
|
raise 'RequestFail' unless resp.status == 200
|
29
|
-
|
30
|
+
body = resp.body.gsub(/\/\//, '')
|
31
|
+
|
32
|
+
# Google sends hex encoded data, we need to fix that
|
33
|
+
(33..47).each do |char|
|
34
|
+
body.gsub!(/\\x#{char.to_s(16)}/, char.chr)
|
35
|
+
end
|
36
|
+
MultiJson.load(body)[0]
|
30
37
|
end
|
31
38
|
|
32
39
|
def format_response(data)
|
data/lita-stocks.gemspec
CHANGED
@@ -23,4 +23,11 @@ describe Lita::Handlers::Stocks, lita_handler: true do
|
|
23
23
|
expect(replies.last).to_not include("MktCap")
|
24
24
|
expect(replies.last).to_not include("P/E")
|
25
25
|
end
|
26
|
+
|
27
|
+
|
28
|
+
it "ensures proper encoding" do
|
29
|
+
send_command "stock T"
|
30
|
+
expect(replies.last).to include("AT&T")
|
31
|
+
end
|
32
|
+
|
26
33
|
end
|