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(params) ⇒ Result

Returns a new instance of Result.



12
13
14
# File 'lib/pandorified/result.rb', line 12

def initialize(params)
  @xml = Nokogiri::XML(RestClient.post(API_URL, params))
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.



59
60
61
# File 'lib/pandorified/result.rb', line 59

def botid
  @botid ||= @xml.xpath('/result/@botid').first.value
end

#custidString

Returns The custid for this session.

Returns:

  • (String)

    The custid for this session.



64
65
66
# File 'lib/pandorified/result.rb', line 64

def custid
  @custid ||= @xml.xpath('/result/@custid').first.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.



43
44
45
# File 'lib/pandorified/result.rb', line 43

def error?
  !success?
end

#inputString

Returns The orginal input that triggered this response.

Returns:

  • (String)

    The orginal input that triggered this response.



69
70
71
# File 'lib/pandorified/result.rb', line 69

def input
  @input ||= @xml.xpath('/result/input').first.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.



49
50
51
52
53
# File 'lib/pandorified/result.rb', line 49

def message
  return nil if success?

  @message ||= @xml.xpath('/result/message').first.text
end

#statusNumber

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

Returns:

  • (Number)

    A status number as returned by Pandorabots.



26
27
28
# File 'lib/pandorified/result.rb', line 26

def status
  @status ||= @xml.xpath('/result/@status').first.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.



32
33
34
# File 'lib/pandorified/result.rb', line 32

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.



17
18
19
# File 'lib/pandorified/result.rb', line 17

def that
  @that ||= @xml.xpath('/result/that').first.text.strip
end