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



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



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

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

#custidString



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.



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

def error?
  !success?
end

#inputString



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



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?.



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?



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

def success?
  status.zero?
end

#thatString Also known as: to_s



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

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