Class: CleverBot

Inherits:
Object
  • Object
show all
Defined in:
lib/cleverbot-api.rb

Instance Method Summary collapse

Constructor Details

#initializeCleverBot

Returns a new instance of CleverBot.


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/cleverbot-api.rb', line 5

def initialize
  @service_uri = URI.parse 'http://www.cleverbot.com/webservicemin'
  @post_params = {
    start: 'y',
    icognoid: 'wsf',
    fno: '0',
    sub: 'Say',
    islearning: '1',
    cleanslate: 'false'
  }
  @http = Net::HTTP.new @service_uri.host, @service_uri.port
  @http.read_timeout = nil
  @http.open_timeout = nil
  @backlog = []
end

Instance Method Details

#backlogObject


30
31
32
# File 'lib/cleverbot-api.rb', line 30

def backlog
  @backlog.map(&:dup)
end

#think(thought) ⇒ Object


21
22
23
24
25
26
27
28
# File 'lib/cleverbot-api.rb', line 21

def think thought
  @post_params['stimulus'] = thought
  response_data = make_request
  save_post response_data
  response = CleverBotResponse.new response_data
  @backlog.push response
  response.answer
end