Certain shipments (e.g. FedEx SmartPost) are shared between carriers, and until this PR this dataset had no way of modeling that relationship. Previously, consuming libraries would successfully match a FedExSmartPost number like 420112139261290983497923666238 against the FedExSmartPost criteria, and the USPS91 criteria and return both to the consumer. This wasn't wrong, but it wasn't the complete answer either. #12, #23
This change now models both sides of the relationship so that consuming libraries can detect if the tracking number returned is a partnership, and which part of the relationship that tracking number fulfills. One side of the partnership is a shipper (e.g FedEx), and the other side is the [last mile] carrier (e.g. USPS).
This is how it's implemented in the upcoming version of tracking_number
# Search defaults to only showing numbers that fulfill the carrier side of the relationship
# (if a partnership exists at all), as this is the end a consumer would most likely be interested in.
results = TrackingNumber.search('420112139261290983497923666238')
=> [#<TrackingNumber::USPS91:0x26ac0 420112139261290983497923666238>]
tn = results.first
tn.shipper? #=> false
tn.carrier? #=> true
tn.partnership? #=> true
tn.partners
#=> <struct TrackingNumber::Base::PartnerStruct
# shipper=#<TrackingNumber::FedExSmartPost:0x30624 420112139261290983497923666238>,
# carrier=#<TrackingNumber::USPS91:0x2f1fc 420112139261290983497923666238>>
tn.partners.shipper #=> #<TrackingNumber::FedExSmartPost:0x30624 420112139261290983497923666238>
tn.partners.carrier == tn #=> true
To return both the shipper and carrier when searching, you can pass a second argument into search:
Certain shipments (e.g. FedEx SmartPost) are shared between carriers, and until this PR this dataset had no way of modeling that relationship. Previously, consuming libraries would successfully match a FedExSmartPost number like
420112139261290983497923666238
against theFedExSmartPost
criteria, and theUSPS91
criteria and return both to the consumer. This wasn't wrong, but it wasn't the complete answer either. #12, #23This change now models both sides of the relationship so that consuming libraries can detect if the tracking number returned is a partnership, and which part of the relationship that tracking number fulfills. One side of the partnership is a
shipper
(e.g FedEx), and the other side is the [last mile]carrier
(e.g. USPS).This is how it's implemented in the upcoming version of
tracking_number
To return both the shipper and carrier when searching, you can pass a second argument into search:
TrackingNumbers that are not a partnership fulfill both sides of the relationship and indicate as such: