Class: FriendlyShipping::Services::ShipEngine::SerializeRatesRequest

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly_shipping/services/ship_engine/serialize_rates_request.rb

Overview

Serializes a shipment and options for the rates API request.

Class Method Summary collapse

Class Method Details

.call(shipment:, options:) ⇒ Hash

Returns the serialized request.

Parameters:

  • shipment (Physical::Shipment)

    the shipment to serialize

  • options (LabelOptions)

    the options to serialize

Returns:

  • (Hash)

    the serialized request



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/friendly_shipping/services/ship_engine/serialize_rates_request.rb', line 12

def call(shipment:, options:)
  rates_hash = {
    shipment: {
      carrier_ids: options.carrier_ids,
      service_code: options.service_code,
      ship_date: options.ship_date.strftime('%Y-%m-%d'),
      ship_to: serialize_address(shipment.destination),
      ship_from: serialize_address(shipment.origin),
      items: serialize_items(shipment.packages.first),
      packages: serialize_packages(shipment, options),
      comparison_rate_type: options.comparison_rate_type,
      confirmation: 'none'
    }.merge(SerializeAddressResidentialIndicator.call(shipment.destination)).compact_blank,
    rate_options: {
      carrier_ids: options.carrier_ids,
      service_codes: [options.service_code],
    }
  }

  if international?(shipment)
    rates_hash[:shipment][:customs] = {
      contents: "merchandise",
      non_delivery: "return_to_sender",
    }
  end

  rates_hash
end