class Lita::Handlers::Finance
Public Instance Methods
info(response)
click to toggle source
# File lib/lita/handlers/finance.rb, line 32 def info(response) symbol = response.matches[0][1] http_response = http.get( 'https://query.yahooapis.com/v1/public/yql', q: "select * from yahoo.finance.quote where symbol in ('#{symbol}')", format: 'json', env: 'store://RjdEzitN2Hceujh3tGHPj6' ) data = MultiJson.load(http_response.body) quote = data['query']['results']['quote'] quote.delete('symbol') reply = '' quote.each do |key, value| value = value.nil? ? 'N/A' : value reply << "#{key}: #{value}\n" end response.reply reply rescue response.reply 'Something went wrong. Try again.' end
search(response)
click to toggle source
# File lib/lita/handlers/finance.rb, line 7 def search(response) search = response.matches[0][1] http_response = http.get( 'http://autoc.finance.yahoo.com/autoc', query: search, region: 'EU', lang: 'en-US' ) data = MultiJson.load(http_response.body) results = data['ResultSet']['Result'] reply = '' results.each_with_index do |result, index| reply << "#{index + 1}. #{result['name']}: #{result['symbol']} - #{result['exchDisp']} - #{result['typeDisp']}\n" end response.reply !reply.empty? ? reply : 'No results found.' rescue response.reply 'Something went wrong. Try again.' end