Permalink
Browse files

Handle case where fedex only returns one event. Remove debugger stuff

  • Loading branch information...
1 parent eeecbe3 commit 9c8429cf9f0e8d45fab4fd619a16aafbd2551868 @jkeen committed Mar 20, 2013
@@ -42,14 +42,13 @@ def track_package(package_id)
http_response.error! unless http_response.code == 200
# get the tracking information from the reply
track_reply = http_response["FDXTrack2Reply"]
-
# raise a Trackerific::Error if there is an error in the reply
raise Trackerific::Error, track_reply["Error"]["Message"] unless track_reply["Error"].nil?
# get the details from the reply
details = track_reply["Package"]
# convert them into Trackerific::Events
events = []
- details["Event"].each do |e|
+ [details["Event"]].flatten.each do |e|
date = Time.parse("#{e["Date"]} #{e["Time"]}")
desc = e["Description"]
addr = e["Address"]
@@ -0,0 +1,50 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<FDXTrack2Reply xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <DuplicateWaybill>false</DuplicateWaybill>
+ <MoreData>false</MoreData>
+ <Package>
+ <TrackingNumber>183689015000001</TrackingNumber>
+ <TrackingNumberUniqueIdentifier>12010~183689015000001</TrackingNumberUniqueIdentifier>
+ <StatusCode>DL</StatusCode>
+ <StatusDescription>Delivered</StatusDescription>
+ <CarrierCode>FDXG</CarrierCode>
+ <OtherIdentifier>
+ <Value>770-886-6395</Value>
+ <Type>CUR</Type>
+ </OtherIdentifier>
+ <Service>FedEx Home Delivery</Service>
+ <Weight>19.8</Weight>
+ <WeightUnits>LBS</WeightUnits>
+ <PackagingDescription>Package</PackagingDescription>
+ <PackageSequenceNumber>1</PackageSequenceNumber>
+ <PackageCount>1</PackageCount>
+ <OriginLocationAddress>
+ <City>ANAHEIM</City>
+ <StateOrProvinceCode>CA</StateOrProvinceCode>
+ <CountryCode>US</CountryCode>
+ </OriginLocationAddress>
+ <ShipDate>2010-06-25</ShipDate>
+ <DestinationAddress>
+ <City>Gainesville</City>
+ <StateOrProvinceCode>GA</StateOrProvinceCode>
+ <CountryCode>US</CountryCode>
+ </DestinationAddress>
+ <DeliveredDate>2010-07-01</DeliveredDate>
+ <DeliveredTime>10:43:51</DeliveredTime>
+ <SignatureProofOfDeliveryAvailable>false</SignatureProofOfDeliveryAvailable>
+ <Event>
+ <Date>2010-07-01</Date>
+ <Time>10:43:51</Time>
+ <Type>DL</Type>
+ <Description>Delivered</Description>
+ <StatusExceptionCode>014</StatusExceptionCode>
+ <StatusExceptionDescription>Left at garage. Signature Service not requested.</StatusExceptionDescription>
+ <Address>
+ <City>Gainesville</City>
+ <StateOrProvinceCode>GA</StateOrProvinceCode>
+ <PostalCode>30506</PostalCode>
+ <CountryCode>US</CountryCode>
+ </Address>
+ </Event>
+ </Package>
+</FDXTrack2Reply>
@@ -48,29 +48,42 @@
subject { @tracking }
it("should return a Trackerific::Details") { should be_a Trackerific::Details }
-
+
describe "origin" do
subject { @tracking.origin }
it("should return a Trackerific::Location") { should be_a Trackerific::Location }
end
-
+
describe "destination" do
subject { @tracking.destination }
it("should return a Trackerific::Location") { should be_a Trackerific::Location }
end
-
+
describe "events.length" do
subject { @tracking.events.length }
it { should >= 1}
end
-
+
describe :summary do
subject { @tracking.summary }
it { should_not be_empty }
end
+ end
+
+ context "with a successful response with only one event" do
+ before(:all) do
+ FakeWeb.register_uri(:post, FEDEX_TRACK_URL, :body => load_fixture(:fedex_success_response_single_event))
+ end
+ before(:each) do
+ @tracking = @fedex.track_package(@package_id)
+ end
+
+ subject { @tracking }
+ it("should return a Trackerific::Details") { should be_a Trackerific::Details }
end
+
context "with an error response from the server" do
before(:all) do
@@ -1,6 +1,5 @@
require 'spec_helper'
require 'fakeweb'
-require 'pry'
UPS_TRACK_URL = 'https://wwwcie.ups.com/ups.app/xml/Track'
describe "Trackerific::UPS" do

0 comments on commit 9c8429c

Please sign in to comment.