Class: FriendlyShipping::Services::USPSShip::SerializeRateEstimatesRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly_shipping/services/usps_ship/serialize_rate_estimates_request.rb

Class Method Summary collapse

Class Method Details

.call(shipment:, package:, options:) ⇒ Hash

Serialize a rate estimates request.

Parameters:

Returns:

  • (Hash)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/friendly_shipping/services/usps_ship/serialize_rate_estimates_request.rb', line 14

def call(shipment:, package:, options:)
  length, width, height = package.dimensions.sort.reverse
  package_options = options.options_for_package(package)
  {
    originZIPCode: shipment.origin.zip,
    destinationZIPCode: shipment.destination.zip,
    weight: package.weight.convert_to(:lbs).value.to_f.round(2),
    length: length.convert_to(:in).value.to_f.round(2),
    width: width.convert_to(:in).value.to_f.round(2),
    height: height.convert_to(:in).value.to_f.round(2),
    mailClass: options.shipping_method.service_code,
    processingCategory: processing_category(package, package_options),
    rateIndicator: package_options.rate_indicator,
    destinationEntryFacilityType: options.destination_entry_facility_type,
    priceType: package_options.price_type,
    mailingDate: options.mailing_date.strftime("%Y-%m-%d")
  }
end