Class: Pandorified::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/pandorified/result.rb

Overview

The result of sending a message to a bot, including the response message if successful.

Instance Method Summary collapse

Constructor Details

#initialize(response_body) ⇒ Result

Returns a new instance of Result.



10
11
12
# File 'lib/pandorified/result.rb', line 10

def initialize(response_body)
  @xml = REXML::Document.new(response_body)
end

Instance Method Details

#botidString

Returns The botid of the bot this result is for.

Returns:

  • (String)

    The botid of the bot this result is for.



57
58
59
# File 'lib/pandorified/result.rb', line 57

def botid
  @botid ||= REXML::XPath.first(@xml, '/result/@botid').value
end

#custidString

Returns The custid for this session.

Returns:

  • (String)

    The custid for this session.



62
63
64
# File 'lib/pandorified/result.rb', line 62

def custid
  @custid ||= REXML::XPath.first(@xml, '/result/@custid').value
end

#error?Boolean

Note:

After checking if there is an error, you can read the error message with #message.

Returns ‘true` if Pandorabots returned an error.

Returns:

  • (Boolean)

    ‘true` if Pandorabots returned an error.



41
42
43
# File 'lib/pandorified/result.rb', line 41

def error?
  !success?
end

#inputString

Returns The orginal input that triggered this response.

Returns:

  • (String)

    The orginal input that triggered this response.



67
68
69
# File 'lib/pandorified/result.rb', line 67

def input
  @input ||= REXML::XPath.first(@xml, '/result/input').text
end

#messageString Also known as: error, error_message

Returns The error message as returned by Pandorabots, if an error occured.

Returns:

  • (String)

    The error message as returned by Pandorabots, if an error occured.



47
48
49
50
51
# File 'lib/pandorified/result.rb', line 47

def message
  return nil if success?

  @message ||= REXML::XPath.first(@xml, '/result/message').text
end

#statusNumber

Check the status of this result. See #success? and #error?.

Returns:

  • (Number)

    A status number as returned by Pandorabots.



24
25
26
# File 'lib/pandorified/result.rb', line 24

def status
  @status ||= REXML::XPath.first(@xml, '/result/@status').value.to_i
end

#success?Boolean Also known as: ok?, successful?

Returns ‘true` if this result was successful (no error was returned by Pandorabots), `false` otherwise.

Returns:

  • (Boolean)

    ‘true` if this result was successful (no error was returned by Pandorabots), `false` otherwise.



30
31
32
# File 'lib/pandorified/result.rb', line 30

def success?
  status.zero?
end

#thatString Also known as: to_s

Returns The bot’s response to the input.

Returns:

  • (String)

    The bot’s response to the input.



15
16
17
# File 'lib/pandorified/result.rb', line 15

def that
  @that ||= REXML::XPath.first(@xml, '/result/that').text.strip
end