class Cleverbot
This class represent cleverbot session
@author d0p1
Constants
- ENDPOINT
- HOST
Public Class Methods
new(api_key)
click to toggle source
Create a new session
# File lib/cleverbotrb.rb, line 37 def initialize (api_key) @params = { "key" => api_key, "wrapper" => "cleverbotrb" } @endpoint = ENDPOINT end
Public Instance Methods
reset()
click to toggle source
# File lib/cleverbotrb.rb, line 69 def reset params.delete('cs') end
send(message)
click to toggle source
send a message to cleverbot and get an answer
@param message [String] @return [String] the answer statement
# File lib/cleverbotrb.rb, line 50 def send(message) url_arg = @params url_arg["input"] = message url_arg_str = URI.encode_www_form(url_arg) headers = { 'User-Agent' => 'cleverbotrb https://github.com/d0p1s4m4/cleverbotrb', } req = Net::HTTP.new(HOST, 80) resp = req.get(@endpoint + url_arg_str, headers) if resp.code != "200" return nil end response = JSON.parse(resp.body) @params['cs'] = response['cs'] return response['output'] end