Class: Lita::Handlers::OnewheelDuckDuckGo
- Inherits:
-
Handler
- Object
- Handler
- Lita::Handlers::OnewheelDuckDuckGo
- Defined in:
- lib/lita/handlers/onewheel_duckduckgo.rb
Instance Method Summary collapse
Instance Method Details
#get_result(query) ⇒ Object
23 24 25 |
# File 'lib/lita/handlers/onewheel_duckduckgo.rb', line 23 def get_result(query) JSON.parse(RestClient.get("http://api.duckduckgo.com/?q=#{query}&format=json")) end |
#search(response) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lita/handlers/onewheel_duckduckgo.rb', line 8 def search(response) query = response.matches[0][0] Lita.logger.debug "Querying for #{query}" result = get_result(query) Lita.logger.debug "Result: #{result}" reply = 'DuckDuckGo Result: ' if result['Abstract'].empty? reply += result['AbstractURL'] else reply += result['Abstract'][0..250] end Lita.logger.debug "Reply: #{reply}" response.reply reply end |