17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/lita-wolframalpha.rb', line 17
def wolframalpha(response)
question = response.match_data.captures.join
query = CGI.escape(question)
url = "http://api.wolframalpha.com/v2/query?input=#{query}&appid=#{config.appid}"
answer = nil
begin
doc = Nokogiri::XML(open(url, "User-Agent" => "lita-wolframalpha/#{"1.0"} for Lita (https://lita.io)"))
answer = doc.css("pod[@id='Result'] plaintext").first.text
rescue => e
log.debug e
raise e
answer = "Couldn't get a clear answer, see: http://www.wolframalpha.com/input/?i=#{query}"
end
response.reply(answer)
end
|