Class: Cleverbot
- Inherits:
-
Object
- Object
- Cleverbot
- Defined in:
- lib/cleverbotrb.rb
Overview
This class represent cleverbot session
Constant Summary collapse
- HOST =
"www.cleverbot.com"
- ENDPOINT =
"/webservicemin?uc=777"
- PARAMS =
{ 'stimulus' => '', 'start' => 'y', 'sessionid' => '', 'vText8' => '', 'vText7' => '', 'vText6' => '', 'vText5' => '', 'vText4' => '', 'vText3' => '', 'vText2' => '', 'icognoid' => 'wsf', 'icognocheck' => '', 'fno' => '0', 'prevref' => '', 'emotionaloutput' => '', 'asbotname' => '', 'ttsvoice' => '', 'typing' => '', 'lineref' => '', 'sub' => 'Say', 'islearning' => '1', 'cleanslate' => 'false' }
- RESPONSE_KEY =
[ 'message', 'sessionid', 'logurl', 'vText8', 'vText7', 'vText6', 'vText5', 'vText4', 'vText3', 'vText2', 'prevref', '', 'emotionalhistory', 'ttsLocMP3', 'ttsLocTXT', 'ttsLocTXT3', 'ttsText', 'lineref', 'lineURL', 'linePOST', 'lineChoices', 'lineChoicesAbbrev', 'typingData', 'divert' ]
Instance Method Summary collapse
-
#initialize(api_key = "DEFAULT") ⇒ Cleverbot
constructor
Create a new session.
-
#send(message) ⇒ String
send a message to cleverbot and get an answer.
Constructor Details
Instance Method Details
#send(message) ⇒ String
send a message to cleverbot and get an answer
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cleverbotrb.rb', line 68 def send() body = @params body["stimulus"] = body["icognocheck"] = digest(URI.encode_www_form(body)[9...35]) body_str = URI.encode_www_form(body) #params_encode(body) headers = { 'Content-Type' => 'application/x-www-form-urlencoded', 'Content-Length' => body_str.size.to_s, 'Cache-Control' => 'no-cache', 'Cookie' => (@cookies) } req = Net::HTTP.new(HOST, 80) resp = req.post(@endpoint, body_str, headers) if resp.code != "200" return nil end response = resp.body.split("\r") save_data(response) return response[0] end |