Class: RazorRisk::Razor::Connectivity::Razor3::Response

Inherits:
Object
  • Object
show all
Includes:
Pantheios, Core::Diagnostics::Logger, Xqsr3::Quality::ParameterChecking
Defined in:
lib/razor_risk/razor/connectivity/razor_3/response.rb

Overview

######################################################################## # classes

Defined Under Namespace

Classes: Reason

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Response

Initialises an instance from an XML node (of type Nokogiri::XML::Node)

Parameters:

  • node (::Nokogiri::XML::Node)


127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/razor_risk/razor/connectivity/razor_3/response.rb', line 127

def initialize node

    trace ParamNames[ :node ], node

    check_parameter node, 'node', types: [ ::Nokogiri::XML::Node ]

    razor_outbound          =   node.xpath('/razorOutbound')

    if razor_outbound.nil? || razor_outbound.empty?

        log :failure, "node(#{node.class})='#{node.to_xml}'"

        raise ArgumentError, "node does not contain a recognised Razor 3 response"
    end

    @s                      =   node.to_s

    @body                   =   obtain_ razor_outbound, 'body', no_text: true

    if @body

        # convert to standalone document
        @body               =   ::Nokogiri.XML(@body.to_s).root
    end

    @errors                 =   obtain_ razor_outbound, 'errors', no_text: true

    @caller                 =   obtain_ razor_outbound, 'caller'

    @request_received_time  =   to_time_ obtain_ razor_outbound, 'requestReceivedTime', nil: true

    @response_sent_time     =   to_time_ obtain_ razor_outbound, 'responseSentTime', nil: true

    @response_received_time =   to_time_ obtain_ razor_outbound, 'responseReceivedTime', nil: true

    @result_code            =   obtain_ razor_outbound, 'returnCode'

    @reasons                =   obtain_reasons_ @errors

    e_c                     =   @errors ? @errors.xpath('error/code') : nil
    @razor_code             =   e_c ? e_c.text.chomp.strip : ''
end

Instance Attribute Details

#body ⇒ Object (readonly)

A copy of the response document's node



171
172
173
# File 'lib/razor_risk/razor/connectivity/razor_3/response.rb', line 171

def body
  @body
end

#caller ⇒ Object (readonly)

Returns the value of attribute caller.



173
174
175
# File 'lib/razor_risk/razor/connectivity/razor_3/response.rb', line 173

def caller
  @caller
end

#errors ⇒ Object (readonly)

Returns the value of attribute errors.



172
173
174
# File 'lib/razor_risk/razor/connectivity/razor_3/response.rb', line 172

def errors
  @errors
end

#razor_code ⇒ Object (readonly)

Returns the value of attribute razor_code.



178
179
180
# File 'lib/razor_risk/razor/connectivity/razor_3/response.rb', line 178

def razor_code
  @razor_code
end

#request_received_time ⇒ Object (readonly)

Returns the value of attribute request_received_time.



174
175
176
# File 'lib/razor_risk/razor/connectivity/razor_3/response.rb', line 174

def request_received_time
  @request_received_time
end

#response_received_time ⇒ Object (readonly)

Returns the value of attribute response_received_time.



176
177
178
# File 'lib/razor_risk/razor/connectivity/razor_3/response.rb', line 176

def response_received_time
  @response_received_time
end

#response_sent_time ⇒ Object (readonly)

Returns the value of attribute response_sent_time.



175
176
177
# File 'lib/razor_risk/razor/connectivity/razor_3/response.rb', line 175

def response_sent_time
  @response_sent_time
end

#result_code ⇒ Object (readonly)

Returns the value of attribute result_code.



177
178
179
# File 'lib/razor_risk/razor/connectivity/razor_3/response.rb', line 177

def result_code
  @result_code
end

Instance Method Details

#failed? ⇒ Boolean

false if the response represents success (which means that the result_code is 'ack'); true otherwise

Returns:

  • (Boolean)


189
190
191
192
# File 'lib/razor_risk/razor/connectivity/razor_3/response.rb', line 189

def failed?

    !succeeded?
end

#inspect ⇒ Object

Human-readable debug-like string form



208
209
210
211
# File 'lib/razor_risk/razor/connectivity/razor_3/response.rb', line 208

def inspect

    "#<#{self.class}:#{object_id.to_s(16).rjust(14, '0').upcase} : caller=#{caller}; result_code=#{result_code}>"
end

#reasons ⇒ Object

An array of 0 or more reasons as to why the response represents a failed operation



182
183
184
185
# File 'lib/razor_risk/razor/connectivity/razor_3/response.rb', line 182

def reasons

    @reasons
end

#succeeded? ⇒ Boolean

true if the response represents success (which means that the result_code is 'ack'); false otherwise

Returns:

  • (Boolean)


196
197
198
199
# File 'lib/razor_risk/razor/connectivity/razor_3/response.rb', line 196

def succeeded?

    result_code == 'ack'
end

#to_s ⇒ Object

Full string form of the node from which the instance was initialised



202
203
204
205
# File 'lib/razor_risk/razor/connectivity/razor_3/response.rb', line 202

def to_s

    @s
end