Class: GlobalSign::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/global_sign/response.rb

Constant Summary collapse

SUCCESS_CODE =
'0'.freeze
WARNING_CODE =
'1'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(body) ⇒ Response

Returns a new instance of Response.



8
9
10
# File 'lib/global_sign/response.rb', line 8

def initialize(body)
  @xml = Nokogiri::XML(body)
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/global_sign/response.rb', line 28

def error?
  !success? && !warning?
end

#error_codeObject



32
33
34
# File 'lib/global_sign/response.rb', line 32

def error_code
  errors.at('ErrorCode').try(:text)
end

#error_fieldObject



36
37
38
# File 'lib/global_sign/response.rb', line 36

def error_field
  errors.at('ErrorField').try(:text)
end

#error_messageObject



40
41
42
# File 'lib/global_sign/response.rb', line 40

def error_message
  errors.at('ErrorMessage').try(:text)
end

#success?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/global_sign/response.rb', line 20

def success?
  @xml.xpath(xpath_result).text == SUCCESS_CODE
end

#warning?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/global_sign/response.rb', line 24

def warning?
  @xml.xpath(xpath_result).text == WARNING_CODE
end

#xpath_errorsObject



16
17
18
# File 'lib/global_sign/response.rb', line 16

def xpath_errors
  "//Response/#{response_header}/Errors"
end

#xpath_resultObject



12
13
14
# File 'lib/global_sign/response.rb', line 12

def xpath_result
  "//Response/#{response_header}/SuccessCode"
end