Class: Cleverbot::Client
- Inherits:
-
Object
- Object
- Cleverbot::Client
- Defined in:
- lib/cleverbot/client.rb
Overview
A client that wraps basic API functionality and can maintain multiple conversations associated with an identifier
Instance Attribute Summary collapse
-
#conversations ⇒ Hash<thing, Conversation>
readonly
The conversations initiated by this client.
-
#key ⇒ String
readonly
API key used to make requests with this Client.
Instance Method Summary collapse
-
#conversation(identifier = :default) ⇒ Conversation
The conversation associated with this identifier.
-
#delete(identifier = :default) ⇒ Conversation
Deletes a conversation.
-
#initialize(key) ⇒ Client
constructor
Create a new Client.
-
#say(message, identifier = :default) ⇒ String
Say something to the API.
Constructor Details
#initialize(key) ⇒ Client
Create a new Client
33 34 35 36 |
# File 'lib/cleverbot/client.rb', line 33 def initialize(key) @key = key @conversations = {} end |
Instance Attribute Details
#conversations ⇒ Hash<thing, Conversation> (readonly)
Returns the conversations initiated by this client.
29 30 31 |
# File 'lib/cleverbot/client.rb', line 29 def conversations @conversations end |
#key ⇒ String (readonly)
Returns API key used to make requests with this Client.
26 27 28 |
# File 'lib/cleverbot/client.rb', line 26 def key @key end |
Instance Method Details
#conversation(identifier = :default) ⇒ Conversation
Returns the conversation associated with this identifier.
40 41 42 |
# File 'lib/cleverbot/client.rb', line 40 def conversation(identifier = :default) @conversations[identifier] end |
#delete(identifier = :default) ⇒ Conversation
Deletes a conversation
58 59 60 |
# File 'lib/cleverbot/client.rb', line 58 def delete(identifier = :default) @conversations.delete identifier end |
#say(message, identifier = :default) ⇒ String
Say something to the API
48 49 50 51 52 53 |
# File 'lib/cleverbot/client.rb', line 48 def say(, identifier = :default) convo = conversation(identifier) || Conversation.new(key) @conversations[identifier] = convo convo.reply end |