Class: Cleverbot::Client
- Inherits:
-
Object
- Object
- Cleverbot::Client
- Includes:
- HTTParty
- Defined in:
- lib/cleverbot/client.rb
Overview
Ruby wrapper for Cleverbot.com.
Constant Summary
- DEFAULT_PARAMS =
The default form variables for POSTing to Cleverbot.com
{ 'stimulus' => '', 'start' => 'y', 'sessionid' => '', 'vText8' => '', 'vText7' => '', 'vText6' => '', 'vText5' => '', 'vText4' => '', 'vText3' => '', 'vText2' => '', 'icognoid' => 'wsf', 'icognocheck' => '', 'fno' => '0', 'prevref' => '', 'emotionaloutput' => '', 'emotionalhistory' => '', 'asbotname' => '', 'ttsvoice' => '', 'typing' => '', 'lineref' => '', 'sub' => 'Say', 'islearning' => '1', 'cleanslate' => 'false', }
- PATH =
The path to the form endpoint on Cleverbot.com.
'/webservicemin'
Instance Attribute Summary (collapse)
-
- (Object) params
readonly
Holds the parameters for an instantiated Client.
Class Method Summary (collapse)
-
+ (Object) digest(body)
Creates a digest from the form parameters.
-
+ (Object) write(message = '', params = {})
Sends a message to Cleverbot.com and returns a Hash containing the parameters received.
Instance Method Summary (collapse)
-
- (Client) initialize(params = {})
constructor
Initializes a Client with given parameters.
-
- (Object) write(message = '')
Sends a message and returns a String with the message received.
Constructor Details
- (Client) initialize(params = {})
Initializes a Client with given parameters.
Parameters
- params
-
Optional Hash holding the initial parameters. Defaults to {}.
73 74 75 |
# File 'lib/cleverbot/client.rb', line 73 def initialize params={} @params = params end |
Instance Attribute Details
- (Object) params (readonly)
Holds the parameters for an instantiated Client.
43 44 45 |
# File 'lib/cleverbot/client.rb', line 43 def params @params end |
Class Method Details
+ (Object) digest(body)
Creates a digest from the form parameters.
Parameters
- body
-
String to be digested.
50 51 52 |
# File 'lib/cleverbot/client.rb', line 50 def self.digest body Digest::MD5.hexdigest body[9...29] end |
+ (Object) write(message = '', params = {})
Sends a message to Cleverbot.com and returns a Hash containing the parameters received.
Parameters
- message
-
Optional String holding the message to be sent. Defaults to ''.
- params
-
Optional Hash with form parameters. Merged with DEFAULT_PARAMS. Defaults to {}.
60 61 62 63 64 65 66 |
# File 'lib/cleverbot/client.rb', line 60 def self.write ='', params={} body = DEFAULT_PARAMS.merge params body['stimulus'] = body['icognocheck'] = digest HashConversions.to_params(body) post(PATH, :body => body).parsed_response end |
Instance Method Details
- (Object) write(message = '')
Sends a message and returns a String with the message received. Updates #params to maintain state.
Parameters
- message
-
Optional String holding the message to be sent. Defaults to ''.
82 83 84 85 86 87 88 89 |
# File 'lib/cleverbot/client.rb', line 82 def write ='' response = self.class.write , @params = response['message'] response.keep_if { |key, value| DEFAULT_PARAMS.keys.include? key } @params.merge! response @params.delete_if { |key, value| DEFAULT_PARAMS[key] == value } end |