Skip to content

Instantly share code, notes, and snippets.

@spencereldred
Created October 2, 2013 16:35
Show Gist options
  • Save spencereldred/6796568 to your computer and use it in GitHub Desktop.
Save spencereldred/6796568 to your computer and use it in GitHub Desktop.
Sinatra - stock quote app - stock_app.rb file.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment