class YahooQuote
Attributes
change[R]
change_percent[R]
error[R]
exchange[R]
high[R]
is_index[R]
low[R]
message[R]
name[R]
open[R]
prev_close[R]
price[R]
symbol[RW]
trading_day[R]
volume[R]
Public Class Methods
new(symbol, apikey)
click to toggle source
# File lib/lita/handlers/yahoo_quote.rb, line 5 def initialize(symbol, apikey) # Lita.logger.debug "parsing: #{json_blob}" # hash = JSON.parse(json_blob) @symbol = symbol @apikey = apikey @is_index = false if @symbol[0] == '^' @is_index = true end response = call_api hash = JSON.parse response quote = hash['chart']['result'][0]['meta'] @symbol = quote['symbol'] @open = self.fix_number quote['previousClose'] # when "03. high" # @high = self.fix_number quote[key] # when "04. low" # @low = self.fix_number quote[key] @price = self.fix_number quote['regularMarketPrice'] # when "06. volume" # @volume = quote[key] # when "07. latest trading day" # @trading_day = quote[key] # when "08. previous close" @prev_close = self.fix_number quote['previousClose'] @change = self.fix_number @price - @prev_close @change_percent = self.fix_number ((@change / @price) * 100) end
Public Instance Methods
call_api()
click to toggle source
# File lib/lita/handlers/yahoo_quote.rb, line 46 def call_api url = "https://query1.finance.yahoo.com/v8/finance/chart/#{URI::escape @symbol}" Lita.logger.debug "#{url}" response = RestClient.get url # if @exchange # params[:stock_exchange] = @exchange # end Lita.logger.debug "response: #{response}" response end
fix_number(price_str)
click to toggle source
# File lib/lita/handlers/yahoo_quote.rb, line 38 def fix_number(price_str) price_str.to_f.round(2) end
is_index?()
click to toggle source
# File lib/lita/handlers/yahoo_quote.rb, line 42 def is_index? @is_index end