Class: FreightKit::Platform

Inherits:
Carrier
  • Object
show all
Defined in:
lib/freight_kit/platform.rb

Constant Summary

Constants inherited from Carrier

Carrier::BOL_NUMBER_TRACKING_URL_TEMPLATE, Carrier::NUMBERS, Carrier::ORDER_NUMBER_TRACKING_URL_TEMPLATE, Carrier::PICKUP_NUMBER_TRACKING_URL_TEMPLATE, Carrier::PO_NUMBER_TRACKING_URL_TEMPLATE, Carrier::TRACKING_NUMBER_TRACKING_URL_TEMPLATE, Carrier::VALID_BOL_NUMBER_REGEX, Carrier::VALID_ORDER_NUMBER_REGEX, Carrier::VALID_PICKUP_NUMBER_REGEX, Carrier::VALID_PO_NUMBER_REGEX, Carrier::VALID_TRACKING_NUMBER_REGEX

Instance Attribute Summary

Attributes inherited from Carrier

#conf, #credentials, #customer_location, #last_request, #rates_with_excessive_length_fees, #tariff, #tmpdir

Instance Method Summary collapse

Methods inherited from Carrier

#available_services, #bol, bol_requires_tracking_number?, #cancel_shipment, #create_pickup, default_location, #fetch_credential, #find_estimate, #find_locations, #find_rates, find_rates_with_declared_value?, #find_tracking_info, #find_tracking_number_from_pickup_number, implemented?, maximum_address_field_length, maximum_height, maximum_weight, minimum_length_for_overlength_fees, #overlength_fee, overlength_fees_require_tariff?, pickup_number_is_tracking_number?, #pod, required_credential_types, requirements, #scanned_bol, #serviceable_accessorials?, tracking_url_template, #valid_credentials?, valid_number_regex, #valid_tracking_number?, #validate_packages

Constructor Details

#initialize(credentials, customer_location: nil, tariff: nil) ⇒ Platform

Credentials should be a ‘Credential` or `Array` of `Credential`



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/freight_kit/platform.rb', line 6

def initialize(credentials, customer_location: nil, tariff: nil)
  super

  # Use #superclass instead of using #ancestors to fetch the parent class which the carrier class is inheriting from
  # (#ancestors returns an array including the parent class and all the modules that were included)
  parent_class_name = self.class.superclass.name.demodulize.underscore

  conf_path = File
              .join(
                File.expand_path(
                  '../../../../configuration/platforms',
                  self.class.const_source_location(:REACTIVE_FREIGHT_PLATFORM).first,
                ),
                "#{parent_class_name}.yml",
              )
  @conf = YAML.safe_load_file(conf_path, permitted_classes: [Symbol])

  conf_path = File
              .join(
                File.expand_path(
                  '../../../../configuration/carriers',
                  self.class.const_source_location(:REACTIVE_FREIGHT_CARRIER).first,
                ),
                "#{self.class.to_s.demodulize.underscore}.yml",
              )
  @conf = @conf.deep_merge(YAML.safe_load_file(conf_path, permitted_classes: [Symbol]))

  @rates_with_excessive_length_fees = @conf.dig(:attributes, :rates, :with_excessive_length_fees)
end