Class: FreightKit::ABFS

Inherits:
Carrier show all
Defined in:
lib/freight_kit/carriers/abfs.rb

Constant Summary collapse

REACTIVE_FREIGHT_CARRIER =
true
XML_HEADERS =
{
  'Accept' => 'application/xml',
  'charset' => 'utf-8',
  'Content-Type' => 'application/xml'
}.freeze

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

Class Attribute Summary collapse

Attributes inherited from Carrier

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

Class Method Summary collapse

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_tracking_info, #find_tracking_number_from_pickup_number, implemented?, #initialize, maximum_address_field_length, #overlength_fee, #pod, #scanned_bol, tracking_url_template, #valid_credentials?, valid_number_regex, #valid_tracking_number?

Constructor Details

This class inherits a constructor from FreightKit::Carrier

Class Attribute Details

.nameObject (readonly)

Returns the value of attribute name.



42
43
44
# File 'lib/freight_kit/carriers/abfs.rb', line 42

def name
  @name
end

.scacObject (readonly)

Returns the value of attribute scac.



42
43
44
# File 'lib/freight_kit/carriers/abfs.rb', line 42

def scac
  @scac
end

Class Method Details

.find_rates_with_declared_value?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/freight_kit/carriers/abfs.rb', line 6

def find_rates_with_declared_value?
  true
end

.maximum_heightObject



10
11
12
# File 'lib/freight_kit/carriers/abfs.rb', line 10

def maximum_height
  Measured::Length.new(105, :inches)
end

.maximum_weightObject



14
15
16
# File 'lib/freight_kit/carriers/abfs.rb', line 14

def maximum_weight
  Measured::Weight.new(150, :pounds)
end

.minimum_length_for_overlength_feesObject



18
19
20
# File 'lib/freight_kit/carriers/abfs.rb', line 18

def minimum_length_for_overlength_fees
  Measured::Length.new(6, :feet)
end

.overlength_fees_require_tariff?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/freight_kit/carriers/abfs.rb', line 22

def overlength_fees_require_tariff?
  false
end

.pickup_number_is_tracking_number?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/freight_kit/carriers/abfs.rb', line 26

def pickup_number_is_tracking_number?
  true
end

.required_credential_typesObject



30
31
32
# File 'lib/freight_kit/carriers/abfs.rb', line 30

def required_credential_types
  %i[api api_key]
end

.requirementsObject



34
35
36
# File 'lib/freight_kit/carriers/abfs.rb', line 34

def requirements
  %i[credentials]
end

Instance Method Details

#find_rates(shipment:) ⇒ Object

Rates



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/freight_kit/carriers/abfs.rb', line 85

def find_rates(shipment:)
  begin
    serviceable_accessorials?(shipment.accessorials)
    validate_packages(shipment.packages)
  rescue UnserviceableError => e
    return RateResponse.new(error: e)
  end

  request = build_rate_request(shipment:)
  # commit(request)
  parse_rate_response(shipment:, response: commit(request))
end

#serviceable_accessorials?(accessorials) ⇒ Boolean

Returns:

  • (Boolean)

Raises:



53
54
55
56
57
58
59
60
61
62
# File 'lib/freight_kit/carriers/abfs.rb', line 53

def serviceable_accessorials?(accessorials)
  unsupported_accessorials = conf.dig(:accessorials, :unserviceable).select do |key|
    accessorials.include?(key)
  end.sort!

  message = "#{unsupported_accessorials.join(", ")} unserviceable"
  raise FreightKit::UnserviceableError, message if unsupported_accessorials.any?

  true
end

#validate_packages(packages) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/freight_kit/carriers/abfs.rb', line 64

def validate_packages(packages)
  # @note This doesn't refer to package quantities, instead it referes to maximum number of package-related URL
  # query params
  raise FreightKit::UnserviceableError, 'Too many packages' if packages.count > 15

  unsupported_packaging_types = packages.map(&:packaging).map(&:type).select do |type|
    conf.dig(:package_types).keys.exclude?(type)
  end.sort!

  raise FreightKit::UnserviceableError,
        "#{unsupported_packaging_types.join(", ").upcase_first} unserviceable" if unsupported_packaging_types.any?

  true
end