Class: TalkApi::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/talk_api/response.rb

Overview

Response class

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

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, message, results = [])
  @status = status
  @message = message
  @results = results.map { |result| Result.new(result[:perplexity], result[:reply]) } if success?
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



6
7
8
# File 'lib/talk_api/response.rb', line 6

def message
  @message
end

#resultsObject (readonly)

Returns the value of attribute results.



6
7
8
# File 'lib/talk_api/response.rb', line 6

def results
  @results
end

#statusObject (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_messageObject



20
21
22
23
24
# File 'lib/talk_api/response.rb', line 20

def first_message
  return nil unless success?

  @results.first.reply
end

#success?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/talk_api/response.rb', line 16

def success?
  @status.zero?
end