11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/friendly_shipping/services/usps/parse_xml_response.rb', line 11
def call(request:, response:, expected_root_tag:)
xml = Nokogiri.XML(response.body, &:strict)
if xml.root.nil? || ![expected_root_tag, 'Error'].include?(xml.root.name)
wrap_failure('Invalid document', request, response)
elsif request_successful?(xml)
Success(xml)
else
wrap_failure(error_message(xml), request, response)
end
rescue Nokogiri::XML::SyntaxError => e
wrap_failure(e, request, response)
end
|