Permalink
Browse files

Shipwire: Fix parsing error message from CDATA on failed fulfillment …

…and tracking requests
  • Loading branch information...
1 parent 113d3e7 commit 103bf11b3f3cb9638053b5415781f4b01335173c @Soleone Soleone committed Oct 2, 2012
@@ -27,7 +27,7 @@ class ShipwireService < Service
'UK' => 'United Kingdom'
}
- INVALID_LOGIN = /Error with Valid Username\/EmailAddress and Password Required/
+ INVALID_LOGIN = /(Error with Valid Username\/EmailAddress and Password Required)|(Could not verify Username\/EmailAddress and Password combination)/
class_attribute :affiliate_id
@@ -193,7 +193,7 @@ def parse_fulfillment_response(xml)
document = REXML::Document.new(xml)
document.root.elements.each do |node|
- response[node.name.underscore.to_sym] = node.text
+ response[node.name.underscore.to_sym] = text_content(node)
end
response[:success] = response[:status] == '0'
@@ -214,7 +214,7 @@ def parse_inventory_response(xml)
amount = to_check.sum { |a| node.attributes[a].to_i }
response[:stock_levels][node.attributes['code']] = amount
else
- response[node.name.underscore.to_sym] = node.text
+ response[node.name.underscore.to_sym] = text_content(node)
end
end
@@ -237,7 +237,7 @@ def parse_tracking_response(xml)
response[:tracking_numbers][node.attributes['id']] = tracking_number
end
else
- response[node.name.underscore.to_sym] = node.text
+ response[node.name.underscore.to_sym] = text_content(node)
end
end
@@ -250,6 +250,12 @@ def message_from(string)
return if string.blank?
string.gsub("\n", '').squeeze(" ")
end
+
+ def text_content(xml_node)
+ text = xml_node.text
+ text = xml_node.cdatas.join if text.blank?
+ text
+ end
end
end
end
@@ -0,0 +1,7 @@
+<!DOCTYPE SubmitOrderResponse SYSTEM "http://www.shipwire.com/exec/download/SubmitOrderResponse.dtd">
+<SubmitOrderResponse>
+ <Status>Error</Status>
+ <ErrorMessage>
+ <![CDATA[Could not verify Username/EmailAddress and Password combination]]>
+</ErrorMessage>
+</SubmitOrderResponse>
@@ -170,6 +170,11 @@ def test_order_includes_note_when_present
assert_equal "A test note", note_node.to_s
end
+ def test_error_response_cdata_parsing
+ @shipwire.expects(:ssl_post).returns(xml_fixture('shipwire/fulfillment_failure_response'))
+ assert !@shipwire.valid_credentials?
+ end
+
private
def successful_empty_tracking_response
"<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n<TrackingUpdateResponse><Status>Test</Status><TotalOrders></TotalOrders><TotalShippedOrders></TotalShippedOrders><TotalProducts></TotalProducts><Bookmark></Bookmark></TrackingUpdateResponse>"

0 comments on commit 103bf11

Please sign in to comment.