johnyerhot-rQuote 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +18 -0
- data/lib/rquote.rb +45 -0
- metadata +55 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
rQuote
|
2
|
+
======
|
3
|
+
|
4
|
+
Gets realtime stock quotes from Yahoo Finance.
|
5
|
+
|
6
|
+
Its super simple to use.
|
7
|
+
|
8
|
+
|
9
|
+
Example
|
10
|
+
=======
|
11
|
+
|
12
|
+
quote = Rquote.new
|
13
|
+
quote.find("aapl", "msft")
|
14
|
+
|
15
|
+
=> [{:change=>"-4.02", :price=>"169.72", :volume=>"16105013", :symbol=>"aapl"}, {:change=>"-0.42", :price=>"27.52", :volume=>"27024456", :symbol=>"msft"}]
|
16
|
+
|
17
|
+
|
18
|
+
Copyright (c) 2008 John Yerhot, released under the MIT license
|
data/lib/rquote.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# rQuote - Simple, realtime stock market quoting Ruby on Rails plugin
|
2
|
+
# Homepage: rquote.yerhot.org
|
3
|
+
# Repository: git://github.com/johnyerhot/rquote.git
|
4
|
+
# Author: John Yerhot (john@yerhot.org)
|
5
|
+
# Sample Usage:
|
6
|
+
# quote = Rquote.new
|
7
|
+
# quote.find("aapl", "msft")
|
8
|
+
# => [{:change=>"-4.02", :price=>"169.72", :volume=>"16105013", :symbol=>"aapl"}, {:change=>"-0.42", :price=>"27.52", :volume=>"27024456", :symbol=>"msft"}]
|
9
|
+
|
10
|
+
require 'cgi'
|
11
|
+
require 'net/http'
|
12
|
+
|
13
|
+
class Rquote
|
14
|
+
|
15
|
+
@@service_uri = "http://download.finance.yahoo.com/d/quotes.csv"
|
16
|
+
|
17
|
+
def find(*args)
|
18
|
+
output = Array.new
|
19
|
+
i = 0
|
20
|
+
String.new(send_request(*args)).each do |line|
|
21
|
+
a = line.chomp.split(",")
|
22
|
+
output << { :symbol => args[i].to_s,
|
23
|
+
:price => a[0],
|
24
|
+
:change => a[1],
|
25
|
+
:volume => a[2]
|
26
|
+
}
|
27
|
+
i += 1
|
28
|
+
end
|
29
|
+
return output
|
30
|
+
end
|
31
|
+
|
32
|
+
def 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 construct_args(*args)
|
42
|
+
path = "?f=l1c1v&s=" + args.map{|x| CGI.escape(x)}.join(",")
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: johnyerhot-rQuote
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Yerhot
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-11 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: john@yerhot.org
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
files:
|
25
|
+
- README
|
26
|
+
- MIT-LICENSE
|
27
|
+
- lib/rquote.rb
|
28
|
+
has_rdoc: true
|
29
|
+
homepage: http://rquote.yerhot.org/
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
version:
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
requirements: []
|
48
|
+
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.2.0
|
51
|
+
signing_key:
|
52
|
+
specification_version: 2
|
53
|
+
summary: Yahoo Finance Stock Quote Ruby Gem
|
54
|
+
test_files: []
|
55
|
+
|