ystock 0.1.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.
- data/Manifest +5 -0
- data/README.rdoc +29 -0
- data/Rakefile +15 -0
- data/init.rb +1 -0
- data/lib/ystock.rb +48 -0
- data/ystock.gemspec +29 -0
- metadata +67 -0
data/Manifest
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= Ystock
|
2
|
+
|
3
|
+
Get stock information from Yahoo Finance
|
4
|
+
|
5
|
+
== Install
|
6
|
+
|
7
|
+
gem install ystock
|
8
|
+
|
9
|
+
Add it to your Gemfile
|
10
|
+
|
11
|
+
gem 'ystock'
|
12
|
+
|
13
|
+
|
14
|
+
== Usage
|
15
|
+
|
16
|
+
This gem uses Yahoo Finance (yahoo.finance.com) to get stock quotes. Remember the delay is up to 20 mins.
|
17
|
+
|
18
|
+
stock = 'aapl'
|
19
|
+
Ystock.get_stock(stock)
|
20
|
+
# Returns an array
|
21
|
+
####
|
22
|
+
# :symbol
|
23
|
+
# :price
|
24
|
+
# :change
|
25
|
+
# :volume
|
26
|
+
|
27
|
+
== Build by
|
28
|
+
|
29
|
+
Greg Winn
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Rakefile
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
require 'echoe'
|
5
|
+
Echoe.new('ystock', '0.1.5') 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
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'ystock'
|
data/lib/ystock.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#
|
2
|
+
# Yahoo Stock find
|
3
|
+
# gem ystock
|
4
|
+
#
|
5
|
+
# by Greg Winn
|
6
|
+
# winn.ws
|
7
|
+
# http://github.com/gregwinn/ystock
|
8
|
+
#
|
9
|
+
require 'cgi'
|
10
|
+
require 'net/http'
|
11
|
+
module Ystock
|
12
|
+
def ensure_unique(name)
|
13
|
+
begin
|
14
|
+
self[name] = yield
|
15
|
+
end while self.class.exists?(name => self[name])
|
16
|
+
end
|
17
|
+
|
18
|
+
@@service_uri = "http://download.finance.yahoo.com/d/quotes.csv"
|
19
|
+
|
20
|
+
def self.get_stock(stock)
|
21
|
+
output = Array.new
|
22
|
+
s = send_request(stock)
|
23
|
+
a = s.chomp.split(",")
|
24
|
+
output << { :symbol => stock,
|
25
|
+
:price => a[0],
|
26
|
+
:change => a[1],
|
27
|
+
:volume => a[2]
|
28
|
+
}
|
29
|
+
return output
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.send_request(*args)
|
33
|
+
completed_path = @@service_uri + construct_args(*args)
|
34
|
+
uri = URI.parse(completed_path)
|
35
|
+
response = Net::HTTP.start(uri.host, uri.port) do |http|
|
36
|
+
http.get completed_path
|
37
|
+
end
|
38
|
+
return response.body
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.construct_args(*args)
|
42
|
+
path = "?f=l1c1v&s=" + args.map{|x| CGI.escape(x)}.join(",")
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
class ActiveRecord::Base
|
47
|
+
include Ystock
|
48
|
+
end
|
data/ystock.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{ystock}
|
5
|
+
s.version = "0.1.5"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Greg Winn"]
|
9
|
+
s.date = %q{2011-02-13}
|
10
|
+
s.description = %q{Get stock information from Yahoo Finance}
|
11
|
+
s.email = %q{greg@winn.ws}
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/ystock.rb"]
|
13
|
+
s.files = ["Manifest", "README.rdoc", "Rakefile", "init.rb", "lib/ystock.rb", "ystock.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/gregwinn/ystock}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Ystock", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{ystock}
|
18
|
+
s.rubygems_version = %q{1.5.0}
|
19
|
+
s.summary = %q{Get stock information from Yahoo Finance}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
s.specification_version = 3
|
23
|
+
|
24
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
25
|
+
else
|
26
|
+
end
|
27
|
+
else
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ystock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.5
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Greg Winn
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-02-13 00:00:00 -06:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Get stock information from Yahoo Finance
|
18
|
+
email: greg@winn.ws
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.rdoc
|
25
|
+
- lib/ystock.rb
|
26
|
+
files:
|
27
|
+
- Manifest
|
28
|
+
- README.rdoc
|
29
|
+
- Rakefile
|
30
|
+
- init.rb
|
31
|
+
- lib/ystock.rb
|
32
|
+
- ystock.gemspec
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/gregwinn/ystock
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options:
|
39
|
+
- --line-numbers
|
40
|
+
- --inline-source
|
41
|
+
- --title
|
42
|
+
- Ystock
|
43
|
+
- --main
|
44
|
+
- README.rdoc
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "1.2"
|
59
|
+
requirements: []
|
60
|
+
|
61
|
+
rubyforge_project: ystock
|
62
|
+
rubygems_version: 1.5.0
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Get stock information from Yahoo Finance
|
66
|
+
test_files: []
|
67
|
+
|