Module: FreightKit::Rateable

Included in:
CCYQ, CLNI, CarrierLogistics, DPHE, FWDA, PENS, RDFS, SAIA, TQYL, TheGreatInformationFactory
Defined in:
lib/freight_kit/helpers/rateable.rb

Instance Method Summary collapse

Instance Method Details

#find_rates(shipment:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/freight_kit/helpers/rateable.rb', line 5

def find_rates(shipment:)
  begin
    validate_packages(shipment.packages, @tariff)
  rescue UnserviceableError => e
    return RateResponse.new(error: e)
  end

  request = build_rate_request(shipment:)

  # For SOAP APIs, the :action parameter is required
  response = commit(:rates, request) if method(:commit).parameters.count == 2
  response ||= commit(request)

  return response if response.is_a?(RateResponse)

  parse_rate_response(shipment:, response:)
rescue FreightKit::InvalidCredentialsError => e
  rate_response = RateResponse.new(request:, response:)
  rate_response.error = e

  rate_response
end