active_shipping 1.6.3 → 1.6.4

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: b9a6c28f3db40c57a1e0867e54f2ef39eddbd137
4
- data.tar.gz: 57b27cc5be5e949d436c1b0cd5dc40538de8612a
3
+ metadata.gz: bf492f5f78fa92510f0f17837a59225eca7a8230
4
+ data.tar.gz: d8609c76e64bb66b7ca522eab646f944b4684c90
5
5
  SHA512:
6
- metadata.gz: 28d093af4fc4bfbe762f7aeefff77201277f08eb25e07897d498b6f71d03ff40fa8d6bbcae0ea32f6fccc6c3c6bc925a86e14c1bf8b87026dd7705086022374d
7
- data.tar.gz: eee9c390eabaccd2c95f4991fa761a0c90334e6fa5ad08416f82e9740e232a1637f614447afe534cb9bfc8555724ca57f26d86e8d79688cc1a07570e0e617ab2
6
+ metadata.gz: 9e31884ad4afb2e2948f6f1558f174b7ca4c09b6428818ad555e3798b02e61321ea9a1de6664d4acc6969f4756c3e5c79e932773ef603b5b412a53e91fe776d5
7
+ data.tar.gz: ebe8569df5061fa69e3a4fd36f281ce83c907dd5f8bc5c76a9b06c60c2d07050d21c2e925fd69d7637360edf8de80ee1b931a8df7ebcc9b1ccfbcd18b20e7a1c
@@ -474,31 +474,46 @@ module ActiveShipping
474
474
  message = response_message(xml)
475
475
 
476
476
  if success
477
+ missing_xml_field = false
477
478
  rate_estimates = xml.root.css('> RateReplyDetails').map do |rated_shipment|
478
- service_code = rated_shipment.at('ServiceType').text
479
- is_saturday_delivery = rated_shipment.at('AppliedOptions').try(:text) == 'SATURDAY_DELIVERY'
480
- service_type = is_saturday_delivery ? "#{service_code}_SATURDAY_DELIVERY" : service_code
481
-
482
- transit_time = rated_shipment.at('TransitTime').text if ["FEDEX_GROUND", "GROUND_HOME_DELIVERY"].include?(service_code)
483
- max_transit_time = rated_shipment.at('MaximumTransitTime').try(:text) if service_code == "FEDEX_GROUND"
484
-
485
- delivery_timestamp = rated_shipment.at('DeliveryTimestamp').try(:text)
486
- delivery_range = delivery_range_from(transit_time, max_transit_time, delivery_timestamp, (service_code == "GROUND_HOME_DELIVERY"), options)
487
-
488
- currency = rated_shipment.at('RatedShipmentDetails/ShipmentRateDetail/TotalNetCharge/Currency').text
489
- RateEstimate.new(origin, destination, @@name,
490
- self.class.service_name_for_code(service_type),
491
- :service_code => service_code,
492
- :total_price => rated_shipment.at('RatedShipmentDetails/ShipmentRateDetail/TotalNetCharge/Amount').text.to_f,
493
- :currency => currency,
494
- :packages => packages,
495
- :delivery_range => delivery_range)
479
+ begin
480
+ service_code = rated_shipment.at('ServiceType').text
481
+ is_saturday_delivery = rated_shipment.at('AppliedOptions').try(:text) == 'SATURDAY_DELIVERY'
482
+ service_type = is_saturday_delivery ? "#{service_code}_SATURDAY_DELIVERY" : service_code
483
+
484
+ transit_time = rated_shipment.at('TransitTime').text if ["FEDEX_GROUND", "GROUND_HOME_DELIVERY"].include?(service_code)
485
+ max_transit_time = rated_shipment.at('MaximumTransitTime').try(:text) if service_code == "FEDEX_GROUND"
486
+
487
+ delivery_timestamp = rated_shipment.at('DeliveryTimestamp').try(:text)
488
+ delivery_range = delivery_range_from(transit_time, max_transit_time, delivery_timestamp, (service_code == "GROUND_HOME_DELIVERY"), options)
489
+
490
+ currency = rated_shipment.at('RatedShipmentDetails/ShipmentRateDetail/TotalNetCharge/Currency').text
491
+
492
+ RateEstimate.new(origin, destination, @@name,
493
+ self.class.service_name_for_code(service_type),
494
+ :service_code => service_code,
495
+ :total_price => rated_shipment.at('RatedShipmentDetails/ShipmentRateDetail/TotalNetCharge/Amount').text.to_f,
496
+ :currency => currency,
497
+ :packages => packages,
498
+ :delivery_range => delivery_range)
499
+ rescue NoMethodError
500
+ missing_xml_field = true
501
+ nil
502
+ end
496
503
  end
497
504
 
505
+ rate_estimates = rate_estimates.compact
506
+ logger.warn("[FedexParseRateError] Some fields where missing in the response: #{response}") if logger && missing_xml_field
507
+
498
508
  if rate_estimates.empty?
499
509
  success = false
500
- message = "No shipping rates could be found for the destination address" if message.blank?
510
+ if missing_xml_field
511
+ message = "The response from the carrier contained errors and could not be treated"
512
+ else
513
+ message = "No shipping rates could be found for the destination address" if message.blank?
514
+ end
501
515
  end
516
+
502
517
  else
503
518
  rate_estimates = []
504
519
  end
@@ -727,6 +727,24 @@ module ActiveShipping
727
727
  xml.DCISType(PACKAGE_DELIVERY_CONFIRMATION_CODES[delivery_confirmation])
728
728
  end
729
729
  end
730
+
731
+ if dry_ice = package.options[:dry_ice]
732
+ xml.DryIce do
733
+ xml.RegulationSet(dry_ice[:regulation_set] || 'CFR')
734
+ xml.DryIceWeight do
735
+ xml.UnitOfMeasurement do
736
+ xml.Code(options[:imperial] ? 'LBS' : 'KGS')
737
+ end
738
+ # Cannot be more than package weight.
739
+ # Should be more than 0.0.
740
+ # Valid characters are 0-9 and .(Decimal point).
741
+ # Limit to 1 digit after the decimal. The maximum length
742
+ # of the field is 5 including . and can hold up
743
+ # to 1 decimal place.
744
+ xml.Weight(dry_ice[:weight])
745
+ end
746
+ end
747
+ end
730
748
  end
731
749
 
732
750
  # not implemented: * Shipment/Package/LargePackageIndicator element
@@ -1,3 +1,3 @@
1
1
  module ActiveShipping
2
- VERSION = "1.6.3"
2
+ VERSION = "1.6.4"
3
3
  end
@@ -426,4 +426,17 @@ class RemoteUPSTest < Minitest::Test
426
426
  assert_instance_of ActiveShipping::LabelResponse, response
427
427
  assert_equal "GIF", response.params['ShipmentResults']['PackageResults']['LabelImage']['LabelImageFormat']['Code']
428
428
  end
429
+
430
+ def test_create_shipment_with_dry_ice_options
431
+ response = @carrier.create_shipment(
432
+ location_fixtures[:beverly_hills_with_name],
433
+ location_fixtures[:new_york_with_name],
434
+ package_fixtures.values_at(:frozen_stuff),
435
+ :service_code => '01',
436
+ :test => true
437
+ )
438
+
439
+ assert response.success?
440
+ assert_instance_of ActiveShipping::LabelResponse, response
441
+ end
429
442
  end
data/test/test_helper.rb CHANGED
@@ -85,6 +85,7 @@ module ActiveShipping::Test
85
85
  :small_half_pound => Package.new(8, [1, 1, 1], :units => :imperial),
86
86
  :big_half_pound => Package.new((16 * 50), [24, 24, 36], :units => :imperial),
87
87
  :chocolate_stuff => Package.new(80, [2, 6, 12], :units => :imperial),
88
+ :frozen_stuff => Package.new(80, [2, 6, 12], :units => :imperial, :dry_ice => {weight: 1.4}),
88
89
  :declared_value => Package.new(80, [2, 6, 12], :units => :imperial, :currency => 'USD', :value => 999.99),
89
90
  :tshirts => Package.new(10 * 16, nil, :units => :imperial),
90
91
  :shipping_container => Package.new(2200000, [2440, 2600, 6058], :description => '20 ft Standard Container', :units => :metric),
@@ -205,6 +205,32 @@ class FedExTest < Minitest::Test
205
205
  assert_equal message, exception.message
206
206
  end
207
207
 
208
+ def test_parsing_response_with_no_system_code_for_one_rate_does_not_crash
209
+ mock_response = xml_fixture('fedex/freight_rate_response').gsub('<v13:ServiceType>FEDEX_FREIGHT_ECONOMY</v13:ServiceType>','')
210
+
211
+ @carrier.expects(:commit).returns(mock_response)
212
+ @carrier.logger = Logger.new(StringIO.new)
213
+ @carrier.logger.expects(:warn).once.with("[FedexParseRateError] Some fields where missing in the response: #{mock_response}")
214
+
215
+ rates = @carrier.find_rates( location_fixtures[:ottawa], location_fixtures[:beverly_hills], package_fixtures.values_at(:book, :wii), :test => true)
216
+ assert rates.rates.length == 1
217
+ assert_equal rates.rates[0].service_code, 'FEDEX_FREIGHT_PRIORITY'
218
+ end
219
+
220
+ def test_parsing_response_with_no_system_code_on_any_shipping_rate
221
+ mock_response = xml_fixture('fedex/freight_rate_response').gsub('<v13:ServiceType>FEDEX_FREIGHT_ECONOMY</v13:ServiceType>','').gsub('<v13:ServiceType>FEDEX_FREIGHT_PRIORITY</v13:ServiceType>','')
222
+
223
+ @carrier.expects(:commit).returns(mock_response)
224
+ @carrier.logger = Logger.new(StringIO.new)
225
+ @carrier.logger.expects(:warn).once.with("[FedexParseRateError] Some fields where missing in the response: #{mock_response}")
226
+
227
+ exception = assert_raises(ActiveShipping::ResponseError) do
228
+ @carrier.find_rates( location_fixtures[:ottawa], location_fixtures[:beverly_hills], package_fixtures.values_at(:book, :wii), :test => true)
229
+ end
230
+ message = "The response from the carrier contained errors and could not be treated"
231
+ assert_equal exception.message, message
232
+ end
233
+
208
234
  def test_service_name_for_code
209
235
  FedEx::SERVICE_TYPES.each do |capitalized_name, readable_name|
210
236
  assert_equal readable_name, FedEx.service_name_for_code(capitalized_name)
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.6.3
4
+ version: 1.6.4
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-12-03 00:00:00.000000000 Z
14
+ date: 2015-12-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: quantified