Class: FriendlyShipping::Services::ShipEngine::RatesOptions

Inherits:
FriendlyShipping::ShipmentOptions show all
Defined in:
lib/friendly_shipping/services/ship_engine/rates_options.rb

Overview

Options for the rates API call.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from FriendlyShipping::ShipmentOptions

#options_for_package

Constructor Details

#initialize(carriers:, service_code:, ship_date: Date.today, comparison_rate_type: nil, **kwargs) ⇒ RatesOptions

Returns a new instance of RatesOptions.

Parameters:

  • carriers (Array<Carrier>)

    the carriers for these rates

  • service_code (String)

    the service code to use when getting rates

  • ship_date (#strftime) (defaults to: Date.today)

    the date we want to ship on

  • comparison_rate_type (String) (defaults to: nil)

    set to "retail" for retail rates (UPS/USPS only)

  • kwargs (Hash)

Options Hash (**kwargs):

  • :package_options (Array<PackageOptions>)

    the options for packages in this shipment

  • :package_options_class (Class)

    the class to use for package options when none are provided



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/friendly_shipping/services/ship_engine/rates_options.rb', line 27

def initialize(
  carriers:,
  service_code:,
  ship_date: Date.today,
  comparison_rate_type: nil,
  **kwargs
)
  @carriers = carriers
  @service_code = service_code
  @ship_date = ship_date
  @comparison_rate_type = comparison_rate_type
  validate_comparison_rate_type!
  super(**kwargs.reverse_merge(package_options_class: RatesPackageOptions))
end

Instance Attribute Details

#carriersArray<Carrier> (readonly)

Returns the carriers from which to get rates.

Returns:

  • (Array<Carrier>)

    the carriers from which to get rates



9
10
11
# File 'lib/friendly_shipping/services/ship_engine/rates_options.rb', line 9

def carriers
  @carriers
end

#comparison_rate_typeString (readonly)

Returns:

  • (String)


18
19
20
# File 'lib/friendly_shipping/services/ship_engine/rates_options.rb', line 18

def comparison_rate_type
  @comparison_rate_type
end

#service_codeString (readonly)

Returns the service code for which to get rates.

Returns:

  • (String)

    the service code for which to get rates



12
13
14
# File 'lib/friendly_shipping/services/ship_engine/rates_options.rb', line 12

def service_code
  @service_code
end

#ship_date#strftime (readonly)

Returns:

  • (#strftime)


15
16
17
# File 'lib/friendly_shipping/services/ship_engine/rates_options.rb', line 15

def ship_date
  @ship_date
end

Instance Method Details

#carrier_idsArray<String>

Returns the carrier IDs for these rates.

Returns:

  • (Array<String>)

    the carrier IDs for these rates



43
44
45
# File 'lib/friendly_shipping/services/ship_engine/rates_options.rb', line 43

def carrier_ids
  carriers.map(&:id)
end