nas-yahoo_stock 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +9 -0
- data/README.rdoc +79 -0
- data/Rakefile +22 -0
- data/lib/yahoo_stock.rb +9 -0
- data/lib/yahoo_stock/interface.rb +197 -0
- data/lib/yahoo_stock/quote.rb +78 -0
- data/spec/spec_helper.rb +3 -0
- data/spec/yahoo_stock/quote_spec.rb +235 -0
- metadata +81 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
= yahoo_stock
|
2
|
+
|
3
|
+
* http://github.com/nas/yahoo_stock
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Provides an interface to yahoo finance to get stock related data. For instance, latest trade related data, volume, 50 day moving average, market cap, etc.
|
8
|
+
|
9
|
+
You must know the stock symbol. For instance, YHOO for yahoo, GOOG for google, etc.
|
10
|
+
The kind of parameters can be passed can be found after initializing the
|
11
|
+
YahooStock::Quote object and passing valid_parameters message.
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
* Initialize quote object
|
16
|
+
|
17
|
+
quote = YahooStock::Quote.new(:stock_symbols => ['YHOO', 'GOOG'])
|
18
|
+
|
19
|
+
* To view the valid parameters that can be passed
|
20
|
+
|
21
|
+
quote.valid_parameters
|
22
|
+
|
23
|
+
* To view the current parameters used
|
24
|
+
|
25
|
+
quote.current_parameters
|
26
|
+
|
27
|
+
* To view the current stock symbols used
|
28
|
+
|
29
|
+
quote.current_symbols
|
30
|
+
|
31
|
+
* To add more stocks to the list
|
32
|
+
|
33
|
+
quote.add_symbols('MSFT', 'AAPL')
|
34
|
+
|
35
|
+
* To remove stocks from list
|
36
|
+
|
37
|
+
quote.remove_symbols('MSFT', 'AAPL')
|
38
|
+
|
39
|
+
* To get data for all stocks
|
40
|
+
|
41
|
+
quote.get_data
|
42
|
+
|
43
|
+
|
44
|
+
== INSTALL:
|
45
|
+
|
46
|
+
gem sources -a http://gems.github.com
|
47
|
+
|
48
|
+
sudo gem install yahoo_stock
|
49
|
+
|
50
|
+
== TESTS:
|
51
|
+
|
52
|
+
Tests are written using Rspec 1.2.2
|
53
|
+
|
54
|
+
To run all tests 'rake spec' from the root directory
|
55
|
+
|
56
|
+
== LICENSE:
|
57
|
+
|
58
|
+
(The MIT License)
|
59
|
+
|
60
|
+
Copyright (c) 2009 Nasir Jamal
|
61
|
+
|
62
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
63
|
+
a copy of this software and associated documentation files (the
|
64
|
+
'Software'), to deal in the Software without restriction, including
|
65
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
66
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
67
|
+
permit persons to whom the Software is furnished to do so, subject to
|
68
|
+
the following conditions:
|
69
|
+
|
70
|
+
The above copyright notice and this permission notice shall be
|
71
|
+
included in all copies or substantial portions of the Software.
|
72
|
+
|
73
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
74
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
75
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
76
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
77
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
78
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
79
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/yahoo_stock'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
# Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec 'yahoo_stock' do
|
14
|
+
self.developer 'Nasir Jamal', 'nas35_in@yahoo.com'
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'newgem/tasks'
|
18
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
19
|
+
|
20
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
21
|
+
# remove_task :default
|
22
|
+
# task :default => [:spec, :features]
|
data/lib/yahoo_stock.rb
ADDED
@@ -0,0 +1,197 @@
|
|
1
|
+
=begin
|
2
|
+
|
3
|
+
http://www.gummy-stuff.org/Yahoo-data.htm
|
4
|
+
http://finance.yahoo.com/d/quotes.csv?s=XOM+BBDb.TO+JNJ+MSFT&f=snd1l1yr
|
5
|
+
|
6
|
+
=end
|
7
|
+
|
8
|
+
=begin
|
9
|
+
|
10
|
+
Class to generate the right url and interface with yahoo
|
11
|
+
|
12
|
+
=end
|
13
|
+
|
14
|
+
require 'net/http'
|
15
|
+
module YahooStock
|
16
|
+
class Interface
|
17
|
+
|
18
|
+
class InterfaceError < RuntimeError ; end
|
19
|
+
|
20
|
+
PARAMETERS = {
|
21
|
+
:ask => 'a',
|
22
|
+
:average_daily_volume => 'a2',
|
23
|
+
:ask_size => 'a5',
|
24
|
+
:bid => 'b',
|
25
|
+
:ask_real_time => 'b2',
|
26
|
+
:bid_real_time => 'b3',
|
27
|
+
:book_value => 'b4',
|
28
|
+
:bid_size => 'b4',
|
29
|
+
:change_with_percent_change => 'c',
|
30
|
+
:change => 'c1',
|
31
|
+
:commission => 'c3',
|
32
|
+
:change_real_time => 'c6',
|
33
|
+
:after_hours_change_real_time => 'c8',
|
34
|
+
:dividend_per_share => 'd',
|
35
|
+
:last_trade_date => 'd1',
|
36
|
+
:trade_date => 'd2',
|
37
|
+
:earnings_per_share => 'e',
|
38
|
+
:error_indication => 'e1',
|
39
|
+
:eps_estimate_current_year => 'e7',
|
40
|
+
:eps_estimate_next_year => 'e8',
|
41
|
+
:eps_estimate_next_quarter => 'e9',
|
42
|
+
:day_low => 'g',
|
43
|
+
:day_high => 'h',
|
44
|
+
:fifty_two_week_low => 'j',
|
45
|
+
:fifty_two_week_high => 'k',
|
46
|
+
:holdings_gain_percent => 'g1',
|
47
|
+
:annualized_gain => 'g3',
|
48
|
+
:holdings_gain => 'g4',
|
49
|
+
:holdings_gain_percent_real_time => 'g5',
|
50
|
+
:holdings_gain_real_time => 'g6',
|
51
|
+
:more_info => 'i',
|
52
|
+
:order_book_real_time => 'i5',
|
53
|
+
:market_capitalization => 'j1',
|
54
|
+
:market_cap_real_time => 'j3',
|
55
|
+
:ebitda => 'j4',
|
56
|
+
:change_from_52_week_low => 'j5',
|
57
|
+
:percent_change_from_52_week_low => 'j6',
|
58
|
+
:last_trade_real_time_with_time => 'k1',
|
59
|
+
:change_percent_real_time => 'k2',
|
60
|
+
:change_from_52_week_high => 'k4',
|
61
|
+
:percent_change_from_52_week_high => 'k5',
|
62
|
+
:last_trade_with_time => 'l',
|
63
|
+
:last_trade_price_only => 'l1',
|
64
|
+
:high_limit => 'l2',
|
65
|
+
:low_limit => 'l3',
|
66
|
+
:day_range => 'm',
|
67
|
+
:day_range_real_time => 'm2',
|
68
|
+
:fifty_day_moving_average => 'm3',
|
69
|
+
:two_hundred_day_moving_average => 'm4',
|
70
|
+
:change_from_200_day_moving_average => 'm5',
|
71
|
+
:percent_change_from_200_day_moving_average => 'm6',
|
72
|
+
:change_from_50_day_moving_average => 'm7',
|
73
|
+
:percent_change_from_50_day_moving_average => 'm8',
|
74
|
+
:name => 'n',
|
75
|
+
:notes => 'n4',
|
76
|
+
:open => 'o',
|
77
|
+
:previous_close => 'p',
|
78
|
+
:price_paid => 'p1',
|
79
|
+
:change_in_percent => 'p2',
|
80
|
+
:ex_dividend_date => 'q',
|
81
|
+
:p_e_ratio => 'r',
|
82
|
+
:dividend_pay_date => 'r1',
|
83
|
+
:p_e_ratio_real_time => 'r2',
|
84
|
+
:peg_ratio => 'r5',
|
85
|
+
:price_eps_estimate_current_year => 'r6',
|
86
|
+
:price_eps_estimate_next_year => 'r7',
|
87
|
+
:symbol => 's',
|
88
|
+
:shares_owned => 's1',
|
89
|
+
:short_ratio => 's7',
|
90
|
+
:last_trade_time => 't1',
|
91
|
+
:trade_links => 't6',
|
92
|
+
:ticker_trend => 't7',
|
93
|
+
:one_yr_target_price => 't8',
|
94
|
+
:volume => 'v',
|
95
|
+
:holdings_value => 'v1',
|
96
|
+
:holdings_value_real_time => 'v7',
|
97
|
+
:fifty_two_week_range => 'w',
|
98
|
+
:day_value_change => 'w1',
|
99
|
+
:day_value_change_real_time => 'w4',
|
100
|
+
:stock_exchange => 'x',
|
101
|
+
:dividend_yield => 'y',
|
102
|
+
}
|
103
|
+
|
104
|
+
attr_accessor :stock_symbols, :yahoo_url_parameters
|
105
|
+
|
106
|
+
def initialize(stock_params_hash)
|
107
|
+
unless stock_params_hash
|
108
|
+
raise InterfaceError, 'You must pass a hash of stock symbols and the data you would like to see'
|
109
|
+
end
|
110
|
+
if !stock_params_hash[:stock_symbols] || stock_params_hash[:stock_symbols].length.zero?
|
111
|
+
raise(InterfaceError, 'No stocks passed')
|
112
|
+
end
|
113
|
+
if !stock_params_hash[:read_parameters] || stock_params_hash[:read_parameters].length.zero?
|
114
|
+
raise InterfaceError, 'Dont know what data to get'
|
115
|
+
end
|
116
|
+
@stock_symbols = stock_params_hash[:stock_symbols]
|
117
|
+
@yahoo_url_parameters = stock_params_hash[:read_parameters]
|
118
|
+
@base_url = "http://download.finance.yahoo.com/d/quotes.csv"
|
119
|
+
end
|
120
|
+
|
121
|
+
def full_url
|
122
|
+
all_stock_symbols = stock_symbols.join('+')
|
123
|
+
parameter_values = yahoo_url_parameters.collect {|v| parameters[v]}.join('')
|
124
|
+
if !all_stock_symbols.any?
|
125
|
+
raise InterfaceError, "You must add atleast one stock symbol to get stock data"
|
126
|
+
end
|
127
|
+
if !parameter_values.any?
|
128
|
+
raise InterfaceError, "You must add atleast one parameter to get stock data"
|
129
|
+
end
|
130
|
+
"#{@base_url}?s=#{all_stock_symbols}&f=#{parameter_values}"
|
131
|
+
end
|
132
|
+
|
133
|
+
def get_values
|
134
|
+
Net::HTTP.get(URI.parse(full_url)).gsub(/\"/,'').split(/\r\n/)
|
135
|
+
end
|
136
|
+
|
137
|
+
def results
|
138
|
+
stock = {}
|
139
|
+
get_values.each_with_index do |values, index|
|
140
|
+
parsed_values = values.split(',')
|
141
|
+
stock[stock_symbols[index]] ||= {}
|
142
|
+
parsed_values.each_with_index do |value, i|
|
143
|
+
stock[stock_symbols[index]][yahoo_url_parameters[i]] = value
|
144
|
+
end
|
145
|
+
end
|
146
|
+
stock
|
147
|
+
end
|
148
|
+
|
149
|
+
def add_symbols(*symbols)
|
150
|
+
symbols.each do |symbol|
|
151
|
+
unless stock_symbols.include?(symbol)
|
152
|
+
stock_symbols << symbol
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
def remove_symbols(*symbols)
|
158
|
+
symbols.each do |symbol|
|
159
|
+
unless stock_symbols.include?(symbol)
|
160
|
+
raise InterfaceError, "Cannot remove stock symbol #{symbol} as it is currently not present."
|
161
|
+
end
|
162
|
+
stock_symbols.reject!{|stock_sym| stock_sym == symbol}
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def add_parameters(*parameters)
|
167
|
+
parameters.each do |parameter|
|
168
|
+
unless allowed_parameters.include?(parameter)
|
169
|
+
raise InterfaceError, "Interface parameter #{parameter} is not a valid parameter."
|
170
|
+
end
|
171
|
+
unless yahoo_url_parameters.include?(parameter)
|
172
|
+
yahoo_url_parameters << parameter
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def remove_parameters(*parameters)
|
178
|
+
parameters.each do |parameter|
|
179
|
+
unless yahoo_url_parameters.include?(parameter)
|
180
|
+
raise InterfaceError, "Parameter #{parameter} is not present in current list"
|
181
|
+
end
|
182
|
+
yahoo_url_parameters.reject!{|parameter_key| parameter_key == parameter}
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
def allowed_parameters
|
187
|
+
parameters.keys
|
188
|
+
end
|
189
|
+
|
190
|
+
private
|
191
|
+
|
192
|
+
def parameters
|
193
|
+
PARAMETERS
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module YahooStock
|
2
|
+
class Quote
|
3
|
+
|
4
|
+
class QuoteException < RuntimeError; end
|
5
|
+
|
6
|
+
# options expects a hash with two key value pairs
|
7
|
+
# :stock_symbols => 'Array of stock symbols'
|
8
|
+
# e.g. :stock_symbols => [:MSFT,:YHOO]
|
9
|
+
# another :read_parameters => 'array of values'
|
10
|
+
# e.g. :read_parameters => [:last_trade_price_only, :last_trade_date]
|
11
|
+
# usage YahooStock::Quote.new(:stock_symbols => ['MSFT','YHOO'], :read_parameters => [:last_trade_price_only, :last_trade_date])
|
12
|
+
def initialize(options)
|
13
|
+
if options.nil? || !options[:stock_symbols]
|
14
|
+
raise QuoteException, "You must provide a hash of stock symbols to fetch data"
|
15
|
+
end
|
16
|
+
unless options[:stock_symbols].any?
|
17
|
+
raise QuoteException, "You must provide atleast one stock symbol to fetch data"
|
18
|
+
end
|
19
|
+
if !(options[:read_parameters] && options[:read_parameters].any?)
|
20
|
+
options[:read_parameters] = [:last_trade_price_only, :last_trade_date]
|
21
|
+
end
|
22
|
+
options[:stock_symbols] = options[:stock_symbols].to_a unless options[:stock_symbols].kind_of?(Array)
|
23
|
+
@interface = YahooStock::Interface.new(options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def get_data
|
27
|
+
@interface.results
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_symbols(*symbols)
|
31
|
+
symbols.each { |symbol| @interface.add_symbols(symbol) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def remove_symbols(*symbols)
|
35
|
+
symbols.each { |symbol| @interface.remove_symbols(symbol) }
|
36
|
+
end
|
37
|
+
|
38
|
+
def clear_symbols
|
39
|
+
@interface.stock_symbols.clear
|
40
|
+
end
|
41
|
+
|
42
|
+
def current_symbols
|
43
|
+
@interface.stock_symbols
|
44
|
+
end
|
45
|
+
|
46
|
+
def add_parameters(*parameters)
|
47
|
+
parameters.each { |parameter| @interface.add_parameters(parameter) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def remove_parameters(*parameters)
|
51
|
+
parameters.each { |parameter| @interface.remove_parameters(parameter) }
|
52
|
+
end
|
53
|
+
|
54
|
+
def current_parameters
|
55
|
+
sort_symbols(@interface.yahoo_url_parameters)
|
56
|
+
end
|
57
|
+
|
58
|
+
def use_all_parameters
|
59
|
+
params = valid_parameters.each {|parameter| add_parameters(parameter)}
|
60
|
+
sort_symbols(params)
|
61
|
+
end
|
62
|
+
|
63
|
+
def clear_parameters
|
64
|
+
@interface.yahoo_url_parameters.clear
|
65
|
+
end
|
66
|
+
|
67
|
+
def valid_parameters
|
68
|
+
sort_symbols(@interface.allowed_parameters)
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def sort_symbols(array_of_symbols)
|
74
|
+
array_of_symbols.map(&:id2name).sort.map(&:to_sym)
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,235 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "/../spec_helper")
|
2
|
+
|
3
|
+
module YahooStock
|
4
|
+
describe Quote do
|
5
|
+
|
6
|
+
describe "initialize" do
|
7
|
+
|
8
|
+
it "should raise error when no parameter is passed" do
|
9
|
+
lambda { YahooStock::Quote.new }.should raise_error
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should raise QuoteException error when parameter passed is nil" do
|
13
|
+
lambda { YahooStock::Quote.new(nil)}.should raise_error Quote::QuoteException
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should raise QuoteException when a hash of stock_symbols are not passed" do
|
17
|
+
lambda { YahooStock::Quote.new(:misspelled => 'YHOO')}.should raise_error(Quote::QuoteException, 'You must provide a hash of stock symbols to fetch data')
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise QuoteException when stock symbols hash key value is an emtpy array" do
|
21
|
+
lambda { YahooStock::Quote.new(:stock_symbols => [])}.should raise_error(Quote::QuoteException, 'You must provide atleast one stock symbol to fetch data')
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should raise QuoteException when stock symbols hash key value is an emtpy string" do
|
25
|
+
lambda { YahooStock::Quote.new(:stock_symbols => '')}.should raise_error(Quote::QuoteException, 'You must provide atleast one stock symbol to fetch data')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should create 2 read parameter when no parameters are passed" do
|
29
|
+
quote = YahooStock::Quote.new(:stock_symbols => 'test')
|
30
|
+
quote.current_parameters.length.should eql(2)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should have last_trade_price_only key in the read parameters when no keys are passed" do
|
34
|
+
quote = YahooStock::Quote.new(:stock_symbols => 'test')
|
35
|
+
quote.current_parameters.should include(:last_trade_price_only)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should have last_trade_date key in the read parameters when no keys are passed" do
|
39
|
+
quote = YahooStock::Quote.new(:stock_symbols => 'test')
|
40
|
+
quote.current_parameters.should include(:last_trade_date)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should convert the symbols passed to an array when passed as a single string" do
|
44
|
+
quote = YahooStock::Quote.new(:stock_symbols => 'test')
|
45
|
+
quote.current_symbols.should eql(['test'])
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should not keep stock symbols as a string" do
|
49
|
+
quote = YahooStock::Quote.new(:stock_symbols => 'test')
|
50
|
+
quote.current_symbols.should_not eql('test')
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should create a new instance of the Stock Interface class" do
|
54
|
+
YahooStock::Interface.should_receive(:new)
|
55
|
+
YahooStock::Quote.new(:stock_symbols => 'test')
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "subject" do
|
61
|
+
|
62
|
+
before(:each) do
|
63
|
+
@interface = mock(YahooStock::Interface)
|
64
|
+
YahooStock::Interface.stub!(:new).and_return(@interface)
|
65
|
+
@quote = YahooStock::Quote.new(:stock_symbols => 'MSFT')
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "get_data" do
|
69
|
+
|
70
|
+
it "should get the results from the interface" do
|
71
|
+
@interface.should_receive(:results)
|
72
|
+
@quote.get_data
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "add_symbols" do
|
77
|
+
|
78
|
+
it "should add the symbol to existing symbols by calling add symbols on interface" do
|
79
|
+
@interface.should_receive(:add_symbols)
|
80
|
+
@quote.add_symbols('new_symbol')
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should add the symbol to existing symbols by calling add symbols on interface for each sybmol" do
|
84
|
+
@interface.should_receive(:add_symbols).exactly(2).times
|
85
|
+
@quote.add_symbols('new_symbol', 'another_symbol')
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "remove_symbols" do
|
91
|
+
|
92
|
+
it "should remove the symbol from existing symbols by calling remove symbols on interface" do
|
93
|
+
@interface.should_receive(:remove_symbols)
|
94
|
+
@quote.remove_symbols('remove_symbol')
|
95
|
+
end
|
96
|
+
|
97
|
+
it "should remove the symbol from existing symbols by calling remove symbols on interface for each symbol" do
|
98
|
+
@interface.should_receive(:remove_symbols).exactly(2).times
|
99
|
+
@quote.remove_symbols('new_symbol', 'another_symbol')
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
|
104
|
+
describe "clear_symbols" do
|
105
|
+
|
106
|
+
it "should get all stock symbols from the interface" do
|
107
|
+
@interface.should_receive(:stock_symbols).and_return([])
|
108
|
+
@quote.clear_symbols
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should remove the symbol from existing symbols by calling remove symbols on interface for each symbol" do
|
112
|
+
symbols = ['symbol1', 'symbol2']
|
113
|
+
@interface.stub!(:stock_symbols).and_return(symbols)
|
114
|
+
symbols.should_receive(:clear)
|
115
|
+
@quote.clear_symbols
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
|
120
|
+
describe "current_symbols" do
|
121
|
+
|
122
|
+
it "should get all stock symbols from the interface" do
|
123
|
+
@interface.should_receive(:stock_symbols)
|
124
|
+
@quote.current_symbols
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "add_parameters" do
|
130
|
+
|
131
|
+
it "should add the parameter to existing parameter by calling add parameters on interface" do
|
132
|
+
@interface.should_receive(:add_parameters)
|
133
|
+
@quote.add_parameters('param1')
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should add the parameter to existing parameters by calling add parameters on interface for each parameter" do
|
137
|
+
@interface.should_receive(:add_parameters).exactly(2).times
|
138
|
+
@quote.add_parameters('param1', 'param2')
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "remove_parameters" do
|
144
|
+
|
145
|
+
it "should remove the parameter from existing parameters by calling remove parameters on interface" do
|
146
|
+
@interface.should_receive(:remove_parameters)
|
147
|
+
@quote.remove_parameters('remove_parameter')
|
148
|
+
end
|
149
|
+
|
150
|
+
it "should remove the parameter from existing parameters by calling remove parameters on interface for each parameter" do
|
151
|
+
@interface.should_receive(:remove_parameters).exactly(2).times
|
152
|
+
@quote.remove_parameters('param1', 'param2')
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "valid_parameters" do
|
158
|
+
|
159
|
+
it "should get the valid parameters by sending allowed parameters message to the yahoo interface" do
|
160
|
+
@quote.stub!(:sort_symbols)
|
161
|
+
@interface.should_receive(:allowed_parameters)
|
162
|
+
@quote.valid_parameters
|
163
|
+
end
|
164
|
+
|
165
|
+
it "sort the parameters after fetching them" do
|
166
|
+
@interface.stub!(:allowed_parameters)
|
167
|
+
@quote.should_receive(:sort_symbols)
|
168
|
+
@quote.valid_parameters
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "current_parameters" do
|
174
|
+
|
175
|
+
it "should get all current parameters from the interface" do
|
176
|
+
@quote.stub!(:sort_symbols)
|
177
|
+
@interface.should_receive(:yahoo_url_parameters)
|
178
|
+
@quote.current_parameters
|
179
|
+
end
|
180
|
+
|
181
|
+
it "should sort all received current parameters" do
|
182
|
+
@interface.stub!(:yahoo_url_parameters)
|
183
|
+
@quote.should_receive(:sort_symbols)
|
184
|
+
@quote.current_parameters
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
188
|
+
|
189
|
+
describe "use_all_parameters" do
|
190
|
+
|
191
|
+
before(:each) do
|
192
|
+
@quote.stub!(:sort_symbols)
|
193
|
+
@interface.stub!(:allowed_parameters)
|
194
|
+
end
|
195
|
+
|
196
|
+
it "should get all valid parameters" do
|
197
|
+
@quote.should_receive(:valid_parameters).and_return([])
|
198
|
+
@quote.use_all_parameters
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should sort all received current parameters" do
|
202
|
+
@quote.stub!(:valid_parameters).and_return([])
|
203
|
+
@quote.should_receive(:sort_symbols)
|
204
|
+
@quote.use_all_parameters
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should add each parameter" do
|
208
|
+
@quote.stub!(:valid_parameters).and_return([:param1, :param2])
|
209
|
+
@quote.should_receive(:add_parameters).exactly(2).times
|
210
|
+
@quote.use_all_parameters
|
211
|
+
end
|
212
|
+
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "clear_parameters" do
|
216
|
+
|
217
|
+
it "should get all values for parameters from the interface" do
|
218
|
+
@interface.should_receive(:yahoo_url_parameters).and_return([])
|
219
|
+
@quote.clear_parameters
|
220
|
+
end
|
221
|
+
|
222
|
+
it "should remove the parameter from existing parameters by calling remove parameters on interface for each parameter" do
|
223
|
+
params = ['param1', 'param2']
|
224
|
+
@interface.stub!(:yahoo_url_parameters).and_return(params)
|
225
|
+
params.should_receive(:clear)
|
226
|
+
@quote.clear_parameters
|
227
|
+
end
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
|
235
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nas-yahoo_stock
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nasir Jamal
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-08-31 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mime-types
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "1.15"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: diff-lcs
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.1.2
|
34
|
+
version:
|
35
|
+
description: Yahoo Stock is a Ruby library for extracting information about stocks from yahoo finance
|
36
|
+
email: nas35_in@yahoo.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- README.rdoc
|
43
|
+
files:
|
44
|
+
- History.txt
|
45
|
+
- README.rdoc
|
46
|
+
- Manifest.txt
|
47
|
+
- Rakefile
|
48
|
+
- lib/yahoo_stock.rb
|
49
|
+
- lib/yahoo_stock/quote.rb
|
50
|
+
- lib/yahoo_stock/interface.rb
|
51
|
+
- spec/spec_helper.rb
|
52
|
+
- spec/yahoo_stock/quote_spec.rb
|
53
|
+
has_rdoc: true
|
54
|
+
homepage: http://github.com/nas/yahoo_stock
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options:
|
57
|
+
- --inline-source
|
58
|
+
- --charset=UTF-8
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: "1.8"
|
66
|
+
version:
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: "0"
|
72
|
+
version:
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.2.0
|
77
|
+
signing_key:
|
78
|
+
specification_version: 2
|
79
|
+
summary: Yahoo Stock is a Ruby library for extracting information about stocks from yahoo finance.
|
80
|
+
test_files: []
|
81
|
+
|