Permalink
Browse files

Extract tracking number information into arrays

Instead of giving back a string for tracking numbers we
return arrays instead.  This is a backwards-incompatible change,
and as such requires a major version update.  All current fulfillment
providers, and future providers will need to providing tracking
numbers as arrays, even if it is guaranteed that they only provide
a single tracking number.
  • Loading branch information...
1 parent 4383e43 commit 096eb1223772e91b9eee704e2718e84f0b5735cf Chris Saunders committed Oct 4, 2012
View
@@ -1 +1 @@
-1.0.3
+2.0.0
@@ -5,7 +5,7 @@
Gem::Specification.new do |s|
s.name = %q{active_fulfillment}
- s.version = "1.0.3"
+ s.version = "2.0.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Cody Fauser", "James MacAulay"]
@@ -342,7 +342,7 @@ def parse_tracking_response(document)
track_node = REXML::XPath.first(document, '//ns1:FulfillmentShipmentPackage/ns1:TrackingNumber')
if track_node
id_node = REXML::XPath.first(document, '//ns1:MerchantFulfillmentOrderId')
- response[:tracking_numbers][id_node.text] = track_node.text
+ response[:tracking_numbers][id_node.text] = [track_node.text]
end
response[:response_status] = SUCCESS
@@ -227,15 +227,11 @@ def parse_response(service, op, xml)
def parse_tracking_response(document)
response = {}
response[:tracking_numbers] = {}
- order_id = REXML::XPath.first(document, "//FulfillmentOrder/SellerFulfillmentOrderId").text.strip
- tracking_numbers = REXML::XPath.match(document, "//FulfillmentShipmentPackage/member/TrackingNumber")
+ tracking_numbers = REXML::XPath.match(document, "//FulfillmentShipmentPackage/member/TrackingNumber")
if tracking_numbers.present?
- response[:tracking_numbers][order_id] = ''
- tracking_numbers.each do |tracking_number|
- response[:tracking_numbers][order_id] += ',' if response[:tracking_numbers][order_id].length > 0
- response[:tracking_numbers][order_id] += tracking_number.text.strip
- end
+ order_id = REXML::XPath.first(document, "//FulfillmentOrder/SellerFulfillmentOrderId").text.strip
+ response[:tracking_numbers][order_id] = tracking_numbers.map{ |t| t.text.strip }
end
response[:response_status] = SUCCESS
@@ -234,7 +234,7 @@ def parse_tracking_response(xml)
if node.name == 'Order'
if node.attributes["shipped"] == "YES" && node.elements['TrackingNumber']
tracking_number = node.elements['TrackingNumber'].text
- response[:tracking_numbers][node.attributes['id']] = tracking_number
+ response[:tracking_numbers][node.attributes['id']] = [tracking_number]
end
else
response[node.name.underscore.to_sym] = node.text
@@ -301,7 +301,7 @@ def parse_tracking_response(document)
params = node.elements.to_a.each_with_object({}) {|elem, hash| hash[elem.name] = elem.text}
tracking = params['ShipmentTrackingNumber']
- response[:tracking_numbers][params['InvoiceNumber']] = tracking unless tracking == NOT_SHIPPED
+ response[:tracking_numbers][params['InvoiceNumber']] = [tracking] unless tracking == NOT_SHIPPED
end
response
@@ -79,8 +79,8 @@ def test_fetch_tracking_numbers
'1254658', 'FAItest123', 'Flat Rate Test Order 4'
])
assert response.success?
- assert_equal '4209073191018052136352154', response.tracking_numbers['1254658']
- assert_equal '9101805213907472080032', response.tracking_numbers['Flat Rate Test Order 4']
+ assert_equal ['4209073191018052136352154'], response.tracking_numbers['1254658']
+ assert_equal ['9101805213907472080032'], response.tracking_numbers['Flat Rate Test Order 4']
assert_nil response.tracking_numbers['FAItest123'] # 'Not Shipped'
end
@@ -217,7 +217,7 @@ def test_fetch_tracking_numbers
response = @service.fetch_tracking_numbers(['extern_id_1154539615776', 'extern_id_1154539615777'])
assert response.success?
- assert_equal '93ZZ00', response.tracking_numbers['extern_id_1154539615776']
+ assert_equal %w{93ZZ00}, response.tracking_numbers['extern_id_1154539615776']
assert_nil response.tracking_numbers['extern_id_1154539615777']
end
@@ -227,7 +227,7 @@ def test_fetch_multiple_tracking_numbers
response = @service.fetch_tracking_numbers(['extern_id_1154539615776'])
assert response.success?
- assert_equal '93YY00,93ZZ00', response.tracking_numbers['extern_id_1154539615776']
+ assert_equal %w{93YY00 93ZZ00}, response.tracking_numbers['extern_id_1154539615776']
end
def test_that_generated_requests_do_not_double_escape_spaces
@@ -250,7 +250,7 @@ def test_fetch_tracking_numbers_ignores_not_found
response = @service.fetch_tracking_numbers(['extern_id_1154539615776', 'dafdfafsdafdafasdfa', 'extern_id_1154539615777'])
assert response.success?
- assert_equal '93ZZ00', response.tracking_numbers['extern_id_1154539615776']
+ assert_equal %w{93ZZ00}, response.tracking_numbers['extern_id_1154539615776']
end
def test_fetch_tracking_numbers_aborts_on_error
@@ -98,7 +98,7 @@ def test_fetch_tracking_numbers
response = @service.fetch_tracking_numbers(['TEST-00000001', 'TEST-00000002'])
assert response.success?
- assert_equal 'UPS00000001', response.tracking_numbers['TEST-00000001']
+ assert_equal %w{UPS00000001}, response.tracking_numbers['TEST-00000001']
assert_nil response.tracking_numbers['TEST-00000002']
end
@@ -115,7 +115,7 @@ def test_fetch_tracking_numbers_ignores_not_found
response = @service.fetch_tracking_numbers(['TEST-00000001', '#1337-1', 'TEST-00000002'])
assert response.success?
- assert_equal 'UPS00000001', response.tracking_numbers['TEST-00000001']
+ assert_equal %w{UPS00000001}, response.tracking_numbers['TEST-00000001']
end
def test_fetch_tracking_numbers_aborts_on_error
@@ -105,8 +105,8 @@ def test_no_tracking_numbers_available
end
def test_successful_tracking
- expected = { "2986" => "1ZW682E90326614239",
- "2987" => "1ZW682E90326795080" }
+ expected = { "2986" => ["1ZW682E90326614239"],
+ "2987" => ["1ZW682E90326795080"] }
@shipwire.expects(:ssl_post).returns(successful_tracking_response)
response = @shipwire.fetch_tracking_numbers(["2986", "2987"])
@@ -106,7 +106,7 @@ def test_tracking_numbers
response = @service.fetch_tracking_numbers(['AB12345', 'XY4567'])
assert response.success?
assert_equal WebgistixService::SUCCESS_MESSAGE, response.message
- assert_equal '1Z8E5A380396682872', response.tracking_numbers['AB12345']
+ assert_equal ['1Z8E5A380396682872'], response.tracking_numbers['AB12345']
assert_nil response.tracking_numbers['XY4567']
end

0 comments on commit 096eb12

Please sign in to comment.