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 =
"/getreply?"
Instance Method Summary collapse
-
#initialize(api_key = "DEFAULT") ⇒ Cleverbot
constructor
Create a new session.
- #reset ⇒ Object
-
#send(message) ⇒ String
send a message to cleverbot and get an answer.
Constructor Details
Instance Method Details
#reset ⇒ Object
69 70 71 |
# File 'lib/cleverbotrb.rb', line 69 def reset params.delete('cs') end |
#send(message) ⇒ String
send a message to cleverbot and get an answer
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cleverbotrb.rb', line 50 def send() url_arg = @params url_arg["input"] = 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 |