Class: Experian::Response

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

Direct Known Subclasses

ConnectCheck::Response

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(xml) ⇒ Response

Returns a new instance of Response.



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

def initialize(xml)
  @xml = xml
  @response = parse_xml_response
end

Instance Attribute Details

#xmlObject (readonly)

Returns the value of attribute xml.



6
7
8
# File 'lib/experian/response.rb', line 6

def xml
  @xml
end

Instance Method Details

#completion_codeObject



21
22
23
# File 'lib/experian/response.rb', line 21

def completion_code
  @response["CompletionCode"]
end

#completion_messageObject



25
26
27
# File 'lib/experian/response.rb', line 25

def completion_message
  Experian::COMPLETION_CODES[completion_code]
end

#error?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/experian/response.rb', line 61

def error?
  completion_code != "0000" || !error_segment.nil?
end

#error_action_indicatorObject



76
77
78
79
# File 'lib/experian/response.rb', line 76

def error_action_indicator
  return unless error_segment
  error_message_segment[9]
end

#error_action_indicator_messageObject



81
82
83
# File 'lib/experian/response.rb', line 81

def error_action_indicator_message
  Experian::ERROR_ACTION_INDICATORS[error_action_indicator]
end

#error_codeObject



71
72
73
74
# File 'lib/experian/response.rb', line 71

def error_code
  return unless error_segment
  error_message_segment[6..8].to_i
end

#error_messageObject



13
14
15
# File 'lib/experian/response.rb', line 13

def error_message
  @response["ErrorMessage"] || (Experian::Error.message(error_code) if error_code)
end

#error_message_segmentObject

The error message segment is embedded in the error segment :(



66
67
68
69
# File 'lib/experian/response.rb', line 66

def error_message_segment
  return unless error_segment
  error_segment[error_segment.index("200")..-1]
end

#error_segmentObject

error_segment returns the entire host response (segments 100, 200, 900) since error responses do not separate segments with “@”.



53
54
55
# File 'lib/experian/response.rb', line 53

def error_segment
  segment(100)
end

#header_segmentObject



47
48
49
# File 'lib/experian/response.rb', line 47

def header_segment
  segment(110)
end

#host_responseObject



17
18
19
# File 'lib/experian/response.rb', line 17

def host_response
  @response["HostResponse"]
end

#segment(segment_id) ⇒ Object



43
44
45
# File 'lib/experian/response.rb', line 43

def segment(segment_id)
  segments(segment_id).first
end

#segments(segment_id = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/experian/response.rb', line 33

def segments(segment_id = nil)
  @segments ||= host_response ? host_response.split("@") : []

  if segment_id
    @segments.select { |segment| segment.length >= 3 ? segment[0..2].to_i == segment_id : false }
  else
    @segments
  end
end

#success?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/experian/response.rb', line 57

def success?
  completion_code == "0000" && !header_segment.nil?
end

#transaction_idObject



29
30
31
# File 'lib/experian/response.rb', line 29

def transaction_id
  @response["TransactionId"]
end