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