active_shipping 1.1.2 → 1.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a07fa58ed94231189659050981cff9cd14bebe39
4
- data.tar.gz: 1578bdf8fc0512fee2909bd8b24d2ae5f120ee4a
3
+ metadata.gz: 5868e8cfd35acb6845aa850d2a8e12999cc0a71b
4
+ data.tar.gz: 998bba416cc03877b6da20f141fff0272b5f9543
5
5
  SHA512:
6
- metadata.gz: 638e7db8b10b0ecc916c272a0bc14067edd447b2edf738013a23fdaee4c6d32eea0ffc8880b1c6c19c7360ace2b22663f5c9301fb58e5d1c6d0d5b267315e98a
7
- data.tar.gz: 8f36922200fa5aa2432426bd1757dab15a7e3961ddf533b36000f5c7c168f5291718d5b814f98d89ab9acdd195e0121a485cbef7d14a87d733e25ffc68c46d32
6
+ metadata.gz: 8ecbdea4269a2eeb54d54e45219dbbddd4518fcc65a88cee70575d0c8c40814ec1dbd99986bc715e6bb10e66ab16d3da3ee534e209b4a94ea0557053f5eeb372
7
+ data.tar.gz: 4b27e759684cea1e91286dfc062cc5ab167ae9696053b0b252e8c4b0804d7aee04c5ba2f1bf7cbf6bd3a8bc7d63ddc9e37c4317c58c70e9cfb1f84ffaa0f53ee
@@ -539,23 +539,19 @@ module ActiveShipping
539
539
 
540
540
  def extract_address(document, possible_node_names)
541
541
  node = nil
542
+ args = {}
542
543
  possible_node_names.each do |name|
543
544
  node = document.at(name)
544
545
  break if node
545
546
  end
546
547
 
547
- args = if node && node.at('CountryCode')
548
- {
549
- :country => node.at('CountryCode').text,
550
- :province => node.at('StateOrProvinceCode').text,
551
- :city => node.at('City').text
552
- }
553
- else
554
- {
555
- :country => ActiveUtils::Country.new(:alpha2 => 'ZZ', :name => 'Unknown or Invalid Territory', :alpha3 => 'ZZZ', :numeric => '999'),
556
- :province => 'unknown',
557
- :city => 'unknown'
558
- }
548
+ if node
549
+ args[:country] =
550
+ node.at('CountryCode').try(:text) ||
551
+ ActiveUtils::Country.new(:alpha2 => 'ZZ', :name => 'Unknown or Invalid Territory', :alpha3 => 'ZZZ', :numeric => '999')
552
+
553
+ args[:province] = node.at('StateOrProvinceCode').try(:text) || 'unknown'
554
+ args[:city] = node.at('City').try(:text) || 'unknown'
559
555
  end
560
556
 
561
557
  Location.new(args)
@@ -65,6 +65,7 @@ module ActiveShipping
65
65
  "84" => "UPS Today Intercity",
66
66
  "85" => "UPS Today Express",
67
67
  "86" => "UPS Today Express Saver"
68
+
68
69
  }
69
70
 
70
71
  CANADA_ORIGIN_SERVICES = {
@@ -133,6 +134,15 @@ module ActiveShipping
133
134
  parse_rate_response(origin, destination, packages, response, options)
134
135
  end
135
136
 
137
+ # Retrieves tracking information for a previous shipment
138
+ #
139
+ # @note Override with whatever you need to get a shipping label
140
+ #
141
+ # @param tracking_number [String] The unique identifier of the shipment to track.
142
+ # @param options [Hash] Carrier-specific parameters.
143
+ # @option options [Boolean] :mail_innovations Set this to true to track a Mail Innovations Package
144
+ # @return [ActiveShipping::TrackingResponse] The response from the carrier. This
145
+ # response should a list of shipment tracking events if successful.
136
146
  def find_tracking_info(tracking_number, options = {})
137
147
  options = @options.update(options)
138
148
  access_request = build_access_request
@@ -514,11 +524,13 @@ module ActiveShipping
514
524
  def build_tracking_request(tracking_number, options = {})
515
525
  xml_builder = Nokogiri::XML::Builder.new do |xml|
516
526
  xml.TrackRequest do
527
+ xml.TrackingOption(options[:tracking_option]) if options[:tracking_option]
517
528
  xml.Request do
518
529
  xml.RequestAction('Track')
519
530
  xml.RequestOption('1')
520
531
  end
521
532
  xml.TrackingNumber(tracking_number.to_s)
533
+ xml.TrackingOption('03') if options[:mail_innovations]
522
534
  end
523
535
  end
524
536
  xml_builder.to_xml
@@ -256,7 +256,7 @@ module ActiveShipping
256
256
  xml.ClientIp { xml.text(@options[:client_ip] || '127.0.0.1') }
257
257
  xml.SourceId { xml.text(@options[:source_id] || 'active_shipping') }
258
258
  xml.TrackID('ID' => tracking_number) do
259
- xml.DestinationZipCode { xml.text(@options[:destination_zip])} if @options[:destination_zip]
259
+ xml.DestinationZipCode { xml.text(strip_zip(@options[:destination_zip]))} if @options[:destination_zip]
260
260
  if @options[:mailing_date]
261
261
  formatted_date = @options[:mailing_date].strftime('%Y-%m-%d')
262
262
  xml.MailingDate { xml.text(formatted_date)}
@@ -58,11 +58,15 @@ module ActiveShipping
58
58
  attr_reader :origin, :destination, :package_rates,
59
59
  :carrier, :service_name, :service_code,
60
60
  :shipping_date, :delivery_date, :delivery_range,
61
- :currency, :negotiated_rate, :insurance_price
61
+ :currency, :negotiated_rate, :insurance_price,
62
+ :estimate_reference, :expires_at, :pickup_time
62
63
 
63
64
  def initialize(origin, destination, carrier, service_name, options = {})
64
65
  @origin, @destination, @carrier, @service_name = origin, destination, carrier, service_name
65
66
  @service_code = options[:service_code]
67
+ @estimate_reference = options[:estimate_reference]
68
+ @pickup_time = options[:pickup_time]
69
+ @expires_at = options[:expires_at]
66
70
  if options[:package_rates]
67
71
  @package_rates = options[:package_rates].map { |p| p.update(:rate => Package.cents_from(p[:rate])) }
68
72
  else
@@ -1,3 +1,3 @@
1
1
  module ActiveShipping
2
- VERSION = "1.1.2"
2
+ VERSION = "1.1.3"
3
3
  end
@@ -0,0 +1,107 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <TrackReply xmlns="http://fedex.com/ws/track/v7" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
3
+ <HighestSeverity>SUCCESS</HighestSeverity>
4
+ <Notifications>
5
+ <Severity>SUCCESS</Severity>
6
+ <Source>trck</Source>
7
+ <Code>0</Code>
8
+ <Message>Request was successfully processed.</Message>
9
+ <LocalizedMessage>Request was successfully processed.</LocalizedMessage>
10
+ </Notifications>
11
+ <TransactionDetail>
12
+ <CustomerTransactionId>ActiveShipping</CustomerTransactionId>
13
+ </TransactionDetail>
14
+ <Version>
15
+ <ServiceId>trck</ServiceId>
16
+ <Major>7</Major>
17
+ <Intermediate>0</Intermediate>
18
+ <Minor>0</Minor>
19
+ </Version>
20
+ <CompletedTrackDetails>
21
+ <HighestSeverity>SUCCESS</HighestSeverity>
22
+ <Notifications>
23
+ <Severity>SUCCESS</Severity>
24
+ <Source>trck</Source>
25
+ <Code>0</Code>
26
+ <Message>Request was successfully processed.</Message>
27
+ <LocalizedMessage>Request was successfully processed.</LocalizedMessage>
28
+ </Notifications>
29
+ <DuplicateWaybill>false</DuplicateWaybill>
30
+ <MoreData>false</MoreData>
31
+ <TrackDetails>
32
+ <Notification>
33
+ <Severity>SUCCESS</Severity>
34
+ <Source>trck</Source>
35
+ <Code>0</Code>
36
+ <Message>Request was successfully processed.</Message>
37
+ <LocalizedMessage>Request was successfully processed.</LocalizedMessage>
38
+ </Notification>
39
+ <TrackingNumber>798701052354</TrackingNumber>
40
+ <TrackingNumberUniqueIdentifier>2456777000~798701052354~FX</TrackingNumberUniqueIdentifier>
41
+ <StatusDetail>
42
+ <Code>DL</Code>
43
+ <Description>Delivered</Description>
44
+ <Location>
45
+ <Residential>false</Residential>
46
+ </Location>
47
+ </StatusDetail>
48
+ <CarrierCode>FDXE</CarrierCode>
49
+ <OperatingCompanyOrCarrierDescription>FedEx Express</OperatingCompanyOrCarrierDescription>
50
+ <Service>
51
+ <Type>PRIORITY_OVERNIGHT</Type>
52
+ <Description>FedEx International Priority</Description>
53
+ </Service>
54
+ <PackageSequenceNumber>0</PackageSequenceNumber>
55
+ <PackageCount>0</PackageCount>
56
+ <SpecialHandlings>
57
+ <Type>DELIVER_WEEKDAY</Type>
58
+ <Description>Deliver Weekday</Description>
59
+ <PaymentType>OTHER</PaymentType>
60
+ </SpecialHandlings>
61
+ <SpecialHandlings>
62
+ <Type>RESIDENTIAL_DELIVERY</Type>
63
+ <Description>Residential Delivery</Description>
64
+ <PaymentType>OTHER</PaymentType>
65
+ </SpecialHandlings>
66
+ <ShipTimestamp>2014-04-30T15:27:00+00:00</ShipTimestamp>
67
+ <DestinationAddress>
68
+ <City>SAITAMA</City>
69
+ <CountryCode>JP</CountryCode>
70
+ <CountryName>Japan</CountryName>
71
+ <Residential>false</Residential>
72
+ </DestinationAddress>
73
+ <ActualDeliveryTimestamp>2014-05-08T19:02:00+00:00</ActualDeliveryTimestamp>
74
+ <ActualDeliveryAddress>
75
+ <City>SAITAMA</City>
76
+ <CountryCode>JP</CountryCode>
77
+ <CountryName>Japan</CountryName>
78
+ <Residential>false</Residential>
79
+ </ActualDeliveryAddress>
80
+ <DeliveryAttempts>0</DeliveryAttempts>
81
+ <DeliverySignatureName>..SAITOU</DeliverySignatureName>
82
+ <TotalUniqueAddressCountInConsolidation>0</TotalUniqueAddressCountInConsolidation>
83
+ <Signature>
84
+ <Notifications>
85
+ <Severity>ERROR</Severity>
86
+ <Source>trck</Source>
87
+ <Code>4550</Code>
88
+ <Message>Signature images are not available for display for shipments to this country.</Message>
89
+ <LocalizedMessage>Signature images are not available for display for shipments to this country.</LocalizedMessage>
90
+ </Notifications>
91
+ </Signature>
92
+ <RedirectToHoldEligibility>INELIGIBLE</RedirectToHoldEligibility>
93
+ <Events>
94
+ <Timestamp>2014-05-08T19:02:00+00:00</Timestamp>
95
+ <EventType>DL</EventType>
96
+ <EventDescription>Delivered</EventDescription>
97
+ <Address>
98
+ <City>SAITAMA</City>
99
+ <PostalCode>34800</PostalCode>
100
+ <CountryCode>JP</CountryCode>
101
+ <Residential>false</Residential>
102
+ </Address>
103
+ <ArrivalLocation>DELIVERY_LOCATION</ArrivalLocation>
104
+ </Events>
105
+ </TrackDetails>
106
+ </CompletedTrackDetails>
107
+ </TrackReply>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0"?>
2
+ <AccessRequest>
3
+ <AccessLicenseNumber>key</AccessLicenseNumber>
4
+ <UserId>login</UserId>
5
+ <Password>password</Password>
6
+ </AccessRequest>
@@ -0,0 +1,9 @@
1
+ <?xml version="1.0"?>
2
+ <TrackRequest>
3
+ <TrackingOption>03</TrackingOption>
4
+ <Request>
5
+ <RequestAction>Track</RequestAction>
6
+ <RequestOption>1</RequestOption>
7
+ </Request>
8
+ <TrackingNumber>1Z5FX0076803466397</TrackingNumber>
9
+ </TrackRequest>
@@ -23,6 +23,8 @@ class RemoteCorreiosTest < Minitest::Test
23
23
  assert_equal 1, response.params["responses"].size
24
24
  assert_equal 2, response.rates.size
25
25
  assert_equal 1, response.raw_responses.size
26
+ rescue ActiveUtils::ConnectionError
27
+ skip("This API is unreliable and often times out.")
26
28
  end
27
29
 
28
30
  def test_poster_and_book_request
@@ -34,6 +36,8 @@ class RemoteCorreiosTest < Minitest::Test
34
36
  assert_equal 2, response.params["responses"].size
35
37
  assert_equal 2, response.rates.size
36
38
  assert_equal 2, response.raw_responses.size
39
+ rescue ActiveUtils::ConnectionError
40
+ skip("This API is unreliable and often times out.")
37
41
  end
38
42
 
39
43
  def test_book_request_with_specific_services
@@ -45,6 +49,8 @@ class RemoteCorreiosTest < Minitest::Test
45
49
  assert_equal 1, response.params["responses"].size
46
50
  assert_equal 3, response.rates.size
47
51
  assert_equal 1, response.raw_responses.size
52
+ rescue ActiveUtils::ConnectionError
53
+ skip("This API is unreliable and often times out.")
48
54
  end
49
55
 
50
56
  def test_response_prices
@@ -57,11 +63,17 @@ class RemoteCorreiosTest < Minitest::Test
57
63
  total_price = response.rates.sum(&:price)
58
64
 
59
65
  assert total_price == book_price + poster_price
66
+ rescue ActiveUtils::ConnectionError
67
+ skip("This API is unreliable and often times out.")
60
68
  end
61
69
 
62
70
  def test_invalid_zip
63
71
  error = assert_raises(ActiveShipping::ResponseError) do
64
- @carrier.find_rates(@saopaulo, @invalid_city, [@book])
72
+ begin
73
+ @carrier.find_rates(@saopaulo, @invalid_city, [@book])
74
+ rescue ActiveUtils::ConnectionError
75
+ skip("This API is unreliable and often times out.")
76
+ end
65
77
  end
66
78
 
67
79
  assert_kind_of RateResponse, error.response
@@ -72,7 +84,11 @@ class RemoteCorreiosTest < Minitest::Test
72
84
 
73
85
  def test_valid_book_and_invalid_book
74
86
  error = assert_raises(ActiveShipping::ResponseError) do
75
- @carrier.find_rates(@saopaulo, @riodejaneiro, [@book, @invalid_book])
87
+ begin
88
+ @carrier.find_rates(@saopaulo, @riodejaneiro, [@book, @invalid_book])
89
+ rescue ActiveUtils::ConnectionError
90
+ skip("This API is unreliable and often times out.")
91
+ end
76
92
  end
77
93
 
78
94
  assert_kind_of RateResponse, error.response
@@ -312,6 +312,21 @@ class FedExTest < Minitest::Test
312
312
  assert_equal nil, response.delivery_signature
313
313
  end
314
314
 
315
+ def test_state_degrades_to_unknown
316
+ mock_response = xml_fixture('fedex/tracking_response_with_blank_state')
317
+ @carrier.expects(:commit).returns(mock_response)
318
+
319
+ response = @carrier.find_tracking_info('798701052354')
320
+
321
+ destination_address = ActiveShipping::Location.new(
322
+ city: 'SAITAMA',
323
+ country: 'Japan',
324
+ state: 'unknown'
325
+ )
326
+
327
+ assert_equal destination_address.to_hash, response.destination.to_hash
328
+ end
329
+
315
330
  def test_tracking_info_for_in_transit
316
331
  mock_response = xml_fixture('fedex/tracking_response_in_transit')
317
332
  @carrier.expects(:commit).returns(mock_response)
@@ -21,6 +21,12 @@ class UPSTest < Minitest::Test
21
21
  assert UPS.new(:login => 'blah', :password => 'bloo', :key => 'kee')
22
22
  end
23
23
 
24
+ def test_find_tracking_info_should_create_correct_xml
25
+ xml_request = xml_fixture('ups/access_request') + xml_fixture('ups/tracking_request')
26
+ @carrier.expects(:commit).with(:track, xml_request, true).returns(@tracking_response)
27
+ @carrier.find_tracking_info('1Z5FX0076803466397', :tracking_option => '03', :test => true)
28
+ end
29
+
24
30
  def test_find_tracking_info_should_return_a_tracking_response
25
31
  @carrier.expects(:commit).returns(@tracking_response)
26
32
  assert_equal 'ActiveShipping::TrackingResponse', @carrier.find_tracking_info('1Z5FX0076803466397').class.name
@@ -14,6 +14,11 @@ class USPSTest < Minitest::Test
14
14
  @carrier.find_tracking_info('9102901000462189604217', :destination_zip => '12345', :mailing_date => Date.new(2010,1,30))
15
15
  end
16
16
 
17
+ def test_tracking_request_should_handle_9_digit_zip
18
+ @carrier.expects(:commit).with(:track, xml_fixture('usps/tracking_request'),false).returns(@tracking_response)
19
+ @carrier.find_tracking_info('9102901000462189604217', :destination_zip => '12345-4444', :mailing_date => Date.new(2010,1,30))
20
+ end
21
+
17
22
  def test_tracking_failure_should_raise_exception
18
23
  @carrier.expects(:commit).returns(@tracking_response_failure)
19
24
  e = assert_raises ResponseError do
@@ -29,4 +29,10 @@ class RateEstimateTest < Minitest::Test
29
29
  RateEstimate.new(nil, nil, nil, nil, :currency => 'FAKE')
30
30
  end
31
31
  end
32
+
33
+ def test_estimate_reference_is_set
34
+ est = RateEstimate.new(@origin, @destination, @carrier, @service_name, @options.merge(estimate_reference: "somefakeref"))
35
+
36
+ assert_equal "somefakeref", est.estimate_reference
37
+ end
32
38
  end
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.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - James MacAulay
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-05-25 00:00:00.000000000 Z
14
+ date: 2015-05-27 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: quantified
@@ -263,6 +263,7 @@ files:
263
263
  - test/fixtures/xml/fedex/tracking_response_multiple_results.xml
264
264
  - test/fixtures/xml/fedex/tracking_response_not_found.xml
265
265
  - test/fixtures/xml/fedex/tracking_response_shipment_exception.xml
266
+ - test/fixtures/xml/fedex/tracking_response_with_blank_state.xml
266
267
  - test/fixtures/xml/fedex/unknown_fedex_document_reply.xml
267
268
  - test/fixtures/xml/kunaki/invalid_state_response.xml
268
269
  - test/fixtures/xml/kunaki/no_valid_items_response.xml
@@ -290,6 +291,7 @@ files:
290
291
  - test/fixtures/xml/stamps/purchase_postage_response.xml
291
292
  - test/fixtures/xml/stamps/track_shipment_request.xml
292
293
  - test/fixtures/xml/stamps/track_shipment_response.xml
294
+ - test/fixtures/xml/ups/access_request.xml
293
295
  - test/fixtures/xml/ups/delivered_shipment_with_refund.xml
294
296
  - test/fixtures/xml/ups/delivered_shipment_without_events_tracking_response.xml
295
297
  - test/fixtures/xml/ups/delivery_dates_response.xml
@@ -305,6 +307,7 @@ files:
305
307
  - test/fixtures/xml/ups/test_real_home_as_residential_destination_response.xml
306
308
  - test/fixtures/xml/ups/test_real_home_as_residential_destination_response_with_insured.xml
307
309
  - test/fixtures/xml/ups/test_real_home_as_residential_destination_with_origin_account_response.xml
310
+ - test/fixtures/xml/ups/tracking_request.xml
308
311
  - test/fixtures/xml/ups/triple_accept_response.xml
309
312
  - test/fixtures/xml/ups/triple_confirm_response.xml
310
313
  - test/fixtures/xml/usps/beverly_hills_to_new_york_book_commercial_base_rate_response.xml
@@ -448,6 +451,7 @@ test_files:
448
451
  - test/fixtures/xml/fedex/tracking_response_multiple_results.xml
449
452
  - test/fixtures/xml/fedex/tracking_response_not_found.xml
450
453
  - test/fixtures/xml/fedex/tracking_response_shipment_exception.xml
454
+ - test/fixtures/xml/fedex/tracking_response_with_blank_state.xml
451
455
  - test/fixtures/xml/fedex/unknown_fedex_document_reply.xml
452
456
  - test/fixtures/xml/kunaki/invalid_state_response.xml
453
457
  - test/fixtures/xml/kunaki/no_valid_items_response.xml
@@ -475,6 +479,7 @@ test_files:
475
479
  - test/fixtures/xml/stamps/purchase_postage_response.xml
476
480
  - test/fixtures/xml/stamps/track_shipment_request.xml
477
481
  - test/fixtures/xml/stamps/track_shipment_response.xml
482
+ - test/fixtures/xml/ups/access_request.xml
478
483
  - test/fixtures/xml/ups/delivered_shipment_with_refund.xml
479
484
  - test/fixtures/xml/ups/delivered_shipment_without_events_tracking_response.xml
480
485
  - test/fixtures/xml/ups/delivery_dates_response.xml
@@ -490,6 +495,7 @@ test_files:
490
495
  - test/fixtures/xml/ups/test_real_home_as_residential_destination_response.xml
491
496
  - test/fixtures/xml/ups/test_real_home_as_residential_destination_response_with_insured.xml
492
497
  - test/fixtures/xml/ups/test_real_home_as_residential_destination_with_origin_account_response.xml
498
+ - test/fixtures/xml/ups/tracking_request.xml
493
499
  - test/fixtures/xml/ups/triple_accept_response.xml
494
500
  - test/fixtures/xml/ups/triple_confirm_response.xml
495
501
  - test/fixtures/xml/usps/beverly_hills_to_new_york_book_commercial_base_rate_response.xml