Class: Lita::Handlers::OnewheelDuckDuckGo

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/onewheel_duckduckgo.rb

Instance Method Summary collapse

Instance Method Details

#get_result(query) ⇒ Object



25
26
27
# File 'lib/lita/handlers/onewheel_duckduckgo.rb', line 25

def get_result(query)
  JSON.parse(RestClient.get("http://api.duckduckgo.com/?q=#{query}&format=json"))
end

#search(response) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/lita/handlers/onewheel_duckduckgo.rb', line 11

def search(response)
  query = response.matches[0][0]
  Lita.logger.debug "Querying for #{query}"
  result = get_result(query)
  Lita.logger.debug "Result: #{result}"
  if result['Abstract'].empty?
    reply = result['AbstractURL']
  else
    reply = result['Abstract'][0..250]
  end
  Lita.logger.debug "Reply: #{reply}"
  response.reply reply
end