Class: Lita::Handlers::OnewheelFinance
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::OnewheelFinance
- Defined in:
- lib/lita/handlers/onewheel_finance.rb
Instance Method Summary collapse
-
#handle_alphavantage ⇒ Object
deprecated for now.
- #handle_quote(response) ⇒ Object
- #handle_world_trade_data(symbol) ⇒ Object
Instance Method Details
#handle_alphavantage ⇒ Object
deprecated for now
165 166 167 168 169 170 171 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 165 def handle_alphavantage url = "https://www.alphavantage.co/query" params = {function: 'GLOBAL_QUOTE', symbol: response.matches[0][0], apikey: config.apikey} Lita.logger.debug "#{url} #{params.inspect}" resp = RestClient.get url, {params: params} stock = GlobalQuote.new resp end |
#handle_quote(response) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 128 def handle_quote(response) stock = handle_world_trade_data response.matches[0][0] if stock.error str = "`#{stock.symbol}` not found on any stock exchange." else str = "#{IrcColors::grey}#{stock.exchange} - #{IrcColors::reset}#{stock.symbol}: #{IrcColors::blue}$#{stock.price}#{IrcColors::reset} " if stock.change >= 0 # if irc str += "#{IrcColors::green} ⬆$#{stock.change}#{IrcColors::reset}, #{IrcColors::green}#{stock.change_percent}%#{IrcColors::reset} " str += "#{IrcColors::grey}(#{stock.name})#{IrcColors::reset}" else str += "#{IrcColors::red} ↯$#{stock.change}#{IrcColors::reset}, #{IrcColors::red}#{stock.change_percent}%#{IrcColors::reset} " str += "(#{stock.name})" end end response.reply str end |
#handle_world_trade_data(symbol) ⇒ Object
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 148 def handle_world_trade_data(symbol) url = "https://api.worldtradingdata.com/api/v1/stock" params = {symbol: symbol, api_token: config.apikey} Lita.logger.debug "#{url} #{params.inspect}" resp = RestClient.get url, {params: params} Lita.logger.debug "response: #{resp}" stock = WorldTradeDataQuote.new resp if stock.error stock.symbol = symbol end stock end |