Sha256: ea5deec63266c13edf33285fa1424cefae687d8c8756601c04ee004daa6910f3

Contents?: true

Size: 1.97 KB

Versions: 1

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

require 'friendly_shipping/services/ups_json/label_item_options'

module FriendlyShipping
  module Services
    class UpsJson
      # Package properties relevant for generating a UPS shipping label
      #
      # @option reference_numbers [Hash] a Hash where keys are _reference number codes_ and
      #   values are _reference number values_. Example: `{ reference_numbers: { xn: 'my_reference_1 }`
      # @option delivery_confirmation [Symbol] Can be set to any key from PACKAGE_DELIVERY_CONFIRMATION_CODES.
      #   Only possible for domestic shipments or shipments between the US and Puerto Rico.
      # @option shipper_release [Boolean] Indicates that the package may be released by driver without a signature from
      #   the consignee. Default: false
      # @option declared_value [Boolean] When true, declared value (calculated as the sum of all items in the shipment)
      #   will be included in the request. Default: false
      class LabelPackageOptions < FriendlyShipping::PackageOptions
        PACKAGE_DELIVERY_CONFIRMATION_CODES = {
          delivery_confirmation: 1,
          delivery_confirmation_signature_required: 2,
          delivery_confirmation_adult_signature_required: 3
        }.freeze

        attr_reader :reference_numbers, :shipper_release, :declared_value

        def initialize(
          reference_numbers: {},
          delivery_confirmation: nil,
          shipper_release: false,
          declared_value: false,
          **kwargs
        )
          @reference_numbers = reference_numbers
          @delivery_confirmation = delivery_confirmation
          @shipper_release = shipper_release
          @declared_value = declared_value
          super(**kwargs.reverse_merge(item_options_class: LabelItemOptions))
        end

        def delivery_confirmation_code
          PACKAGE_DELIVERY_CONFIRMATION_CODES[delivery_confirmation]
        end

        private

        attr_reader :delivery_confirmation
      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/ups_json/label_package_options.rb