active_shipping 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +4 -0
- data/lib/active_shipping/carriers/usps.rb +41 -29
- data/lib/active_shipping/shipment_event.rb +3 -3
- data/lib/active_shipping/version.rb +1 -1
- data/repodb.yml +3 -0
- data/test/fixtures/xml/usps/tracking_request.xml +10 -3
- data/test/fixtures/xml/usps/tracking_response.xml +158 -9
- data/test/fixtures/xml/usps/tracking_response_alt.xml +44 -0
- data/test/fixtures/xml/usps/tracking_response_failure.xml +10 -1
- data/test/unit/carriers/usps_test.rb +58 -43
- metadata +6 -7
- metadata.gz.sig +0 -0
- data/test/fixtures/xml/usps/delivered_extended_tracking_response.xml +0 -11
- data/test/fixtures/xml/usps/delivered_tracking_response.xml +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f255b6e48e25f1a22656abd5424216bea74ef80
|
4
|
+
data.tar.gz: 7bafa8bea0f1a247ebb9aef8668c663b1b3eab44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f79e434be0cb714e9edfdb8d9e72bdfc5d1411de34593a373e914031b1c92f3890a937f8e8741cc6cc8218d434910c89cfd1dfbc1479aaf244dbfbad929a5dbe
|
7
|
+
data.tar.gz: 3a316e22f8772503f7e807d7ca4ffc057bbe8e88412cf32bcd697cc195b8ab0632a7508ea901e7d31ddcd7c7f145a390da6ffdd06bda2ea34598cd6dcf3170b9
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -10,11 +10,8 @@ module ActiveShipping
|
|
10
10
|
# This will send a test request to the USPS test servers, which they ask you
|
11
11
|
# to do before they put your API key in production mode.
|
12
12
|
class USPS < Carrier
|
13
|
-
EventDetails = Struct.new(:description, :time, :zoneless_time, :location)
|
14
|
-
|
15
|
-
/^(.*), (\w+ \d{1,2}, \d{4}, \d{1,2}:\d\d [ap]m), (.*), (\w\w) (\d{5})$/i,
|
16
|
-
/^Your item \w{2,3} (out for delivery|delivered).* at (\d{1,2}:\d\d [ap]m on \w+ \d{1,2}, \d{4}) in (.*), (\w\w) (\d{5})\.$/i
|
17
|
-
]
|
13
|
+
EventDetails = Struct.new(:description, :time, :zoneless_time, :location, :event_code)
|
14
|
+
ONLY_PREFIX_EVENTS = ['DELIVERED','OUT FOR DELIVERY']
|
18
15
|
self.retry_safe = true
|
19
16
|
|
20
17
|
cattr_reader :name
|
@@ -232,26 +229,44 @@ module ActiveShipping
|
|
232
229
|
Mass.new(70, :pounds)
|
233
230
|
end
|
234
231
|
|
235
|
-
def extract_event_details(
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
232
|
+
def extract_event_details(node)
|
233
|
+
description = node.at('Event').text.upcase
|
234
|
+
|
235
|
+
if prefix = ONLY_PREFIX_EVENTS.find { |p| description.starts_with?(p) }
|
236
|
+
description = prefix
|
237
|
+
end
|
238
|
+
|
239
|
+
timestamp = "#{node.at('EventDate').text}, #{node.at('EventTime').text}"
|
240
|
+
event_code = node.at('EventCode').text
|
241
|
+
city = node.at('EventCity').text
|
242
|
+
state = node.at('EventState').text
|
243
|
+
zip_code = node.at('EventZIPCode').text
|
244
|
+
|
245
|
+
country_node = node.at('EventCountry')
|
246
|
+
country = country_node ? country_node.text : ''
|
247
|
+
country = 'USA' if country.empty?
|
242
248
|
|
243
249
|
time = Time.parse(timestamp)
|
244
250
|
zoneless_time = Time.utc(time.year, time.month, time.mday, time.hour, time.min, time.sec)
|
245
|
-
location = Location.new(city: city, state: state, postal_code: zip_code, country:
|
246
|
-
EventDetails.new(description, time, zoneless_time, location)
|
251
|
+
location = Location.new(city: city, state: state, postal_code: zip_code, country: country)
|
252
|
+
EventDetails.new(description, time, zoneless_time, location, event_code)
|
247
253
|
end
|
248
254
|
|
249
255
|
protected
|
250
256
|
|
251
257
|
def build_tracking_request(tracking_number, options = {})
|
252
258
|
xml_builder = Nokogiri::XML::Builder.new do |xml|
|
253
|
-
xml.
|
254
|
-
xml.
|
259
|
+
xml.TrackFieldRequest('USERID' => @options[:login]) do
|
260
|
+
xml.Revision { xml.text('1') }
|
261
|
+
xml.ClientIp { xml.text(@options[:client_ip] || '127.0.0.1') }
|
262
|
+
xml.SourceId { xml.text(@options[:source_id] || 'active_shipping') }
|
263
|
+
xml.TrackID('ID' => tracking_number) do
|
264
|
+
xml.DestinationZipCode { xml.text(@options[:destination_zip])} if @options[:destination_zip]
|
265
|
+
if @options[:mailing_date]
|
266
|
+
formatted_date = @options[:mailing_date].strftime('%Y-%m-%d')
|
267
|
+
xml.MailingDate { xml.text(formatted_date)}
|
268
|
+
end
|
269
|
+
end
|
255
270
|
end
|
256
271
|
end
|
257
272
|
xml_builder.to_xml
|
@@ -529,7 +544,6 @@ module ActiveShipping
|
|
529
544
|
def parse_tracking_response(response, options)
|
530
545
|
actual_delivery_date, status = nil
|
531
546
|
xml = Nokogiri.XML(response)
|
532
|
-
root_node = xml.root
|
533
547
|
|
534
548
|
success = response_success?(xml)
|
535
549
|
message = response_message(xml)
|
@@ -538,20 +552,17 @@ module ActiveShipping
|
|
538
552
|
destination = nil
|
539
553
|
shipment_events = []
|
540
554
|
tracking_details = xml.root.xpath('TrackInfo/TrackDetail')
|
541
|
-
|
542
|
-
tracking_summary = xml.root.at('TrackInfo/TrackSummary')
|
543
|
-
if tracking_details.length > 0
|
544
|
-
tracking_details << tracking_summary
|
545
|
-
else
|
546
|
-
success = false
|
547
|
-
message = tracking_summary.text
|
548
|
-
end
|
555
|
+
tracking_details << xml.root.at('TrackInfo/TrackSummary')
|
549
556
|
|
550
557
|
tracking_number = xml.root.at('TrackInfo').attributes['ID'].value
|
558
|
+
scheduled_delivery = Time.parse(xml.root.at('PredictedDeliveryDate').text)
|
551
559
|
|
552
560
|
tracking_details.each do |event|
|
553
|
-
details = extract_event_details(event
|
554
|
-
|
561
|
+
details = extract_event_details(event)
|
562
|
+
if details.location
|
563
|
+
shipment_events << ShipmentEvent.new(details.description, details.zoneless_time,
|
564
|
+
details.location, details.description, details.event_code)
|
565
|
+
end
|
555
566
|
end
|
556
567
|
|
557
568
|
shipment_events = shipment_events.sort_by(&:time)
|
@@ -570,12 +581,13 @@ module ActiveShipping
|
|
570
581
|
:destination => destination,
|
571
582
|
:tracking_number => tracking_number,
|
572
583
|
:status => status,
|
573
|
-
:actual_delivery_date => actual_delivery_date
|
584
|
+
:actual_delivery_date => actual_delivery_date,
|
585
|
+
:scheduled_delivery_date => scheduled_delivery
|
574
586
|
)
|
575
587
|
end
|
576
588
|
|
577
589
|
def track_summary_node(document)
|
578
|
-
document.root.xpath('TrackInfo/
|
590
|
+
document.root.xpath('TrackInfo/StatusSummary')
|
579
591
|
end
|
580
592
|
|
581
593
|
def error_description_node(document)
|
@@ -1,9 +1,9 @@
|
|
1
1
|
module ActiveShipping
|
2
2
|
class ShipmentEvent
|
3
|
-
attr_reader :name, :time, :location, :message
|
3
|
+
attr_reader :name, :time, :location, :message, :type_code
|
4
4
|
|
5
|
-
def initialize(name, time, location, message = nil)
|
6
|
-
@name, @time, @location, @message = name, time, location, message
|
5
|
+
def initialize(name, time, location, message = nil, type_code = nil)
|
6
|
+
@name, @time, @location, @message, @type_code = name, time, location, message, type_code
|
7
7
|
end
|
8
8
|
|
9
9
|
def delivered?
|
data/repodb.yml
ADDED
@@ -1,3 +1,10 @@
|
|
1
|
-
|
2
|
-
<
|
3
|
-
</
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<TrackFieldRequest USERID="login">
|
3
|
+
<Revision>1</Revision>
|
4
|
+
<ClientIp>127.0.0.1</ClientIp>
|
5
|
+
<SourceId>active_shipping</SourceId>
|
6
|
+
<TrackID ID="9102901000462189604217">
|
7
|
+
<DestinationZipCode>12345</DestinationZipCode>
|
8
|
+
<MailingDate>2010-01-30</MailingDate>
|
9
|
+
</TrackID>
|
10
|
+
</TrackFieldRequest>
|
@@ -1,13 +1,162 @@
|
|
1
|
-
<?xml version="1.0"?>
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<TrackResponse>
|
3
|
+
<!-- other than this comment and an altered tracking number this is a real API response -->
|
3
4
|
<TrackInfo ID="9102901000462189604217">
|
4
|
-
<
|
5
|
-
<
|
6
|
-
<
|
7
|
-
<
|
8
|
-
<
|
9
|
-
<
|
10
|
-
<
|
11
|
-
<
|
5
|
+
<Class>First-Class Package Service</Class>
|
6
|
+
<ClassOfMailCode>FC</ClassOfMailCode>
|
7
|
+
<DestinationCity>HANNA CITY</DestinationCity>
|
8
|
+
<DestinationState>IL</DestinationState>
|
9
|
+
<DestinationZip>61536</DestinationZip>
|
10
|
+
<EmailEnabled>true</EmailEnabled>
|
11
|
+
<ExpectedDeliveryDate>April 28, 2015</ExpectedDeliveryDate>
|
12
|
+
<KahalaIndicator>false</KahalaIndicator>
|
13
|
+
<MailTypeCode>DM</MailTypeCode>
|
14
|
+
<MPDATE>2015-04-24 02:08:04.000000</MPDATE>
|
15
|
+
<MPSUFFIX>495865558</MPSUFFIX>
|
16
|
+
<OriginCity>ARGYLE</OriginCity>
|
17
|
+
<OriginState>TX</OriginState>
|
18
|
+
<OriginZip>76226</OriginZip>
|
19
|
+
<PodEnabled>false</PodEnabled>
|
20
|
+
<PredictedDeliveryDate>April 28, 2015</PredictedDeliveryDate>
|
21
|
+
<RestoreEnabled>false</RestoreEnabled>
|
22
|
+
<RramEnabled>false</RramEnabled>
|
23
|
+
<RreEnabled>false</RreEnabled>
|
24
|
+
<Service>USPS Tracking<SUP>&#153;</SUP></Service>
|
25
|
+
<ServiceTypeCode>001</ServiceTypeCode>
|
26
|
+
<Status>Delivered, In/At Mailbox</Status>
|
27
|
+
<StatusCategory>Delivered</StatusCategory>
|
28
|
+
<StatusSummary>Your item was delivered in or at the mailbox at 9:01 am on April 28, 2015 in HANNA CITY, IL 61536.</StatusSummary>
|
29
|
+
<TABLECODE>T</TABLECODE>
|
30
|
+
<TrackSummary>
|
31
|
+
<EventTime>9:01 am</EventTime>
|
32
|
+
<EventDate>April 28, 2015</EventDate>
|
33
|
+
<Event>Delivered, In/At Mailbox</Event>
|
34
|
+
<EventCity>HANNA CITY</EventCity>
|
35
|
+
<EventState>IL</EventState>
|
36
|
+
<EventZIPCode>61536</EventZIPCode>
|
37
|
+
<EventCountry/>
|
38
|
+
<FirmName/>
|
39
|
+
<Name/>
|
40
|
+
<AuthorizedAgent>false</AuthorizedAgent>
|
41
|
+
<EventCode>01</EventCode>
|
42
|
+
<DeliveryAttributeCode>01</DeliveryAttributeCode>
|
43
|
+
</TrackSummary>
|
44
|
+
<TrackDetail>
|
45
|
+
<EventTime>8:29 am</EventTime>
|
46
|
+
<EventDate>April 28, 2015</EventDate>
|
47
|
+
<Event>Out for Delivery</Event>
|
48
|
+
<EventCity>HANNA CITY</EventCity>
|
49
|
+
<EventState>IL</EventState>
|
50
|
+
<EventZIPCode>61536</EventZIPCode>
|
51
|
+
<EventCountry/>
|
52
|
+
<FirmName/>
|
53
|
+
<Name/>
|
54
|
+
<AuthorizedAgent>false</AuthorizedAgent>
|
55
|
+
<EventCode>OF</EventCode>
|
56
|
+
</TrackDetail>
|
57
|
+
<TrackDetail>
|
58
|
+
<EventTime>8:19 am</EventTime>
|
59
|
+
<EventDate>April 28, 2015</EventDate>
|
60
|
+
<Event>Sorting Complete</Event>
|
61
|
+
<EventCity>HANNA CITY</EventCity>
|
62
|
+
<EventState>IL</EventState>
|
63
|
+
<EventZIPCode>61536</EventZIPCode>
|
64
|
+
<EventCountry/>
|
65
|
+
<FirmName/>
|
66
|
+
<Name/>
|
67
|
+
<AuthorizedAgent>false</AuthorizedAgent>
|
68
|
+
<EventCode>PC</EventCode>
|
69
|
+
</TrackDetail>
|
70
|
+
<TrackDetail>
|
71
|
+
<EventTime>7:03 am</EventTime>
|
72
|
+
<EventDate>April 28, 2015</EventDate>
|
73
|
+
<Event>Arrived at Post Office</Event>
|
74
|
+
<EventCity>HANNA CITY</EventCity>
|
75
|
+
<EventState>IL</EventState>
|
76
|
+
<EventZIPCode>61536</EventZIPCode>
|
77
|
+
<EventCountry/>
|
78
|
+
<FirmName/>
|
79
|
+
<Name/>
|
80
|
+
<AuthorizedAgent>false</AuthorizedAgent>
|
81
|
+
<EventCode>07</EventCode>
|
82
|
+
</TrackDetail>
|
83
|
+
<TrackDetail>
|
84
|
+
<EventTime>4:05 am</EventTime>
|
85
|
+
<EventDate>April 28, 2015</EventDate>
|
86
|
+
<Event>Departed USPS Facility</Event>
|
87
|
+
<EventCity>HAZELWOOD</EventCity>
|
88
|
+
<EventState>MO</EventState>
|
89
|
+
<EventZIPCode>63042</EventZIPCode>
|
90
|
+
<EventCountry/>
|
91
|
+
<FirmName/>
|
92
|
+
<Name/>
|
93
|
+
<AuthorizedAgent>false</AuthorizedAgent>
|
94
|
+
<EventCode>EF</EventCode>
|
95
|
+
</TrackDetail>
|
96
|
+
<TrackDetail>
|
97
|
+
<EventTime>4:04 pm</EventTime>
|
98
|
+
<EventDate>April 27, 2015</EventDate>
|
99
|
+
<Event>Arrived at USPS Facility</Event>
|
100
|
+
<EventCity>HAZELWOOD</EventCity>
|
101
|
+
<EventState>MO</EventState>
|
102
|
+
<EventZIPCode>63042</EventZIPCode>
|
103
|
+
<EventCountry/>
|
104
|
+
<FirmName/>
|
105
|
+
<Name/>
|
106
|
+
<AuthorizedAgent>false</AuthorizedAgent>
|
107
|
+
<EventCode>10</EventCode>
|
108
|
+
</TrackDetail>
|
109
|
+
<TrackDetail>
|
110
|
+
<EventTime>12:18 am</EventTime>
|
111
|
+
<EventDate>April 26, 2015</EventDate>
|
112
|
+
<Event>Departed USPS Facility</Event>
|
113
|
+
<EventCity>COPPELL</EventCity>
|
114
|
+
<EventState>TX</EventState>
|
115
|
+
<EventZIPCode>75099</EventZIPCode>
|
116
|
+
<EventCountry/>
|
117
|
+
<FirmName/>
|
118
|
+
<Name/>
|
119
|
+
<AuthorizedAgent>false</AuthorizedAgent>
|
120
|
+
<EventCode>EF</EventCode>
|
121
|
+
</TrackDetail>
|
122
|
+
<TrackDetail>
|
123
|
+
<EventTime>7:19 pm</EventTime>
|
124
|
+
<EventDate>April 25, 2015</EventDate>
|
125
|
+
<Event>Arrived at USPS Origin Facility</Event>
|
126
|
+
<EventCity>COPPELL</EventCity>
|
127
|
+
<EventState>TX</EventState>
|
128
|
+
<EventZIPCode>75099</EventZIPCode>
|
129
|
+
<EventCountry/>
|
130
|
+
<FirmName/>
|
131
|
+
<Name/>
|
132
|
+
<AuthorizedAgent>false</AuthorizedAgent>
|
133
|
+
<EventCode>10</EventCode>
|
134
|
+
</TrackDetail>
|
135
|
+
<TrackDetail>
|
136
|
+
<EventTime>6:04 pm</EventTime>
|
137
|
+
<EventDate>April 25, 2015</EventDate>
|
138
|
+
<Event>Accepted at USPS Origin Sort Facility</Event>
|
139
|
+
<EventCity>ARGYLE</EventCity>
|
140
|
+
<EventState>TX</EventState>
|
141
|
+
<EventZIPCode>76226</EventZIPCode>
|
142
|
+
<EventCountry/>
|
143
|
+
<FirmName/>
|
144
|
+
<Name/>
|
145
|
+
<AuthorizedAgent>false</AuthorizedAgent>
|
146
|
+
<EventCode>OA</EventCode>
|
147
|
+
</TrackDetail>
|
148
|
+
<TrackDetail>
|
149
|
+
<EventTime>11:36 pm</EventTime>
|
150
|
+
<EventDate>April 23, 2015</EventDate>
|
151
|
+
<Event>Shipping Label Created</Event>
|
152
|
+
<EventCity>ARGYLE</EventCity>
|
153
|
+
<EventState>TX</EventState>
|
154
|
+
<EventZIPCode>76226</EventZIPCode>
|
155
|
+
<EventCountry/>
|
156
|
+
<FirmName/>
|
157
|
+
<Name/>
|
158
|
+
<AuthorizedAgent>false</AuthorizedAgent>
|
159
|
+
<EventCode>GX</EventCode>
|
160
|
+
</TrackDetail>
|
12
161
|
</TrackInfo>
|
13
162
|
</TrackResponse>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<TrackResponse>
|
3
|
+
<!-- this is a manually altered response designed to test cases that might occur but have never been actually observed yet. -->
|
4
|
+
<TrackInfo ID="9102901000462189604217">
|
5
|
+
<Class>First-Class Package Service</Class>
|
6
|
+
<ClassOfMailCode>FC</ClassOfMailCode>
|
7
|
+
<DestinationCity>HANNA CITY</DestinationCity>
|
8
|
+
<DestinationState>IL</DestinationState>
|
9
|
+
<DestinationZip>61536</DestinationZip>
|
10
|
+
<EmailEnabled>true</EmailEnabled>
|
11
|
+
<ExpectedDeliveryDate>April 28, 2015</ExpectedDeliveryDate>
|
12
|
+
<KahalaIndicator>false</KahalaIndicator>
|
13
|
+
<MailTypeCode>DM</MailTypeCode>
|
14
|
+
<MPDATE>2015-04-24 02:08:04.000000</MPDATE>
|
15
|
+
<MPSUFFIX>495865558</MPSUFFIX>
|
16
|
+
<OriginCity>ARGYLE</OriginCity>
|
17
|
+
<OriginState>TX</OriginState>
|
18
|
+
<OriginZip>76226</OriginZip>
|
19
|
+
<PodEnabled>false</PodEnabled>
|
20
|
+
<PredictedDeliveryDate>April 28, 2015</PredictedDeliveryDate>
|
21
|
+
<RestoreEnabled>false</RestoreEnabled>
|
22
|
+
<RramEnabled>false</RramEnabled>
|
23
|
+
<RreEnabled>false</RreEnabled>
|
24
|
+
<Service>USPS Tracking<SUP>&#153;</SUP></Service>
|
25
|
+
<ServiceTypeCode>001</ServiceTypeCode>
|
26
|
+
<Status>Delivered, In/At Mailbox</Status>
|
27
|
+
<StatusCategory>Delivered</StatusCategory>
|
28
|
+
<StatusSummary>Your item was delivered in or at the mailbox at 9:01 am on April 28, 2015 in HANNA CITY, IL 61536.</StatusSummary>
|
29
|
+
<TABLECODE>T</TABLECODE>
|
30
|
+
<TrackSummary>
|
31
|
+
<EventTime>8:29 am</EventTime>
|
32
|
+
<EventDate>April 28, 2015</EventDate>
|
33
|
+
<Event>Out for Delivery, in truck</Event>
|
34
|
+
<EventCity>OTTAWA</EventCity>
|
35
|
+
<EventState>ON</EventState>
|
36
|
+
<EventZIPCode>61536</EventZIPCode>
|
37
|
+
<EventCountry>Canada</EventCountry>
|
38
|
+
<FirmName/>
|
39
|
+
<Name/>
|
40
|
+
<AuthorizedAgent>false</AuthorizedAgent>
|
41
|
+
<EventCode>OF</EventCode>
|
42
|
+
</TrackSummary>
|
43
|
+
</TrackInfo>
|
44
|
+
</TrackResponse>
|
@@ -1,2 +1,11 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<TrackResponse
|
2
|
+
<TrackResponse>
|
3
|
+
<TrackInfo ID="9102901000462189604217">
|
4
|
+
<Error>
|
5
|
+
<Number>-2147219302</Number>
|
6
|
+
<Description>The Postal Service could not locate the tracking information for your request. Please verify your tracking number and try again later.</Description>
|
7
|
+
<HelpFile/>
|
8
|
+
<HelpContext/>
|
9
|
+
</Error>
|
10
|
+
</TrackInfo>
|
11
|
+
</TrackResponse>
|
@@ -9,6 +9,11 @@ class USPSTest < Minitest::Test
|
|
9
9
|
@tracking_response_failure = xml_fixture('usps/tracking_response_failure')
|
10
10
|
end
|
11
11
|
|
12
|
+
def test_tracking_request_should_create_correct_xml
|
13
|
+
@carrier.expects(:commit).with(:track, xml_fixture('usps/tracking_request'),false).returns(@tracking_response)
|
14
|
+
@carrier.find_tracking_info('9102901000462189604217', :destination_zip => '12345', :mailing_date => Date.new(2010,1,30))
|
15
|
+
end
|
16
|
+
|
12
17
|
def test_tracking_failure_should_raise_exception
|
13
18
|
@carrier.expects(:commit).returns(@tracking_response_failure)
|
14
19
|
assert_raises ResponseError do
|
@@ -44,10 +49,13 @@ class USPSTest < Minitest::Test
|
|
44
49
|
assert_equal 'ActiveShipping::TrackingResponse', @carrier.find_tracking_info('EJ958083578US').class.name
|
45
50
|
end
|
46
51
|
|
47
|
-
def
|
52
|
+
def test_find_tracking_info_should_have_correct_fields
|
48
53
|
@carrier.expects(:commit).returns(@tracking_response)
|
49
54
|
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
50
|
-
assert_equal
|
55
|
+
assert_equal 10, response.shipment_events.size
|
56
|
+
assert_equal Time.parse('April 28, 2015'), response.scheduled_delivery_date
|
57
|
+
assert_equal Time.parse('2015-04-28 09:01:00 UTC'), response.actual_delivery_date
|
58
|
+
assert_equal '9102901000462189604217', response.tracking_number
|
51
59
|
end
|
52
60
|
|
53
61
|
def test_find_tracking_info_should_return_shipment_events_in_ascending_chronological_order
|
@@ -59,37 +67,62 @@ class USPSTest < Minitest::Test
|
|
59
67
|
def test_find_tracking_info_should_have_correct_timestamps_for_shipment_events
|
60
68
|
@carrier.expects(:commit).returns(@tracking_response)
|
61
69
|
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
62
|
-
assert_equal [
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
70
|
+
assert_equal [
|
71
|
+
"2015-04-23 23:36:00 UTC",
|
72
|
+
"2015-04-25 18:04:00 UTC",
|
73
|
+
"2015-04-25 19:19:00 UTC",
|
74
|
+
"2015-04-26 00:18:00 UTC",
|
75
|
+
"2015-04-27 16:04:00 UTC",
|
76
|
+
"2015-04-28 04:05:00 UTC",
|
77
|
+
"2015-04-28 07:03:00 UTC",
|
78
|
+
"2015-04-28 08:19:00 UTC",
|
79
|
+
"2015-04-28 08:29:00 UTC",
|
80
|
+
"2015-04-28 09:01:00 UTC"], response.shipment_events.map { |e| e.time.strftime('%Y-%m-%d %H:%M:00 %Z') }
|
69
81
|
end
|
70
82
|
|
71
83
|
def test_find_tracking_info_should_have_correct_names_for_shipment_events
|
72
84
|
@carrier.expects(:commit).returns(@tracking_response)
|
73
85
|
response = @carrier.find_tracking_info('9102901000462189604217')
|
74
|
-
assert_equal [
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
86
|
+
assert_equal [
|
87
|
+
"SHIPPING LABEL CREATED",
|
88
|
+
"ACCEPTED AT USPS ORIGIN SORT FACILITY",
|
89
|
+
"ARRIVED AT USPS ORIGIN FACILITY",
|
90
|
+
"DEPARTED USPS FACILITY",
|
91
|
+
"ARRIVED AT USPS FACILITY",
|
92
|
+
"DEPARTED USPS FACILITY",
|
93
|
+
"ARRIVED AT POST OFFICE",
|
94
|
+
"SORTING COMPLETE",
|
95
|
+
"OUT FOR DELIVERY",
|
96
|
+
"DELIVERED"], response.shipment_events.map(&:name)
|
81
97
|
end
|
82
98
|
|
83
99
|
def test_find_tracking_info_should_have_correct_locations_for_shipment_events
|
84
100
|
@carrier.expects(:commit).returns(@tracking_response)
|
85
101
|
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
86
|
-
assert_equal [
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
102
|
+
assert_equal [
|
103
|
+
"ARGYLE, TX, 76226",
|
104
|
+
"ARGYLE, TX, 76226",
|
105
|
+
"COPPELL, TX, 75099",
|
106
|
+
"COPPELL, TX, 75099",
|
107
|
+
"HAZELWOOD, MO, 63042",
|
108
|
+
"HAZELWOOD, MO, 63042",
|
109
|
+
"HANNA CITY, IL, 61536",
|
110
|
+
"HANNA CITY, IL, 61536",
|
111
|
+
"HANNA CITY, IL, 61536",
|
112
|
+
"HANNA CITY, IL, 61536"], response.shipment_events.map(&:location).map { |l| "#{l.city}, #{l.state}, #{l.postal_code}" }
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_find_tracking_info_should_have_correct_event_codes_for_shipment_events
|
116
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
117
|
+
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
118
|
+
assert_equal ["GX", "OA", "10", "EF", "10", "EF", "07", "PC", "OF", "01"], response.shipment_events.map(&:type_code)
|
119
|
+
end
|
120
|
+
|
121
|
+
def test_find_tracking_info_should_handle_special_cases
|
122
|
+
@carrier.expects(:commit).returns(xml_fixture('usps/tracking_response_alt'))
|
123
|
+
response = @carrier.find_tracking_info('9102901000462189604217', :test => true)
|
124
|
+
assert_equal 'Canada', response.shipment_events.last.location.country.name
|
125
|
+
assert_equal :out_for_delivery, response.status
|
93
126
|
end
|
94
127
|
|
95
128
|
def test_find_tracking_info_destination
|
@@ -108,17 +141,11 @@ class USPSTest < Minitest::Test
|
|
108
141
|
def test_find_tracking_info_should_have_correct_status
|
109
142
|
@carrier.expects(:commit).returns(@tracking_response)
|
110
143
|
response = @carrier.find_tracking_info('9102901000462189604217')
|
111
|
-
assert_equal :
|
144
|
+
assert_equal :delivered, response.status
|
112
145
|
end
|
113
146
|
|
114
147
|
def test_find_tracking_info_should_have_correct_delivered
|
115
|
-
@carrier.expects(:commit).returns(
|
116
|
-
response = @carrier.find_tracking_info('9102901000462189604217')
|
117
|
-
assert_equal true, response.delivered?
|
118
|
-
end
|
119
|
-
|
120
|
-
def test_find_tracking_info_with_extended_response_format_should_have_correct_delivered
|
121
|
-
@carrier.expects(:commit).returns(xml_fixture('usps/delivered_extended_tracking_response'))
|
148
|
+
@carrier.expects(:commit).returns(@tracking_response)
|
122
149
|
response = @carrier.find_tracking_info('9102901000462189604217')
|
123
150
|
assert_equal true, response.delivered?
|
124
151
|
end
|
@@ -453,18 +480,6 @@ class USPSTest < Minitest::Test
|
|
453
480
|
assert_equal [3767, 5526, 7231, 7231], response.rates.map(&:price)
|
454
481
|
end
|
455
482
|
|
456
|
-
def test_extract_event_details_handles_single_digit_calendar_dates
|
457
|
-
assert details = @carrier.extract_event_details("Out for Delivery, October 9, 2013, 10:16 am, BROOKLYN, NY 11201")
|
458
|
-
assert_equal "OUT FOR DELIVERY", details.description
|
459
|
-
assert_equal 9, details.zoneless_time.mday
|
460
|
-
end
|
461
|
-
|
462
|
-
def test_extract_event_details_handles_double_digit_calendar_dates
|
463
|
-
assert details = @carrier.extract_event_details("Out for Delivery, October 12, 2013, 10:16 am, BROOKLYN, NY 11201")
|
464
|
-
assert_equal "OUT FOR DELIVERY", details.description
|
465
|
-
assert_equal 12, details.zoneless_time.mday
|
466
|
-
end
|
467
|
-
|
468
483
|
private
|
469
484
|
|
470
485
|
def build_service_node(options = {})
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_shipping
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James MacAulay
|
@@ -33,7 +33,7 @@ cert_chain:
|
|
33
33
|
fl3hbtVFTqbOlwL9vy1fudXcolIE/ZTcxQ+er07ZFZdKCXayR9PPs64heamfn0fp
|
34
34
|
TConQSX2BnZdhIEYW+cKzEC/bLc=
|
35
35
|
-----END CERTIFICATE-----
|
36
|
-
date: 2015-05-
|
36
|
+
date: 2015-05-14 00:00:00.000000000 Z
|
37
37
|
dependencies:
|
38
38
|
- !ruby/object:Gem::Dependency
|
39
39
|
name: quantified
|
@@ -219,6 +219,7 @@ files:
|
|
219
219
|
- lib/active_shipping/tracking_response.rb
|
220
220
|
- lib/active_shipping/version.rb
|
221
221
|
- lib/certs/eParcel.dtd
|
222
|
+
- repodb.yml
|
222
223
|
- shipit.rubygems.yml
|
223
224
|
- test/credentials.yml
|
224
225
|
- test/fixtures/files/label1.pdf
|
@@ -334,14 +335,13 @@ files:
|
|
334
335
|
- test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_commercial_base_rate_response.xml
|
335
336
|
- test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_commercial_plus_rate_response.xml
|
336
337
|
- test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_rate_response.xml
|
337
|
-
- test/fixtures/xml/usps/delivered_extended_tracking_response.xml
|
338
|
-
- test/fixtures/xml/usps/delivered_tracking_response.xml
|
339
338
|
- test/fixtures/xml/usps/first_class_packages_with_invalid_mail_type_response.xml
|
340
339
|
- test/fixtures/xml/usps/first_class_packages_with_mail_type_response.xml
|
341
340
|
- test/fixtures/xml/usps/first_class_packages_without_mail_type_response.xml
|
342
341
|
- test/fixtures/xml/usps/invalid_xml_tracking_response_error.xml
|
343
342
|
- test/fixtures/xml/usps/tracking_request.xml
|
344
343
|
- test/fixtures/xml/usps/tracking_response.xml
|
344
|
+
- test/fixtures/xml/usps/tracking_response_alt.xml
|
345
345
|
- test/fixtures/xml/usps/tracking_response_failure.xml
|
346
346
|
- test/fixtures/xml/usps/tracking_response_not_available.xml
|
347
347
|
- test/fixtures/xml/usps/tracking_response_test_error.xml
|
@@ -401,7 +401,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
401
401
|
version: '0'
|
402
402
|
requirements: []
|
403
403
|
rubyforge_project:
|
404
|
-
rubygems_version: 2.2.
|
404
|
+
rubygems_version: 2.2.3
|
405
405
|
signing_key:
|
406
406
|
specification_version: 4
|
407
407
|
summary: Simple shipping abstraction library
|
@@ -520,14 +520,13 @@ test_files:
|
|
520
520
|
- test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_commercial_base_rate_response.xml
|
521
521
|
- test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_commercial_plus_rate_response.xml
|
522
522
|
- test/fixtures/xml/usps/beverly_hills_to_ottawa_american_wii_rate_response.xml
|
523
|
-
- test/fixtures/xml/usps/delivered_extended_tracking_response.xml
|
524
|
-
- test/fixtures/xml/usps/delivered_tracking_response.xml
|
525
523
|
- test/fixtures/xml/usps/first_class_packages_with_invalid_mail_type_response.xml
|
526
524
|
- test/fixtures/xml/usps/first_class_packages_with_mail_type_response.xml
|
527
525
|
- test/fixtures/xml/usps/first_class_packages_without_mail_type_response.xml
|
528
526
|
- test/fixtures/xml/usps/invalid_xml_tracking_response_error.xml
|
529
527
|
- test/fixtures/xml/usps/tracking_request.xml
|
530
528
|
- test/fixtures/xml/usps/tracking_response.xml
|
529
|
+
- test/fixtures/xml/usps/tracking_response_alt.xml
|
531
530
|
- test/fixtures/xml/usps/tracking_response_failure.xml
|
532
531
|
- test/fixtures/xml/usps/tracking_response_not_available.xml
|
533
532
|
- test/fixtures/xml/usps/tracking_response_test_error.xml
|
metadata.gz.sig
CHANGED
Binary file
|
@@ -1,11 +0,0 @@
|
|
1
|
-
<?xml version="1.0"?>
|
2
|
-
<TrackResponse>
|
3
|
-
<TrackInfo ID="9361289949034102283511">
|
4
|
-
<TrackSummary>Your item was delivered to the front desk or reception area at 2:16 pm on October 12, 2013 in BROOKLYN, NY 11201.</TrackSummary>
|
5
|
-
<TrackDetail>Out for Delivery, October 12, 2013, 10:16 am, BROOKLYN, NY 11201</TrackDetail>
|
6
|
-
<TrackDetail>Sorting Complete, October 12, 2013, 10:06 am, BROOKLYN, NY 11201</TrackDetail>
|
7
|
-
<TrackDetail>Arrival at Post Office, October 12, 2013, 6:32 am, BROOKLYN, NY 11201</TrackDetail>
|
8
|
-
<TrackDetail>Acceptance, October 12, 2013, 6:26 am, BROOKLYN, NY 11201</TrackDetail>
|
9
|
-
<TrackDetail>Electronic Shipping Info Received, October 12, 2013</TrackDetail>
|
10
|
-
</TrackInfo>
|
11
|
-
</TrackResponse>
|
@@ -1,11 +0,0 @@
|
|
1
|
-
<?xml version="1.0"?>
|
2
|
-
<TrackResponse>
|
3
|
-
<TrackInfo ID="9361289949034102283511">
|
4
|
-
<TrackSummary>Your item was delivered at 2:16 pm on October 12, 2013 in BROOKLYN, NY 11201.</TrackSummary>
|
5
|
-
<TrackDetail>Out for Delivery, October 12, 2013, 10:16 am, BROOKLYN, NY 11201</TrackDetail>
|
6
|
-
<TrackDetail>Sorting Complete, October 12, 2013, 10:06 am, BROOKLYN, NY 11201</TrackDetail>
|
7
|
-
<TrackDetail>Arrival at Post Office, October 12, 2013, 6:32 am, BROOKLYN, NY 11201</TrackDetail>
|
8
|
-
<TrackDetail>Acceptance, October 12, 2013, 6:26 am, BROOKLYN, NY 11201</TrackDetail>
|
9
|
-
<TrackDetail>Electronic Shipping Info Received, October 12, 2013</TrackDetail>
|
10
|
-
</TrackInfo>
|
11
|
-
</TrackResponse>
|