friendly_shipping 0.4.8 → 0.4.9

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
  SHA256:
3
- metadata.gz: 040c918f1349ab0ca0eac9a810082c9b5e751f78ce3f8ccc60af7f5dcc7f81b2
4
- data.tar.gz: '07479b91f4e7ad7bf983eec39da3b286d4959117f95f7e9caa062d95d2883785'
3
+ metadata.gz: c7315eaa32f0429125e0c992d06d2093d324416e0bf36ac79bb5e2a0d1fc7135
4
+ data.tar.gz: e7a15a667a37321ff006da9c5f2d3478bf9f3089a35ae84db4227a775178438c
5
5
  SHA512:
6
- metadata.gz: 15b651d1056fee2933438df10c36fcae9c85deacaf0807e9745b8ccdcc04aa07be53f05e5d6f0737402d0c94591b267546b3878d2bbd8c27ccd499737745cd25
7
- data.tar.gz: 0e683464058b2bf4881d4f9b10b3c887bf39d45b13f19fca170b40d3074573130b7e238422aefe27710c74fc7802633f30361f2ebbac73899b8424e6f64caad6
6
+ metadata.gz: f460abf860b45f6079d364a770f1035778ecc0c5d98dcf5409c5a9f4b244326d954dad6ee3d881927470dbcde089114e767fed5a1e884d56133c419af77e9e8d
7
+ data.tar.gz: b0e92858e9922f8f85b1f93d22d9b5cc13c5af55f864acc6d6e30caddae110b6a65f73c840b12129c1bd34ba65f67f195dcbf0bc756ead50dbd429cc8e184871
@@ -156,7 +156,7 @@ Metrics/ModuleLength:
156
156
  Metrics/CyclomaticComplexity:
157
157
  Enabled: false
158
158
 
159
- Layout/LineLength:
159
+ Metrics/LineLength:
160
160
  Enabled: false
161
161
 
162
162
  Metrics/MethodLength:
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.4.9] - 2020-01-09
8
+
9
+ ### Changed
10
+ - USPS Service: Add missing Commitment sequence (#68)
11
+ - Code quality: Add double splats for Ruby 2.7 compatibility (#67)
12
+ - UPS Service: Add more package-level detail to rate responses (#65)
13
+
7
14
  ## [0.4.8] - 2020-01-06
8
15
 
9
16
  ### Changed
@@ -26,7 +26,7 @@ module FriendlyShipping
26
26
  @shipping_method = shipping_method
27
27
  @label_format = label_format
28
28
  @label_download_type = label_download_type
29
- super kwargs.merge(package_options_class: LabelPackageOptions)
29
+ super(**kwargs.merge(package_options_class: LabelPackageOptions))
30
30
  end
31
31
  end
32
32
  end
@@ -20,7 +20,7 @@ module FriendlyShipping
20
20
  def initialize(package_code: nil, messages: [], **kwargs)
21
21
  @package_code = package_code
22
22
  @messages = messages
23
- super kwargs
23
+ super(**kwargs)
24
24
  end
25
25
  end
26
26
  end
@@ -13,7 +13,7 @@ module FriendlyShipping
13
13
 
14
14
  def initialize(carriers:, **kwargs)
15
15
  @carriers = carriers
16
- super kwargs
16
+ super(**kwargs)
17
17
  end
18
18
 
19
19
  def carrier_ids
@@ -58,7 +58,7 @@ module FriendlyShipping
58
58
  )
59
59
  @commodity_code = commodity_code
60
60
  @product_unit_of_measure = product_unit_of_measure
61
- super kwargs
61
+ super(**kwargs)
62
62
  end
63
63
 
64
64
  def product_unit_of_measure_code
@@ -139,7 +139,7 @@ module FriendlyShipping
139
139
  @terms_of_shipment = terms_of_shipment
140
140
  @reason_for_export = reason_for_export
141
141
  @invoice_date = invoice_date
142
- super kwargs.merge(package_options_class: package_options_class)
142
+ super(**kwargs.merge(package_options_class: package_options_class))
143
143
  end
144
144
 
145
145
  def delivery_confirmation_code
@@ -31,7 +31,7 @@ module FriendlyShipping
31
31
  @reference_numbers = reference_numbers
32
32
  @delivery_confirmation = delivery_confirmation
33
33
  @shipper_release = shipper_release
34
- super kwargs.merge(item_options_class: LabelItemOptions)
34
+ super(**kwargs.merge(item_options_class: LabelItemOptions))
35
35
  end
36
36
 
37
37
  def delivery_confirmation_code
@@ -7,50 +7,72 @@ module FriendlyShipping
7
7
  module Services
8
8
  class Ups
9
9
  class ParseRateResponse
10
- def self.call(request:, response:, shipment:)
11
- parsing_result = ParseXMLResponse.call(response.body, 'RatingServiceSelectionResponse')
12
- parsing_result.fmap do |xml|
13
- FriendlyShipping::ApiResult.new(
14
- build_rates(xml, shipment),
15
- original_request: request,
16
- original_response: response
17
- )
10
+ class << self
11
+ def call(request:, response:, shipment:)
12
+ parsing_result = ParseXMLResponse.call(response.body, 'RatingServiceSelectionResponse')
13
+ parsing_result.fmap do |xml|
14
+ FriendlyShipping::ApiResult.new(
15
+ build_rates(xml, shipment),
16
+ original_request: request,
17
+ original_response: response
18
+ )
19
+ end
18
20
  end
19
- end
20
21
 
21
- def self.build_rates(xml, shipment)
22
- xml.root.css('> RatedShipment').map do |rated_shipment|
23
- service_code = rated_shipment.at('Service/Code').text
24
- shipping_method = CARRIER.shipping_methods.detect do |sm|
25
- sm.service_code == service_code && shipment.origin.country.in?(sm.origin_countries)
26
- end
27
- days_to_delivery = rated_shipment.at('GuaranteedDaysToDelivery').text.to_i
28
-
29
- total = ParseMoneyElement.call(rated_shipment.at('TotalCharges')).last
30
- insurance_price = ParseMoneyElement.call(rated_shipment.at('ServiceOptionsCharges'))&.last
31
- negotiated_rate = ParseMoneyElement.call(
32
- rated_shipment.at('NegotiatedRates/NetSummaryCharges/GrandTotal')
33
- )&.last
34
-
35
- rated_shipment_warnings = rated_shipment.css('RatedShipmentWarning').map { |e| e.text.strip }
36
- if rated_shipment_warnings.any? { |e| e.match?(/to Residential/) }
37
- new_address_type = 'residential'
38
- elsif rated_shipment_warnings.any? { |e| e.match?(/to Commercial/) }
39
- new_address_type = 'commercial'
22
+ def build_rates(xml, shipment)
23
+ xml.root.css('> RatedShipment').map do |rated_shipment|
24
+ service_code = rated_shipment.at('Service/Code').text
25
+ shipping_method = CARRIER.shipping_methods.detect do |sm|
26
+ sm.service_code == service_code && shipment.origin.country.in?(sm.origin_countries)
27
+ end
28
+ days_to_delivery = rated_shipment.at('GuaranteedDaysToDelivery').text.to_i
29
+
30
+ total = ParseMoneyElement.call(rated_shipment.at('TotalCharges')).last
31
+ insurance_price = ParseMoneyElement.call(rated_shipment.at('ServiceOptionsCharges'))&.last
32
+ negotiated_rate = ParseMoneyElement.call(
33
+ rated_shipment.at('NegotiatedRates/NetSummaryCharges/GrandTotal')
34
+ )&.last
35
+
36
+ rated_shipment_warnings = rated_shipment.css('RatedShipmentWarning').map { |e| e.text.strip }
37
+ if rated_shipment_warnings.any? { |e| e.match?(/to Residential/) }
38
+ new_address_type = 'residential'
39
+ elsif rated_shipment_warnings.any? { |e| e.match?(/to Commercial/) }
40
+ new_address_type = 'commercial'
41
+ end
42
+
43
+ FriendlyShipping::Rate.new(
44
+ shipping_method: shipping_method,
45
+ amounts: { total: total },
46
+ warnings: rated_shipment_warnings,
47
+ errors: [],
48
+ data: {
49
+ insurance_price: insurance_price,
50
+ negotiated_rate: negotiated_rate,
51
+ days_to_delivery: days_to_delivery,
52
+ new_address_type: new_address_type,
53
+ packages: build_packages(rated_shipment)
54
+ }.compact
55
+ )
40
56
  end
57
+ end
41
58
 
42
- FriendlyShipping::Rate.new(
43
- shipping_method: shipping_method,
44
- amounts: { total: total },
45
- warnings: rated_shipment_warnings,
46
- errors: [],
47
- data: {
48
- insurance_price: insurance_price,
49
- negotiated_rate: negotiated_rate,
50
- days_to_delivery: days_to_delivery,
51
- new_address_type: new_address_type
59
+ private
60
+
61
+ def build_packages(rated_shipment)
62
+ rated_shipment.css('RatedPackage').map do |rated_package|
63
+ itemized_charges = rated_package.xpath('ItemizedCharges').map do |element|
64
+ ParseMoneyElement.call(element)
65
+ end.compact.to_h
66
+ {
67
+ transportation_charges: ParseMoneyElement.call(rated_package.at('TransportationCharges')).last,
68
+ base_service_charge: ParseMoneyElement.call(rated_package.at('BaseServiceCharge')).last,
69
+ service_options_charges: ParseMoneyElement.call(rated_package.at('ServiceOptionsCharges'))&.last,
70
+ itemized_charges: itemized_charges,
71
+ total_charges: ParseMoneyElement.call(rated_package.at('TotalCharges')).last,
72
+ weight: BigDecimal(rated_package.at('Weight').text),
73
+ billing_weight: BigDecimal(rated_package.at('BillingWeight/Weight').text)
52
74
  }.compact
53
- )
75
+ end
54
76
  end
55
77
  end
56
78
  end
@@ -64,7 +64,7 @@ module FriendlyShipping
64
64
  @packaging_description = PACKAGING_TYPES.fetch(packaging).fetch(:description)
65
65
  @freight_class = freight_class
66
66
  @nmfc_code = nmfc_code
67
- super kwargs
67
+ super(**kwargs)
68
68
  end
69
69
  end
70
70
  end
@@ -54,7 +54,7 @@ module FriendlyShipping
54
54
  @pickup_date = pickup_date
55
55
  @pickup_comments = pickup_comments
56
56
  @commodity_information_generator = commodity_information_generator
57
- super kwargs.merge(package_options_class: RatesPackageOptions)
57
+ super(**kwargs.merge(package_options_class: RatesPackageOptions))
58
58
  end
59
59
  end
60
60
  end
@@ -30,7 +30,7 @@ module FriendlyShipping
30
30
  @handling_unit_code = HANDLING_UNIT_TYPES.fetch(handling_unit).fetch(:code)
31
31
  @handling_unit_description = HANDLING_UNIT_TYPES.fetch(handling_unit).fetch(:description)
32
32
  @handling_unit_tag = "HandlingUnit#{HANDLING_UNIT_TYPES.fetch(handling_unit).fetch(:handling_unit_tag)}"
33
- super kwargs.merge(item_options_class: RatesItemOptions)
33
+ super(**kwargs.merge(item_options_class: RatesItemOptions))
34
34
  end
35
35
  end
36
36
  end
@@ -168,6 +168,11 @@ module FriendlyShipping
168
168
  commitment_time: '10:30 AM',
169
169
  destination_type: :hold_for_pickup
170
170
  },
171
+ 'B0215' => {
172
+ commitment: '2-Day',
173
+ commitment_time: '3:00 PM',
174
+ destination_type: :hold_for_pickup
175
+ },
171
176
  'C0100' => {
172
177
  commitment: '1-Day',
173
178
  destination_type: :street
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FriendlyShipping
4
- VERSION = "0.4.8"
4
+ VERSION = "0.4.9"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: friendly_shipping
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.4.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Meyerhoff
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-06 00:00:00.000000000 Z
11
+ date: 2020-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: data_uri