Class: TalkApi::Response
- Inherits:
-
Object
- Object
- TalkApi::Response
- Defined in:
- lib/talk_api/response.rb
Overview
Response class
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#results ⇒ Object
readonly
Returns the value of attribute results.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #first_message ⇒ Object
-
#initialize(status, message, results = []) ⇒ Response
constructor
A new instance of Response.
- #success? ⇒ Boolean
Constructor Details
#initialize(status, message, results = []) ⇒ Response
Returns a new instance of Response.
10 11 12 13 14 |
# File 'lib/talk_api/response.rb', line 10 def initialize(status, , results = []) @status = status @message = @results = results.map { |result| Result.new(result[:perplexity], result[:reply]) } if success? end |
Instance Attribute Details
#message ⇒ Object (readonly)
Returns the value of attribute message.
6 7 8 |
# File 'lib/talk_api/response.rb', line 6 def @message end |
#results ⇒ Object (readonly)
Returns the value of attribute results.
6 7 8 |
# File 'lib/talk_api/response.rb', line 6 def results @results end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
6 7 8 |
# File 'lib/talk_api/response.rb', line 6 def status @status end |
Instance Method Details
#first_message ⇒ Object
20 21 22 23 24 |
# File 'lib/talk_api/response.rb', line 20 def return nil unless success? @results.first.reply end |
#success? ⇒ Boolean
16 17 18 |
# File 'lib/talk_api/response.rb', line 16 def success? @status.zero? end |