Class: FreightKit::TOTL
- Inherits:
-
CarrierLogistics
- Object
- Carrier
- Platform
- CarrierLogistics
- FreightKit::TOTL
- Defined in:
- lib/freight_kit/carriers/totl.rb
Constant Summary collapse
- REACTIVE_FREIGHT_CARRIER =
true
Constants inherited from CarrierLogistics
CarrierLogistics::EXPIRED_CREDENTIALS_MESSAGES, CarrierLogistics::INVALID_CREDENTIALS_MESSAGES, CarrierLogistics::REACTIVE_FREIGHT_PLATFORM
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
-
.name ⇒ Object
readonly
Returns the value of attribute name.
-
.scac ⇒ Object
readonly
Returns the value of attribute scac.
Attributes inherited from Carrier
#conf, #credentials, #customer_location, #last_request, #rates_with_excessive_length_fees, #tariff, #tmpdir
Class Method Summary collapse
- .maximum_height ⇒ Object
- .maximum_weight ⇒ Object
- .minimum_length_for_overlength_fees ⇒ Object
- .overlength_fees_require_tariff? ⇒ Boolean
- .pickup_number_is_tracking_number? ⇒ Boolean
- .required_credential_types ⇒ Object
- .requirements ⇒ Object
Instance Method Summary collapse
Methods inherited from CarrierLogistics
#build_calculated_accessorials, #build_rate_request, #build_tracking_request, #build_url, #commit, #map_response_errors, #parse_amount, #parse_api_city_state, #parse_api_city_state_zip, #parse_api_date, #parse_api_date_time, #parse_document_response, #parse_tracking_response, #pod, #ratequote_line_description, #scanned_bol
Methods included from Rateable
Methods included from Trackable
Methods inherited from Platform
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?, #initialize, maximum_address_field_length, #overlength_fee, #pod, #scanned_bol, #serviceable_accessorials?, tracking_url_template, #valid_credentials?, valid_number_regex, #valid_tracking_number?, #validate_packages
Constructor Details
This class inherits a constructor from FreightKit::Platform
Class Attribute Details
.name ⇒ Object (readonly)
Returns the value of attribute name.
38 39 40 |
# File 'lib/freight_kit/carriers/totl.rb', line 38 def name @name end |
.scac ⇒ Object (readonly)
Returns the value of attribute scac.
38 39 40 |
# File 'lib/freight_kit/carriers/totl.rb', line 38 def scac @scac end |
Class Method Details
.maximum_height ⇒ Object
6 7 8 |
# File 'lib/freight_kit/carriers/totl.rb', line 6 def maximum_height Measured::Length.new(105, :inches) end |
.maximum_weight ⇒ Object
10 11 12 |
# File 'lib/freight_kit/carriers/totl.rb', line 10 def maximum_weight Measured::Weight.new(10_000, :pounds) end |
.minimum_length_for_overlength_fees ⇒ Object
14 15 16 |
# File 'lib/freight_kit/carriers/totl.rb', line 14 def minimum_length_for_overlength_fees Measured::Length.new(40, :inches) end |
.overlength_fees_require_tariff? ⇒ Boolean
18 19 20 |
# File 'lib/freight_kit/carriers/totl.rb', line 18 def overlength_fees_require_tariff? false end |
.pickup_number_is_tracking_number? ⇒ Boolean
22 23 24 |
# File 'lib/freight_kit/carriers/totl.rb', line 22 def pickup_number_is_tracking_number? true end |
.required_credential_types ⇒ Object
26 27 28 |
# File 'lib/freight_kit/carriers/totl.rb', line 26 def required_credential_types %i[api] end |
.requirements ⇒ Object
30 31 32 |
# File 'lib/freight_kit/carriers/totl.rb', line 30 def requirements %i[credentials] end |
Instance Method Details
#parse_rate_response(shipment:, response:) ⇒ Object
Rates
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/freight_kit/carriers/totl.rb', line 57 def parse_rate_response(shipment:, response:) rate_response = RateResponse.new(request: last_request, response:) if response.blank? rate_response.error = ResponseError.new('Unknown response') return rate_response end if response.is_a?(String) && response.include?('WebSpeed error') rate_response.error = ResponseError.new('API Error: Temporary error (CarrierLogistics WebSpeed error)') return rate_response end error = response.dig('error', 'errormessage') if error.present? if error.downcase.include?('invalid username/password') rate_response.error = InvalidCredentialsError.new return rate_response end if error.downcase.include?('is not available') || error.downcase.include?('out of the serviceable area') rate_response.error = UnserviceableError.new return rate_response end rate_response.error = ResponseError.new("API Error: #{error}") return rate_response end if response.dig('ratequote', 'quotetotal').blank? rate_response.error = ResponseError.new('Cost is blank') return rate_response end total_cents = parse_amount(response.dig('ratequote', 'quotetotal')) transit_days = response.dig('ratequote', 'busdays').to_i estimate_reference = response.dig('ratequote', 'quotenumber') ratequote_lines = response.dig('ratequote', 'ratequoteline') prices = [] ratequote_lines.each do |ratequote_line| next if ratequote_line['chrg'].blank? next if ratequote_line['chargedesc'] == 'FREIGHT' cents = parse_amount(ratequote_line['chrg']) next if cents.zero? prices << Price.new( blame: :api, cents:, description: ratequote_line_description(ratequote_line), ) end prices = [ Price.new( blame: :api, cents: total_cents - prices.sum(&:cents), description: 'Freight', ), ] + prices # Carrier-specific pricing structure oversized_pallets_cents = 0 shipment.packages.each do |package| short_side, long_side = nil if package.length(:in).present? && package.width(:in).present? && package.height(:in).present? long_side = [package.length(:in), package.width(:in)].max short_side = [package.length(:in), package.width(:in)].min end next unless short_side && long_side && package.height(:in) && ( short_side > 40 || long_side > 48 || package.height(:in) > 84 ) oversized_pallets_cents += 1500 end if oversized_pallets_cents.nonzero? prices << Price.new( blame: :library, cents: oversized_pallets_cents, description: 'Overlength fees', ) end RateResponse.new( rates: [ Rate.new( carrier: self, carrier_name: self.class.name, currency: 'USD', estimate_reference:, scac: self.class.scac.upcase, service_name: :standard, shipment:, prices:, transit_days:, with_excessive_length_fees: @conf.dig(:attributes, :rates, :with_excessive_length_fees), ), ], request: last_request, response:, ) end |