class FriendlyShipping::Services::ShipEngine::SerializeRateEstimateRequest

Public Class Methods

call(shipment:, options:) click to toggle source
# File lib/friendly_shipping/services/ship_engine/serialize_rate_estimate_request.rb, line 7
def self.call(shipment:, options:)
  {
    carrier_ids: options.carrier_ids,
    from_country_code: shipment.origin.country.alpha_2_code,
    from_postal_code: shipment.origin.zip,
    to_country_code: shipment.destination.country.alpha_2_code,
    to_postal_code: shipment.destination.zip,
    to_city_locality: shipment.destination.city,
    to_state_province: shipment.destination.region.code,
    weight: {
      value: shipment.packages.map { |p| p.weight.convert_to(:pound).value.to_f }.sum,
      unit: 'pound'
    },
    confirmation: 'none',
    address_residential_indicator: shipment.destination.residential? ? "yes" : "no"
  }
end