Module: Cleverbot::API
- Defined in:
- lib/cleverbot/api.rb
Overview
Wrapper for Cleverbot’s REST API
Constant Summary collapse
- API_URL =
Base API url
'http://cleverbot.com'.freeze
- WRAPPER =
Name of the library
'cleverbot'.freeze
- MAX_BACKOFF =
The most time to wait to retry for a response from the API in seconds. This is because, at the time of writing, the API will sometimes return an empty response and you must retry your request.
60
Class Method Summary collapse
-
.get_reply(key, input, conversation = nil, retry_empty: true, backoff: 1) ⇒ String
The reply.
-
.get_request(route = '', params = {}) ⇒ Object
Executre a GET request.
Class Method Details
.get_reply(key, input, conversation = nil, retry_empty: true, backoff: 1) ⇒ String
Returns the reply.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cleverbot/api.rb', line 36 def get_reply(key, input, conversation = nil, retry_empty: true, backoff: 1) return if backoff > MAX_BACKOFF reply = get_request( 'getreply', key: key, input: input, cs: conversation ) return reply unless retry_empty && reply['output'].nil? puts "Reponse empty! Retrying after #{backoff} seconds." sleep backoff get_reply(key, input, conversation, retry_empty: true, backoff: backoff * 2) end |