ystock 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ystock.rb +19 -55
- data/lib/ystock/google.rb +53 -0
- data/ystock.gemspec +2 -2
- metadata +2 -4
- data/Manifest +0 -6
- data/Rakefile +0 -15
- data/init.rb +0 -1
data/lib/ystock.rb
CHANGED
@@ -9,6 +9,7 @@
|
|
9
9
|
require 'cgi'
|
10
10
|
require 'json'
|
11
11
|
require 'net/http'
|
12
|
+
require 'httparty'
|
12
13
|
module Ystock
|
13
14
|
def ensure_unique(name)
|
14
15
|
begin
|
@@ -17,52 +18,6 @@ module Ystock
|
|
17
18
|
end
|
18
19
|
|
19
20
|
@@service_uri = "http://download.finance.yahoo.com/d/quotes.csv"
|
20
|
-
|
21
|
-
# => Ystock::Google
|
22
|
-
class Google
|
23
|
-
@@google_service = "http://finance.google.com/finance/info"
|
24
|
-
# => Ystock::Google.find(["aapl", "goog"])
|
25
|
-
def self.find(args)
|
26
|
-
last_stock = args.last
|
27
|
-
stock_string = ""
|
28
|
-
args.each do |stock|
|
29
|
-
if last_stock == stock
|
30
|
-
stock_string += stock
|
31
|
-
else
|
32
|
-
stock_string += stock + ","
|
33
|
-
end
|
34
|
-
end
|
35
|
-
# => Send Request to get quote then format
|
36
|
-
format(send_request(stock_string))
|
37
|
-
end
|
38
|
-
|
39
|
-
def self.get_quote(arg)
|
40
|
-
# => One stock
|
41
|
-
format(send_request(arg))
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.format(results)
|
45
|
-
output = Hash.new
|
46
|
-
results.each do |result|
|
47
|
-
output[result["t"].to_sym] = {
|
48
|
-
:symbol => result["t"],
|
49
|
-
:market => result["e"],
|
50
|
-
:price => result["l"],
|
51
|
-
:change => result["c"]
|
52
|
-
}
|
53
|
-
end
|
54
|
-
return output
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.send_request(args)
|
58
|
-
url = @@google_service + "?client=ig&q="
|
59
|
-
url += args
|
60
|
-
resp = Net::HTTP.get_response(URI.parse(url))
|
61
|
-
data = resp.body.gsub("//", "")
|
62
|
-
# => Result = Hash
|
63
|
-
result = JSON.parse(data)
|
64
|
-
end
|
65
|
-
end
|
66
21
|
|
67
22
|
# Ystock.find(['stock', 'stock'])
|
68
23
|
def self.find(args)
|
@@ -94,12 +49,14 @@ module Ystock
|
|
94
49
|
output = Hash.new
|
95
50
|
results.each_line("\n") do |row|
|
96
51
|
stockdata = row.split(",")
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
52
|
+
if !stockdata.nil?
|
53
|
+
if !stockdata[3].nil?
|
54
|
+
stockdata[3] = stockdata[3].gsub("\r\n", "").gsub('"', '')
|
55
|
+
output[stockdata[3].to_sym] = {:symbol => stockdata[3],
|
56
|
+
:price => stockdata[0],
|
57
|
+
:change => stockdata[1],
|
58
|
+
:volume => stockdata[2]}
|
59
|
+
end
|
103
60
|
end
|
104
61
|
end
|
105
62
|
return output
|
@@ -113,8 +70,15 @@ module Ystock
|
|
113
70
|
end
|
114
71
|
return response.body
|
115
72
|
end
|
73
|
+
|
74
|
+
def self.version
|
75
|
+
return Gem::VERSION
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.test
|
79
|
+
return "Test is working 2"
|
80
|
+
end
|
116
81
|
|
117
82
|
end
|
118
|
-
|
119
|
-
|
120
|
-
end
|
83
|
+
|
84
|
+
require 'ystock/google'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# => Ystock::Google
|
2
|
+
module Ystock
|
3
|
+
class Google
|
4
|
+
#@@google_service = "http://finance.google.com/finance/info"
|
5
|
+
@@google_service = "http://www.google.com/ig/api"
|
6
|
+
# => Ystock::Google.find(["aapl", "goog"])
|
7
|
+
def self.find(args)
|
8
|
+
first_stock = args.first
|
9
|
+
stock_string = ""
|
10
|
+
args.each do |stock|
|
11
|
+
if first_stock == stock
|
12
|
+
stock_string += "?stock=" + stock
|
13
|
+
else
|
14
|
+
stock_string += "&stock=" + stock
|
15
|
+
end
|
16
|
+
end
|
17
|
+
puts stock_string
|
18
|
+
# => Send Request to get quote then format
|
19
|
+
format(send_request(stock_string))
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.get_quote(arg)
|
23
|
+
arg = "?stock=" + arg
|
24
|
+
# => One stock
|
25
|
+
format(send_request(arg))
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.format(results)
|
29
|
+
output = Hash.new
|
30
|
+
|
31
|
+
results.each do |item|
|
32
|
+
item[1]["finance"].each do |stock|
|
33
|
+
output[stock["symbol"]["data"].to_sym] = {
|
34
|
+
:symbol => stock["symbol"]["data"],
|
35
|
+
:market => stock["exchange"]["data"],
|
36
|
+
:price => stock["last"]["data"],
|
37
|
+
:change => stock["change"]["data"],
|
38
|
+
:volume => stock["exchange"]["data"]
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
return output
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.send_request(args)
|
48
|
+
url = @@google_service + args
|
49
|
+
puts url
|
50
|
+
return HTTParty.get(url)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/ystock.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{ystock}
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Greg Winn"]
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.description = %q{Get stock information from Yahoo Finance and Google}
|
11
11
|
s.email = %q{greg@winn.ws}
|
12
12
|
s.extra_rdoc_files = ["README.markdown", "lib/ystock.rb"]
|
13
|
-
s.files = ["
|
13
|
+
s.files = ["README.markdown", "lib/ystock.rb", "lib/ystock/google.rb", "ystock.gemspec"]
|
14
14
|
s.homepage = %q{http://github.com/gregwinn/ystock}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ystock", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ystock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -19,11 +19,9 @@ extra_rdoc_files:
|
|
19
19
|
- README.markdown
|
20
20
|
- lib/ystock.rb
|
21
21
|
files:
|
22
|
-
- Manifest
|
23
22
|
- README.markdown
|
24
|
-
- Rakefile
|
25
|
-
- init.rb
|
26
23
|
- lib/ystock.rb
|
24
|
+
- lib/ystock/google.rb
|
27
25
|
- ystock.gemspec
|
28
26
|
homepage: http://github.com/gregwinn/ystock
|
29
27
|
licenses: []
|
data/Manifest
DELETED
data/Rakefile
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
# Rakefile
|
2
|
-
require 'rubygems'
|
3
|
-
require 'rake'
|
4
|
-
require 'echoe'
|
5
|
-
Echoe.new('ystock', '0.2.4') do |p|
|
6
|
-
p.description = "Get stock information from Yahoo Finance"
|
7
|
-
p.url = "http://github.com/gregwinn/ystock"
|
8
|
-
p.author = "Greg Winn"
|
9
|
-
p.email = "greg@winn.ws"
|
10
|
-
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
-
p.development_dependencies = []
|
12
|
-
end
|
13
|
-
|
14
|
-
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
|
15
|
-
|
data/init.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
require 'ystock'
|