lib/pandorified/result.rb in pandorified-0.8.0 vs lib/pandorified/result.rb in pandorified-0.9.0
- old
+ new
@@ -7,42 +7,24 @@
class Result
def initialize(params)
@xml = Nokogiri::XML(RestClient.post(API_URL, params))
end
+ # @return [String] The bot's response to the input.
+ def that
+ @that ||= @xml.xpath('/result/that').first.text.strip
+ end
+
+ alias_method :to_s, :that
+
# Check the status of this result. See {#success?} and {#error?}.
#
# @return [Number] A status number as returned by Pandorabots.
def status
@status ||= @xml.xpath('/result/@status').first.value.to_i
end
- # @return [String] The botid of the bot this result is for.
- def botid
- @botid ||= @xml.xpath('/result/@botid').first.value
- end
-
- # @return [String] The custid for this session.
- def custid
- @custid ||= @xml.xpath('/result/@custid').first.value
- end
-
- # @return [String] The orginal input that triggered this response.
- def input
- @input ||= @xml.xpath('/result/input').first.text
- end
-
- # @return [String] The bot's response to the input.
- def that
- @that ||= @xml.xpath('/result/that').first.text
- end
-
- # @return [String] The error message as returned by Pandorabots, if an error occured.
- def message
- @message ||= @xml.xpath('/result/message').first.text
- end
-
# @return `true` if this result was successful (no error was returned by Pandorabots), `false` otherwise.
def success?
self.status.zero?
end
@@ -54,8 +36,30 @@
# @return `true` if Pandorabots returned an error.
def error?
!self.success?
end
- alias_method :to_s, :that
+ # @return [String] The error message as returned by Pandorabots, if an error occured.
+ def message
+ return nil if self.success?
+ @message ||= @xml.xpath('/result/message').first.text
+ end
+
+ alias_method :error, :message
+ alias_method :error_message, :message
+
+ # @return [String] The botid of the bot this result is for.
+ def botid
+ @botid ||= @xml.xpath('/result/@botid').first.value
+ end
+
+ # @return [String] The custid for this session.
+ def custid
+ @custid ||= @xml.xpath('/result/@custid').first.value
+ end
+
+ # @return [String] The orginal input that triggered this response.
+ def input
+ @input ||= @xml.xpath('/result/input').first.text
+ end
end
end