freight_kit 0.1.33 → 0.1.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +21 -20
- data/VERSION +1 -1
- data/lib/freight_kit/carrier.rb +84 -5
- data/lib/freight_kit/carriers/best_overnite_express.rb +1 -0
- data/lib/freight_kit/carriers/cross_country_freight_solutions.rb +64 -8
- data/lib/freight_kit/carriers/forward_air.rb +0 -1
- data/lib/freight_kit/carriers/numark_transportation.rb +4 -1
- data/lib/freight_kit/carriers/saia.rb +67 -27
- data/lib/freight_kit/carriers/southeastern_freight_lines.rb +57 -2
- data/lib/freight_kit/carriers/stg.rb +73 -5
- data/lib/freight_kit/carriers/t_force_worldwide.rb +48 -4
- data/lib/freight_kit/carriers/western_regional_delivery_service.rb +35 -1
- data/lib/freight_kit/carriers/xpo_logistics.rb +67 -6
- data/lib/freight_kit/errors/ambiguous_shipment_error.rb +3 -0
- data/lib/freight_kit/helpers/rateable.rb +15 -3
- data/lib/freight_kit/models/search_response.rb +12 -0
- data/lib/freight_kit/models/search_result.rb +121 -0
- data/lib/freight_kit/platforms/carrier_logistics.rb +0 -8
- data/lib/freight_kit/platforms/next_tms.rb +37 -6
- data/lib/freight_kit/platforms/road_vision.rb +31 -8
- data/lib/freight_kit/platforms/the_great_information_factory.rb +1 -10
- metadata +4 -1
|
@@ -45,8 +45,8 @@ module FreightKit
|
|
|
45
45
|
JSON_HEADERS = { Accept: 'application/json', 'Content-Type': 'application/json' }.freeze
|
|
46
46
|
# The `ErrorInfo` of `FetchInvoiceListByPro` for shipments that are not invoiced yet
|
|
47
47
|
NO_INVOICES_MESSAGE = /no corresponding invoices/i
|
|
48
|
-
#
|
|
49
|
-
|
|
48
|
+
# `SearchType`s, by the number that `SearchFor` holds
|
|
49
|
+
SEARCH_TYPES = { bol: 2, carrier_pro: 5, po: 3, pro: 1, sid: 4 }.freeze
|
|
50
50
|
# Response keys that `String#underscore` misses
|
|
51
51
|
UNDERSCORED_KEYS = {
|
|
52
52
|
'BOLnumber' => :bol_number,
|
|
@@ -160,7 +160,7 @@ module FreightKit
|
|
|
160
160
|
}
|
|
161
161
|
end
|
|
162
162
|
|
|
163
|
-
def build_tracking_request(tracking_number) = { search_for: tracking_number, search_type:
|
|
163
|
+
def build_tracking_request(tracking_number) = { search_for: tracking_number, search_type: SEARCH_TYPES[:pro] }
|
|
164
164
|
|
|
165
165
|
def camelize_keys(hash) = hash.deep_transform_keys { |key| CAMELIZED_KEYS[key] || key.to_s.camelize }
|
|
166
166
|
|
|
@@ -292,11 +292,6 @@ module FreightKit
|
|
|
292
292
|
remainder_cents = total_cents - prices.sum(&:cents)
|
|
293
293
|
prices << Price.new(blame: :api, cents: remainder_cents, description: prices.empty? ? 'Total' : 'Other') if remainder_cents.nonzero?
|
|
294
294
|
|
|
295
|
-
if self.class.overlength_fees_require_tariff?
|
|
296
|
-
overlength_cents = shipment.packages.sum { |package| overlength_fee(tariff, package) }
|
|
297
|
-
prices << Price.new(blame: :tariff, cents: overlength_cents, description: 'Overlength fees') if overlength_cents.nonzero?
|
|
298
|
-
end
|
|
299
|
-
|
|
300
295
|
rate = Rate.new(
|
|
301
296
|
carrier: self,
|
|
302
297
|
carrier_name: name,
|
|
@@ -344,6 +339,34 @@ module FreightKit
|
|
|
344
339
|
tracking_response
|
|
345
340
|
end
|
|
346
341
|
|
|
342
|
+
# Searches the reference as each kind of number in `SEARCH_TYPES` but the PRO.
|
|
343
|
+
#
|
|
344
|
+
# @note The API answers searches that find nothing, and rejected logins, with an `ErrorMessage`.
|
|
345
|
+
# @see Carrier#search_reference
|
|
346
|
+
def search_reference(reference, **)
|
|
347
|
+
SEARCH_TYPES.except(:pro).values.filter_map do |search_type|
|
|
348
|
+
data = parse(commit(:track, { search_for: reference, search_type: }))
|
|
349
|
+
error = parse_error(data, key: :error_message)
|
|
350
|
+
raise InvalidCredentialsError, error.message if error&.message&.match?(/authenticat|logon|password/i)
|
|
351
|
+
|
|
352
|
+
info = data[:general_info].to_h if error.nil?
|
|
353
|
+
tracking_number = text(info.to_h[:pro_number])
|
|
354
|
+
next if tracking_number.nil?
|
|
355
|
+
|
|
356
|
+
delivered = data[:status_list].to_a.find { |status| text(status[:status_code])&.upcase == self.class::EVENTS[:delivered] }
|
|
357
|
+
|
|
358
|
+
SearchResult.new(
|
|
359
|
+
delivered_on: delivered&.then { |status| date(status[:status_date]) },
|
|
360
|
+
destination: location(data[:ship_to]),
|
|
361
|
+
origin: location(data[:ship_from]),
|
|
362
|
+
picked_up_on: date(info[:shipment_date]),
|
|
363
|
+
references: { bol_number: info[:bol_number], order_number: info[:sid_number], po_number: info[:po_number] },
|
|
364
|
+
tracking_number:,
|
|
365
|
+
weight: text(info[:total_weight])&.then { |value| Measured::Weight.new(value.delete('^0-9.').to_d, :pounds) }
|
|
366
|
+
)
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
|
|
347
370
|
# Statuses have no location, so events take the origin or destination when they happen there
|
|
348
371
|
def shipment_event(status, destination:, origin:)
|
|
349
372
|
type_code = self.class::EVENTS.key(text(status[:status_code])&.upcase)
|
|
@@ -424,15 +424,6 @@ module FreightKit
|
|
|
424
424
|
prices = [Price.new(blame: :api, cents: total_cents - prices.sum(&:cents), description: 'Freight')] + prices
|
|
425
425
|
end
|
|
426
426
|
|
|
427
|
-
if self.class.overlength_fees_require_tariff?
|
|
428
|
-
shipment.packages.each do |package|
|
|
429
|
-
cents = overlength_fee(tariff, package)
|
|
430
|
-
next unless cents.positive?
|
|
431
|
-
|
|
432
|
-
prices << Price.new(blame: :tariff, cents:, description: 'Overlength fee')
|
|
433
|
-
end
|
|
434
|
-
end
|
|
435
|
-
|
|
436
427
|
transit_days = response.dig(:getquote_response, :return, :service, :days).to_i
|
|
437
428
|
|
|
438
429
|
# Calculate real transit time based on information we have about the destination service days
|
|
@@ -533,7 +524,7 @@ module FreightKit
|
|
|
533
524
|
|
|
534
525
|
break if next_api_event.blank?
|
|
535
526
|
|
|
536
|
-
if next_api_event[:description]
|
|
527
|
+
if next_api_event[:description]&.include?('INTERLINE') && next_api_event[:date] == api_event[:date]
|
|
537
528
|
shipment_events << ShipmentEvent.new(date_time:, location:, type_code: :departed)
|
|
538
529
|
next
|
|
539
530
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: freight_kit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.35
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Third Party Transportation Systems LLC
|
|
@@ -864,6 +864,7 @@ files:
|
|
|
864
864
|
- lib/freight_kit/carriers/zentner_transportation.rb
|
|
865
865
|
- lib/freight_kit/countries.rb
|
|
866
866
|
- lib/freight_kit/error.rb
|
|
867
|
+
- lib/freight_kit/errors/ambiguous_shipment_error.rb
|
|
867
868
|
- lib/freight_kit/errors/document_not_found_error.rb
|
|
868
869
|
- lib/freight_kit/errors/expired_credentials_error.rb
|
|
869
870
|
- lib/freight_kit/errors/http_error.rb
|
|
@@ -903,6 +904,8 @@ files:
|
|
|
903
904
|
- lib/freight_kit/models/rate_response.rb
|
|
904
905
|
- lib/freight_kit/models/region.rb
|
|
905
906
|
- lib/freight_kit/models/response.rb
|
|
907
|
+
- lib/freight_kit/models/search_response.rb
|
|
908
|
+
- lib/freight_kit/models/search_result.rb
|
|
906
909
|
- lib/freight_kit/models/shipment.rb
|
|
907
910
|
- lib/freight_kit/models/shipment_event.rb
|
|
908
911
|
- lib/freight_kit/models/terminal.rb
|