active_shipping 1.2.1 → 1.2.2

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: 1d7d90329e0d2d80ee6f1eb5ae1f2bdc1f16b6dc
4
- data.tar.gz: ba9ce52d2f832b124ef5ccd67f4140888eac68d4
3
+ metadata.gz: 04f69978f627aaebea9a3ddd7cb9fea8f3bfa503
4
+ data.tar.gz: fc82de023d281c9f6d20f40ae0c4e7566a4a9d9a
5
5
  SHA512:
6
- metadata.gz: 549c8f94cc474cd8e00050433bf1b0fddcdb41c2d6afd8a894151e607bb8f33c3f4a77c2c486d9088ed785cde069de5fab9ca012fa2691e4936b81aafb82c2f6
7
- data.tar.gz: e7999cb24985d89f9de6896ae7534619c6f354c72ba5cd0ac85869d6ffd858255a647d1824d131ee3d327127195a685a3ac5414ceecf2d5d219effc7d108e658
6
+ metadata.gz: e5348f5e0ab81dd551e0b899fc8f62302013be5b0873e84de37cdb6e813c403d0e8526d0e0f58e38c3c419899caf7df7caa1f7eff29b893a6917681af07d5990
7
+ data.tar.gz: 922f4675449eb2bf37ee8b7917589b679b09146d4174fb48661ba9e5fe64285ddf205475a8018490f67acc18563d73eb080d2b4e80f1f8e14bbf21cb8be6142b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # ActiveShipping CHANGELOG
2
2
 
3
+ ### v1.2.2
4
+
5
+ - Fix "RECTANGULAR" errors with small USPS US->US package rate requests
6
+ - Fix error tracking USPS packages to other countries
7
+ - Fix USPS rate requests to destinations with only a country.
8
+
3
9
  ### v1.2.1
4
10
 
5
11
  - Fix compatibility with latest USPS WEBTOOLS international rate schema changes.
@@ -246,7 +246,9 @@ module ActiveShipping
246
246
 
247
247
  country_node = node.at('EventCountry')
248
248
  country = country_node ? country_node.text : ''
249
- country = 'USA' if country.empty?
249
+ country = 'UNITED STATES' if country.empty?
250
+ # USPS returns upcased country names which ActiveUtils doesn't recognize without translation
251
+ country = find_country_code_case_insensitive(country)
250
252
 
251
253
  time = Time.parse(timestamp)
252
254
  zoneless_time = Time.utc(time.year, time.month, time.mday, time.hour, time.min, time.sec)
@@ -343,8 +345,11 @@ module ActiveShipping
343
345
  xml.ZipDestination(strip_zip(destination_zip))
344
346
  xml.Pounds(0)
345
347
  xml.Ounces("%0.1f" % [package.ounces, 1].max)
346
- xml.Container(CONTAINERS[package.options[:container]] || (package.cylinder? ? 'NONRECTANGULAR' : 'RECTANGULAR'))
347
- xml.Size(USPS.size_code_for(package))
348
+ size_code = USPS.size_code_for(package)
349
+ container = CONTAINERS[package.options[:container]]
350
+ container ||= (package.cylinder? ? 'NONRECTANGULAR' : 'RECTANGULAR') if size_code == 'LARGE'
351
+ xml.Container(container)
352
+ xml.Size(size_code)
348
353
  xml.Width("%0.2f" % package.inches(:width))
349
354
  xml.Length("%0.2f" % package.inches(:length))
350
355
  xml.Height("%0.2f" % package.inches(:height))
@@ -404,8 +409,10 @@ module ActiveShipping
404
409
  xml.public_send(COMMERCIAL_FLAG_NAME.fetch(commercial_type), 'Y')
405
410
  end
406
411
  xml.OriginZip(origin.zip)
407
- xml.AcceptanceDateTime((options[:acceptance_time] || Time.now.utc).iso8601)
408
- xml.DestinationPostalCode(destination.zip)
412
+ if destination.zip.present?
413
+ xml.AcceptanceDateTime((options[:acceptance_time] || Time.now.utc).iso8601)
414
+ xml.DestinationPostalCode(destination.zip)
415
+ end
409
416
  end
410
417
  end
411
418
  end
@@ -420,7 +427,7 @@ module ActiveShipping
420
427
 
421
428
  xml = Nokogiri.XML(response)
422
429
 
423
- if error = xml.at('/Error')
430
+ if error = xml.at_xpath('/Error | //ServiceErrors/ServiceError')
424
431
  success = false
425
432
  message = error.at('Description').text
426
433
  else
@@ -642,6 +649,13 @@ module ActiveShipping
642
649
  response_status_node(document).text
643
650
  end
644
651
 
652
+ def find_country_code_case_insensitive(name)
653
+ upcase_name = name.upcase
654
+ country = ActiveUtils::Country::COUNTRIES.detect { |c| c[:name].upcase == upcase_name }
655
+ raise ActiveShipping::Error, "No country found for #{name}" unless country
656
+ country[:alpha2]
657
+ end
658
+
645
659
  def commit(action, request, test = false)
646
660
  ssl_get(request_url(action, request, test))
647
661
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveShipping
2
- VERSION = "1.2.1"
2
+ VERSION = "1.2.2"
3
3
  end
@@ -0,0 +1,53 @@
1
+ <?xml version="1.0"?>
2
+ <IntlRateV2Response>
3
+ <Package ID="0">
4
+ <!-- Other successful Services, Prohibitions, etc were here -->
5
+ <Service ID="15">
6
+ <Pounds>0</Pounds>
7
+ <Ounces>9</Ounces>
8
+ <MailType>Package</MailType>
9
+ <Container>RECTANGULAR</Container>
10
+ <Size>REGULAR</Size>
11
+ <Width>5.51</Width>
12
+ <Length>7.48</Length>
13
+ <Height>0.79</Height>
14
+ <Girth>12.60</Girth>
15
+ <Country>CANADA</Country>
16
+ <Postage>10.30</Postage>
17
+ <ExtraServices/>
18
+ <ValueOfContents>0.00</ValueOfContents>
19
+ <InsComment>SERVICE</InsComment>
20
+ <SvcCommitments>Varies by destination</SvcCommitments>
21
+ <SvcDescription>First-Class Package International Service&amp;lt;sup&amp;gt;&amp;#8482;&amp;lt;/sup&amp;gt;</SvcDescription>
22
+ <MaxDimensions>Other than rolls: Max. length 24", max length, height and depth (thickness) combined 36"&lt;br&gt;Rolls: Max. length 36". Max length and twice the diameter combined 42"</MaxDimensions>
23
+ <MaxWeight>4</MaxWeight>
24
+ </Service>
25
+ <Service ID="2">
26
+ <Pounds>0</Pounds>
27
+ <Ounces>9</Ounces>
28
+ <MailType>Package</MailType>
29
+ <Container>RECTANGULAR</Container>
30
+ <Size>REGULAR</Size>
31
+ <Width>5.51</Width>
32
+ <Length>7.48</Length>
33
+ <Height>0.79</Height>
34
+ <Girth>12.60</Girth>
35
+ <Country>CANADA</Country>
36
+ <Postage>0.00</Postage>
37
+ <ExtraServices>
38
+ <ExtraService>
39
+ <ServiceID/>
40
+ <ServiceName/>
41
+ <Available>False</Available>
42
+ <Price/>
43
+ </ExtraService>
44
+ </ExtraServices>
45
+ <ServiceErrors>
46
+ <ServiceError>
47
+ <Id>50050</Id>
48
+ <Description>This is a test response with the format of a real error.</Description>
49
+ </ServiceError>
50
+ </ServiceErrors>
51
+ </Service>
52
+ </Package>
53
+ </IntlRateV2Response>
@@ -31,7 +31,7 @@
31
31
  <Event>Out for Delivery, in truck</Event>
32
32
  <EventState>ON</EventState>
33
33
  <EventZIPCode>61536</EventZIPCode>
34
- <EventCountry>Canada</EventCountry>
34
+ <EventCountry>CANADA</EventCountry>
35
35
  <FirmName/>
36
36
  <Name/>
37
37
  <AuthorizedAgent>false</AuthorizedAgent>
@@ -7,7 +7,7 @@
7
7
  <ZipDestination>10017</ZipDestination>
8
8
  <Pounds>0</Pounds>
9
9
  <Ounces>8.8</Ounces>
10
- <Container>RECTANGULAR</Container>
10
+ <Container/>
11
11
  <Size>REGULAR</Size>
12
12
  <Width>5.51</Width>
13
13
  <Length>7.48</Length>
@@ -0,0 +1,18 @@
1
+ <?xml version="1.0"?>
2
+ <RateV4Request USERID="login">
3
+ <Package ID="0">
4
+ <Service>ALL</Service>
5
+ <FirstClassMailType/>
6
+ <ZipOrigination>90210</ZipOrigination>
7
+ <ZipDestination>10017</ZipDestination>
8
+ <Pounds>0</Pounds>
9
+ <Ounces>800.0</Ounces>
10
+ <Container>RECTANGULAR</Container>
11
+ <Size>LARGE</Size>
12
+ <Width>24.00</Width>
13
+ <Length>36.00</Length>
14
+ <Height>24.00</Height>
15
+ <Girth>96.00</Girth>
16
+ <Machinable>FALSE</Machinable>
17
+ </Package>
18
+ </RateV4Request>
@@ -0,0 +1,22 @@
1
+ <?xml version="1.0"?>
2
+ <IntlRateV2Request USERID="login">
3
+ <Revision>2</Revision>
4
+ <Package ID="0">
5
+ <Pounds>0</Pounds>
6
+ <Ounces>120</Ounces>
7
+ <MailType>Package</MailType>
8
+ <GXG>
9
+ <POBoxFlag>N</POBoxFlag>
10
+ <GiftFlag>N</GiftFlag>
11
+ </GXG>
12
+ <ValueOfContents>269.99</ValueOfContents>
13
+ <Country>Czech Republic</Country>
14
+ <Container>RECTANGULAR</Container>
15
+ <Size>LARGE</Size>
16
+ <Width>10.00</Width>
17
+ <Length>15.00</Length>
18
+ <Height>4.50</Height>
19
+ <Girth>29.00</Girth>
20
+ <OriginZip>90210</OriginZip>
21
+ </Package>
22
+ </IntlRateV2Request>
@@ -12,10 +12,11 @@ class RemoteUSPSTest < Minitest::Test
12
12
  end
13
13
 
14
14
  def test_tracking
15
- skip '<#<ActiveShipping::ResponseError: There is no record of that mail item. If it was mailed recently, it may not yet be tracked. Please try again later.>>.'
16
-
17
- @carrier.find_tracking_info('EJ958083578US', :test => true)
15
+ response = @carrier.find_tracking_info('LN284529912US', :test => true)
18
16
  assert response.success?, response.message
17
+ assert_equal 9,response.shipment_events.size
18
+ assert_equal 'DELIVERED', response.shipment_events.last.message
19
+ assert_equal Time.parse('2015-06-01 13:36:00 UTC'), response.actual_delivery_date
19
20
  end
20
21
 
21
22
  def test_tracking_with_bad_number
@@ -214,6 +214,7 @@ class USPSTest < Minitest::Test
214
214
 
215
215
  def test_build_us_rate_request_uses_proper_container
216
216
  expected_request = xml_fixture('usps/us_rate_request')
217
+ expected_request.gsub!('<Container/>','<Container>RECTANGULAR</Container>')
217
218
  @carrier.expects(:commit).with(:us_rates, expected_request, false).returns(expected_request)
218
219
  @carrier.expects(:parse_rate_response)
219
220
  package = package_fixtures[:book]
@@ -221,7 +222,7 @@ class USPSTest < Minitest::Test
221
222
  @carrier.find_rates(location_fixtures[:beverly_hills], location_fixtures[:new_york], package, :test => true, :container => :rectangular)
222
223
  end
223
224
 
224
- def test_build_us_rate_request_uses_proper_container_when_none_is_specified
225
+ def test_build_us_rate_request_uses_no_container_on_small_packages
225
226
  expected_request = xml_fixture('usps/us_rate_request')
226
227
  @carrier.expects(:commit).with(:us_rates, expected_request, false).returns(expected_request)
227
228
  @carrier.expects(:parse_rate_response)
@@ -229,6 +230,14 @@ class USPSTest < Minitest::Test
229
230
  @carrier.find_rates(location_fixtures[:beverly_hills], location_fixtures[:new_york], package, :test => true)
230
231
  end
231
232
 
233
+ def test_build_us_rate_request_uses_proper_container_when_none_is_specified
234
+ expected_request = xml_fixture('usps/us_rate_request_large')
235
+ @carrier.expects(:commit).with(:us_rates, expected_request, false).returns(expected_request)
236
+ @carrier.expects(:parse_rate_response)
237
+ package = package_fixtures[:big_half_pound]
238
+ @carrier.find_rates(location_fixtures[:beverly_hills], location_fixtures[:new_york], package, :test => true)
239
+ end
240
+
232
241
  def test_build_world_rate_request
233
242
  expected_request = xml_fixture('usps/world_rate_request_without_value')
234
243
  @carrier.expects(:commit).with(:world_rates, expected_request, false).returns(expected_request)
@@ -243,6 +252,13 @@ class USPSTest < Minitest::Test
243
252
  @carrier.find_rates(location_fixtures[:beverly_hills], location_fixtures[:ottawa], package_fixtures[:american_wii], :test => true, :acceptance_time => Time.parse("2015-06-01T20:34:29Z"))
244
253
  end
245
254
 
255
+ def test_build_world_rate_request_only_country
256
+ expected_request = xml_fixture('usps/world_rate_request_only_country')
257
+ @carrier.expects(:commit).with(:world_rates, expected_request, false).returns(expected_request)
258
+ @carrier.expects(:parse_rate_response)
259
+ @carrier.find_rates(location_fixtures[:beverly_hills], Location.new(:country => 'CZ'), package_fixtures[:american_wii], :test => true)
260
+ end
261
+
246
262
  def test_initialize_options_requirements
247
263
  assert_raises(ArgumentError) { USPS.new }
248
264
  assert USPS.new(:login => 'blah')
@@ -281,6 +297,21 @@ class USPSTest < Minitest::Test
281
297
  assert_equal ordered_service_names, response.rates.map(&:service_name).sort
282
298
  end
283
299
 
300
+ def test_parse_international_rate_response_errors
301
+ fixture_xml = xml_fixture('usps/api_error_rate_response')
302
+ @carrier.expects(:commit).returns(fixture_xml)
303
+
304
+ error = assert_raises(ResponseError) do
305
+ @carrier.find_rates(
306
+ location_fixtures[:beverly_hills], # imperial (U.S. origin)
307
+ location_fixtures[:ottawa],
308
+ package_fixtures[:american_wii],
309
+ :test => true
310
+ )
311
+ end
312
+ assert_equal 'This is a test response with the format of a real error.', error.message
313
+ end
314
+
284
315
  def test_parse_max_dimension_sentences
285
316
  limits = {
286
317
  "Max. length 46\", width 35\", height 46\" and max. length plus girth 108\"" =>
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.2.1
4
+ version: 1.2.2
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-06-02 00:00:00.000000000 Z
14
+ date: 2015-06-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: quantified
@@ -312,6 +312,7 @@ files:
312
312
  - test/fixtures/xml/ups/tracking_request.xml
313
313
  - test/fixtures/xml/ups/triple_accept_response.xml
314
314
  - test/fixtures/xml/ups/triple_confirm_response.xml
315
+ - test/fixtures/xml/usps/api_error_rate_response.xml
315
316
  - test/fixtures/xml/usps/beverly_hills_to_new_york_book_commercial_base_rate_response.xml
316
317
  - test/fixtures/xml/usps/beverly_hills_to_new_york_book_commercial_plus_rate_response.xml
317
318
  - test/fixtures/xml/usps/beverly_hills_to_new_york_book_rate_response.xml
@@ -331,6 +332,8 @@ files:
331
332
  - test/fixtures/xml/usps/tracking_response_not_available.xml
332
333
  - test/fixtures/xml/usps/tracking_response_test_error.xml
333
334
  - test/fixtures/xml/usps/us_rate_request.xml
335
+ - test/fixtures/xml/usps/us_rate_request_large.xml
336
+ - test/fixtures/xml/usps/world_rate_request_only_country.xml
334
337
  - test/fixtures/xml/usps/world_rate_request_with_value.xml
335
338
  - test/fixtures/xml/usps/world_rate_request_without_value.xml
336
339
  - test/remote/canada_post_pws_platform_test.rb
@@ -502,6 +505,7 @@ test_files:
502
505
  - test/fixtures/xml/ups/tracking_request.xml
503
506
  - test/fixtures/xml/ups/triple_accept_response.xml
504
507
  - test/fixtures/xml/ups/triple_confirm_response.xml
508
+ - test/fixtures/xml/usps/api_error_rate_response.xml
505
509
  - test/fixtures/xml/usps/beverly_hills_to_new_york_book_commercial_base_rate_response.xml
506
510
  - test/fixtures/xml/usps/beverly_hills_to_new_york_book_commercial_plus_rate_response.xml
507
511
  - test/fixtures/xml/usps/beverly_hills_to_new_york_book_rate_response.xml
@@ -521,6 +525,8 @@ test_files:
521
525
  - test/fixtures/xml/usps/tracking_response_not_available.xml
522
526
  - test/fixtures/xml/usps/tracking_response_test_error.xml
523
527
  - test/fixtures/xml/usps/us_rate_request.xml
528
+ - test/fixtures/xml/usps/us_rate_request_large.xml
529
+ - test/fixtures/xml/usps/world_rate_request_only_country.xml
524
530
  - test/fixtures/xml/usps/world_rate_request_with_value.xml
525
531
  - test/fixtures/xml/usps/world_rate_request_without_value.xml
526
532
  - test/remote/canada_post_pws_platform_test.rb