Sha256: 8bc6ba4cee48e6caa97332d154145c2c657a68db335df3c22bb353f1606e3ef6

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

# frozen_string_literal: true

module FriendlyShipping
  module Services
    class RL
      # Serializes an R+L API request to get a shipment transit timing estimate.
      class SerializeTransitTimesRequest
        class << self
          # @param shipment [Physical::Shipment] the shipment for the request
          # @param options [RateQuoteOptions] options for the request
          # @return [Hash] the serialized request
          def call(shipment:, options:)
            {
              PickupDate: options.pickup_date.strftime('%m/%d/%Y'),
              Origin: serialize_location(shipment.origin),
              Destinations: [
                serialize_location(shipment.destination)
              ]
            }.compact
          end

          private

          # @param location [Physical::Location] the location to serialize
          # @return [Hash] the serialized location
          def serialize_location(location)
            {
              City: location.city,
              StateOrProvince: location.region.code,
              ZipOrPostalCode: location.zip,
              CountryCode: location.country.alpha_3_code
            }.compact
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
friendly_shipping-0.9.0 lib/friendly_shipping/services/rl/serialize_transit_times_request.rb