Class: Pandorified::Result
- Inherits:
-
Object
- Object
- Pandorified::Result
- 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
-
#botid ⇒ String
The botid of the bot this result is for.
-
#custid ⇒ String
The custid for this session.
-
#error? ⇒ Boolean
‘true` if Pandorabots returned an error.
-
#initialize(response_body) ⇒ Result
constructor
A new instance of Result.
-
#input ⇒ String
The orginal input that triggered this response.
-
#message ⇒ String
(also: #error, #error_message)
The error message as returned by Pandorabots, if an error occured.
-
#status ⇒ Number
Check the status of this result.
-
#success? ⇒ Boolean
(also: #ok?, #successful?)
‘true` if this result was successful (no error was returned by Pandorabots), `false` otherwise.
-
#that ⇒ String
(also: #to_s)
The bot’s response to the input.
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
#botid ⇒ String
Returns 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 |
#custid ⇒ String
Returns 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
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 |
#input ⇒ String
Returns 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 |
#message ⇒ String Also known as: error, error_message
Returns The error message as returned by Pandorabots, if an error occured.
47 48 49 50 51 |
# File 'lib/pandorified/result.rb', line 47 def return nil if success? @message ||= REXML::XPath.first(@xml, '/result/message').text end |
#status ⇒ Number
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.
30 31 32 |
# File 'lib/pandorified/result.rb', line 30 def success? status.zero? end |
#that ⇒ String Also known as: to_s
Returns 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 |