require 'sinatra'
require 'sinatra/reloader'
require 'yahoofinance'
get '/' do
@method = "post"
@action = "/stock"
erb :form
end
# Responds with a form to get a new stock symbol
get '/stock/new' do
@method = "post"
@action = "/stock"
erb :form
end
# Receives 'new' stock symbol
post '/stock' do
quote_type = YahooFinance::StandardQuote
quote_symbols = params['stock_symbol']
@quotes = [{'yhoo' => 109.22}]
YahooFinance::get_quotes( quote_type, quote_symbols ) do |qt|
@quotes.push( {
date: qt.date,
symbol: qt.symbol,
close: qt.lastTrade,
volume: qt.volume
} )
@quotes.shift
end
erb :index
end