Class: FriendlyShipping::Services::RL::RateQuotePackagesSerializer

Inherits:
Object
  • Object
show all
Defined in:
lib/friendly_shipping/services/rl/rate_quote_packages_serializer.rb

Overview

Serializes packages for R+L rate quote API requests.

Class Method Summary collapse

Class Method Details

.call(packages:, options:) ⇒ Array<Hash>

Returns serialized packages.

Parameters:

  • packages (Array<Physical::Package>)

    packages to serialize

  • options (RateQuoteOptions)

    options for this request

Returns:

  • (Array<Hash>)

    serialized packages



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/friendly_shipping/services/rl/rate_quote_packages_serializer.rb', line 12

def call(packages:, options:)
  item_hashes = packages.flat_map do |package|
    package_options = options.options_for_package(package)
    package.items.map do |item|
      item_options = package_options.options_for_item(item)
      {
        Class: item_options.freight_class,
        Height: item.height.convert_to(:inches),
        Length: item.length.convert_to(:inches),
        Weight: item.weight.convert_to(:pounds),
        Width: item.width.convert_to(:inches)
      }
    end
  end
  group_items(item_hashes)
end