class Ruboty::Handlers::Ma
Constants
- HOST
- PATH
Public Instance Methods
ma(message)
click to toggle source
# File lib/ruboty/handlers/ma.rb, line 18 def ma(message) res = client.get do |req| req.params["appid"] = ENV["YAHOO_APPID"] req.params["sentence"] = message[:query] req.params["results"] = "ma" end body = res.body["ResultSet"]["ma_result"]["word_list"]["word"] || [] body = [body] if body.class != Array message.reply(body.map { |word| "#{word['surface']}(#{word['pos']})" }.join(" / ")) rescue => e Ruboty.logger.error %(Error: #{e.class}: #{e.message}\n#{e.backtrace.join("\n")}) end
Private Instance Methods
client()
click to toggle source
# File lib/ruboty/handlers/ma.rb, line 33 def client @client ||= Faraday.new(url: url) do |faraday| faraday.request :url_encoded faraday.response :xml faraday.adapter Faraday.default_adapter end end
url()
click to toggle source
# File lib/ruboty/handlers/ma.rb, line 41 def url %(http://#{HOST}/#{PATH}) end