freight_kit 0.1.21 → 0.1.23

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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -3
  3. data/Rakefile +1 -3
  4. data/VERSION +1 -1
  5. data/freight_kit-0.1.21.gem +0 -0
  6. data/freight_kit-0.1.22.gem +0 -0
  7. data/freight_kit.gemspec +8 -19
  8. data/lib/freight_kit/address_normalizer.rb +1 -3
  9. data/lib/freight_kit/api_clients/soap_client.rb +30 -5
  10. data/lib/freight_kit/carrier.rb +36 -7
  11. data/lib/freight_kit/carriers/a1_express.rb +11 -0
  12. data/lib/freight_kit/carriers/abf_freight_system.rb +9 -26
  13. data/lib/freight_kit/carriers/aloha_freight_forwarders.rb +1 -5
  14. data/lib/freight_kit/carriers/amado_trucking.rb +1 -5
  15. data/lib/freight_kit/carriers/clear_lane_freight_systems.rb +6 -15
  16. data/lib/freight_kit/carriers/cpl_express.rb +1 -5
  17. data/lib/freight_kit/carriers/cross_country_freight_solutions.rb +6 -17
  18. data/lib/freight_kit/carriers/dependable_highway_express.rb +6 -18
  19. data/lib/freight_kit/carriers/forward_air.rb +4 -12
  20. data/lib/freight_kit/carriers/gsp_express.rb +13 -0
  21. data/lib/freight_kit/carriers/on_trac.rb +7 -25
  22. data/lib/freight_kit/carriers/peninsula_truck_lines.rb +4 -20
  23. data/lib/freight_kit/carriers/roadrunner_transportation_services.rb +2 -8
  24. data/lib/freight_kit/carriers/saia.rb +4 -19
  25. data/lib/freight_kit/carriers/southeastern_freight_lines.rb +4 -13
  26. data/lib/freight_kit/carriers/t_force_worldwide.rb +7 -19
  27. data/lib/freight_kit/carriers/top_ten_express.rb +13 -0
  28. data/lib/freight_kit/carriers/total_quality_logistics.rb +2 -1
  29. data/lib/freight_kit/carriers/western_regional_delivery_service.rb +26 -11
  30. data/lib/freight_kit/carriers/xpo_logistics.rb +5 -17
  31. data/lib/freight_kit/errors/rate_limit_error.rb +12 -0
  32. data/lib/freight_kit/errors/unserviceable_accessorials_error.rb +1 -3
  33. data/lib/freight_kit/helpers/pickupable.rb +1 -10
  34. data/lib/freight_kit/http_client/httpi_adapter.rb +37 -0
  35. data/lib/freight_kit/http_client/safe_retries.rb +17 -1
  36. data/lib/freight_kit/http_client.rb +13 -9
  37. data/lib/freight_kit/models/credential.rb +2 -15
  38. data/lib/freight_kit/models/lane.rb +20 -0
  39. data/lib/freight_kit/models/shipment.rb +1 -8
  40. data/lib/freight_kit/models/territory.rb +37 -0
  41. data/lib/freight_kit/package.rb +3 -13
  42. data/lib/freight_kit/packaging.rb +1 -16
  43. data/lib/freight_kit/platforms/carrier_logistics.rb +5 -10
  44. data/lib/freight_kit/platforms/dsdc.rb +82 -0
  45. data/lib/freight_kit/platforms/next_tms/graphql_client/mutation/quote_create.rb +32 -0
  46. data/lib/freight_kit/platforms/next_tms/graphql_client/mutation/shipment_create.rb +29 -0
  47. data/lib/freight_kit/platforms/next_tms/graphql_client/query/broker_carrier.rb +37 -0
  48. data/lib/freight_kit/platforms/next_tms/graphql_client/query/broker_carriers.rb +45 -0
  49. data/lib/freight_kit/platforms/next_tms/graphql_client/query/broker_customer.rb +54 -0
  50. data/lib/freight_kit/platforms/next_tms/graphql_client/query/broker_customers.rb +62 -0
  51. data/lib/freight_kit/platforms/next_tms/graphql_client/query/carrier.rb +22 -0
  52. data/lib/freight_kit/platforms/next_tms/graphql_client/query/carriers.rb +30 -0
  53. data/lib/freight_kit/platforms/next_tms/graphql_client/query/customer.rb +20 -0
  54. data/lib/freight_kit/platforms/next_tms/graphql_client/query/customers.rb +28 -0
  55. data/lib/freight_kit/platforms/next_tms/graphql_client/query/invoice.rb +31 -0
  56. data/lib/freight_kit/platforms/next_tms/graphql_client/query/invoices.rb +39 -0
  57. data/lib/freight_kit/platforms/next_tms/graphql_client/query/shipment.rb +102 -0
  58. data/lib/freight_kit/platforms/next_tms/graphql_client/query/shipment_documents.rb +29 -0
  59. data/lib/freight_kit/platforms/next_tms/graphql_client/query/shipments.rb +110 -0
  60. data/lib/freight_kit/platforms/next_tms/graphql_client.rb +22 -0
  61. data/lib/freight_kit/platforms/next_tms/orm/address.rb +22 -0
  62. data/lib/freight_kit/platforms/next_tms/orm/base.rb +120 -0
  63. data/lib/freight_kit/platforms/next_tms/orm/broker_carrier.rb +18 -0
  64. data/lib/freight_kit/platforms/next_tms/orm/broker_customer.rb +22 -0
  65. data/lib/freight_kit/platforms/next_tms/orm/carrier.rb +14 -0
  66. data/lib/freight_kit/platforms/next_tms/orm/collection.rb +335 -0
  67. data/lib/freight_kit/platforms/next_tms/orm/customer.rb +12 -0
  68. data/lib/freight_kit/platforms/next_tms/orm/invoice.rb +21 -0
  69. data/lib/freight_kit/platforms/next_tms/orm/record_not_found_error.rb +9 -0
  70. data/lib/freight_kit/platforms/next_tms/orm/shipment.rb +50 -0
  71. data/lib/freight_kit/platforms/next_tms/orm.rb +38 -0
  72. data/lib/freight_kit/platforms/next_tms.rb +414 -55
  73. data/lib/freight_kit/platforms/the_great_information_factory.rb +4 -12
  74. data/lib/freight_kit.rb +19 -0
  75. data/schemas/next_tms.json +110710 -0
  76. metadata +86 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 543816b71edfd222f466c27be9e96722cb616ebb33768e3985379aea350b36d8
4
- data.tar.gz: 9aba35e8079b412e35cf2a868ac3b7f0b7c7d47ac2a1b595bc2bcb06ba4e920d
3
+ metadata.gz: 378832bcfdc26a1c18c3eaa4f4a08b55dacff49e724b5d1e933de4cd9341e0d0
4
+ data.tar.gz: b14186797e2b67ece60437398fb1fee1c7664c7758138c1560acf3601fa9c5a8
5
5
  SHA512:
6
- metadata.gz: 363cd6ebe87b53b68dc5a8a715657ed62069e9bc55a81fdef7c4ad6d056913f1d33651787fd726167337c1ffb38194c9b2c1af84a6501002f62af6aba050ab8c
7
- data.tar.gz: eda608438300dd2581bef08ea6b8c4bb6ab0166d7f98cc1027c034da683e84a49a51b9c31d8681c6481c92c625a09c7fe673820ff63fee5b9e0f9a0e267b497a
6
+ metadata.gz: 0e7542f3dc7aaf4362a47e713a9c6ee73322f1ecf1f95c512f2d304c0061bcac3d5c741b2469fb060274f3b0d3a4b8d36364ef092f46a45d9a74773d50fe8648
7
+ data.tar.gz: b13e4ece3fb6ffb4f68f0ec485607f986f7127437b37c53a19a8422b901eaa50ae1435573cc885588cb9e737d757db6f8d9d5c79aebbf5c17878483ce8b2cc2f
data/README.md CHANGED
@@ -84,20 +84,22 @@ Debug output contains request headers and bodies, which include carrier credenti
84
84
 
85
85
  The client uses conditional requests: it sends `If-None-Match` and `If-Modified-Since` and reuses the cached body when the carrier replies `304 Not Modified`.
86
86
 
87
- By default, the client keeps cached responses in an in-process `ActiveSupport::Cache::MemoryStore`. To share the cache between processes, set your own backend at boot. The backend must respond to `read`, `write`, and `delete_matched`, like `ActiveSupport::Cache::Store`.
87
+ FreightKit keeps cached data, such as HTTP responses, in `FreightKit.cache`. By default, this is an in-process `ActiveSupport::Cache::MemoryStore`. To share the cache between processes, set your own backend at boot. The backend must respond to `read`, `write`, `fetch`, and `delete_matched`, like `ActiveSupport::Cache::Store`.
88
88
 
89
89
  In Rails, add this line to an initializer:
90
90
 
91
91
  ```ruby
92
- FreightKit::HTTPClient.cache = Rails.cache
92
+ FreightKit.cache = Rails.cache
93
93
  ```
94
94
 
95
95
  In Hanami or plain Ruby, give any compatible store:
96
96
 
97
97
  ```ruby
98
- FreightKit::HTTPClient.cache = ActiveSupport::Cache::RedisCacheStore.new(url: ENV.fetch('REDIS_URL'))
98
+ FreightKit.cache = ActiveSupport::Cache::RedisCacheStore.new(url: ENV.fetch('REDIS_URL'))
99
99
  ```
100
100
 
101
+ To use a different store for HTTP responses only, set `FreightKit::HTTPClient.cache`.
102
+
101
103
  Cache entries contain carrier response bodies. Use a backend that you trust with that data. Keys are SHA-256 digests of the method, the URL, and all request headers. Requests with different credentials thus never share an entry. To turn off the cache, set `ActiveSupport::Cache::NullStore.new`.
102
104
 
103
105
  ## Standard Usage
data/Rakefile CHANGED
@@ -1,6 +1,4 @@
1
1
  desc 'Load FreightKit'
2
- task(:environment) do
3
- require_relative 'lib/freight_kit'
4
- end
2
+ task(:environment) { require_relative 'lib/freight_kit' }
5
3
 
6
4
  Dir[File.expand_path('tasks/*.rake', __dir__)].each { |task| import(task) }
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.21
1
+ 0.1.23
Binary file
Binary file
data/freight_kit.gemspec CHANGED
@@ -4,27 +4,14 @@ Gem::Specification.new do |spec|
4
4
  spec.name = 'freight_kit'
5
5
  spec.version = version
6
6
 
7
- spec.authors = [
8
- 'Third Party Transportation Systems LLC',
9
- 'Brody Hoskins',
10
- 'Sub Pop Records',
11
- 'Shopify'
12
- ]
13
- spec.email = [
14
- 'hello@next-tms.com',
15
- 'brody@brody.digital',
16
- 'webmaster@subpop.com',
17
- 'integrations-team@shopify.com'
18
- ]
7
+ spec.authors = ['Third Party Transportation Systems LLC', 'Brody Hoskins', 'Sub Pop Records', 'Shopify']
8
+ spec.email = ['hello@next-tms.com', 'brody@brody.digital', 'webmaster@subpop.com', 'integrations-team@shopify.com']
19
9
 
20
10
  spec.description = 'Freight carrier API and website abstraction library for transportation management systems (TMS)'
21
11
  spec.homepage = 'https://github.com/next-tms/freight_kit'
22
12
  spec.summary = spec.description
23
13
 
24
- spec.files = Dir['[A-Z]*'] +
25
- Dir['configuration/*/*.yml'] +
26
- Dir['lib/**/*'] +
27
- Dir['test/**/*']
14
+ spec.files = Dir['[A-Z]*'] + Dir['configuration/*/*.yml'] + Dir['lib/**/*'] + Dir['schemas/*'] + Dir['test/**/*']
28
15
  spec.require_paths = ['lib']
29
16
 
30
17
  spec.add_development_dependency('faker', '~> 3.8.0')
@@ -41,14 +28,16 @@ Gem::Specification.new do |spec|
41
28
  spec.add_dependency('brotli', '>= 0.9.2', '< 1') # CVE-2026-111497
42
29
  spec.add_dependency('business_time', '~> 0.13.0')
43
30
  spec.add_dependency('countries', '~> 8.1')
44
- spec.add_dependency('httpx', '>= 1.9.0', '< 2')
31
+ spec.add_dependency('graphql', '>= 2.0', '< 3') # Next TMS
32
+ spec.add_dependency('graphql-client', '>= 0.23.0', '< 1') # Next TMS
33
+ spec.add_dependency('httpx', '>= 1.9.0', '!= 1.9.1', '< 2') # 1.9.1: https://github.com/HoneyryderChuck/httpx/issues/162
45
34
  spec.add_dependency('json', '< 3') # measured
46
- spec.add_dependency('measured', '>= 2.0', '< 3.2.2')
35
+ spec.add_dependency('measured', '>= 2.0', '< 3.2.3')
47
36
  spec.add_dependency('mimemagic', '~> 0.4.3')
48
37
  spec.add_dependency('multi_xml', '>= 0.9.1', '< 1')
49
38
  spec.add_dependency('nokogiri', '>= 1.6', '< 1.20')
50
39
  spec.add_dependency('place_kit', '~> 0.0.6')
51
- spec.add_dependency('savon', '>= 2.17', '< 2.18')
40
+ spec.add_dependency('savon', '>= 2.17', '< 2.19')
52
41
  spec.add_dependency('StreetAddress', '~> 2.0')
53
42
  spec.add_dependency('tzinfo-data', '~> 1.2023', '>= 1.2023.3')
54
43
  spec.add_dependency('watir', '>= 7.0', '< 7.4')
@@ -17,9 +17,7 @@ module FreightKit
17
17
  words = words.take_while { |word| UNIT_DESIGNATORS.exclude?(word) }
18
18
  return unless words.first&.match?(/\d/)
19
19
 
20
- words.map do |word|
21
- StreetAddress::US::DIRECTIONAL[word]&.downcase || StreetAddress::US::STREET_TYPES[word] || word
22
- end.join(' ')
20
+ words.map { |word| StreetAddress::US::DIRECTIONAL[word]&.downcase || StreetAddress::US::STREET_TYPES[word] || word }.join(' ')
23
21
  end
24
22
  end
25
23
  end
@@ -1,14 +1,18 @@
1
1
  module FreightKit
2
2
  class SoapClient
3
3
  API_EXCEPTIONS = [
4
- Savon::HTTPError,
5
- Net::ReadTimeout,
6
- Net::OpenTimeout,
7
4
  Errno::ECONNREFUSED,
8
5
  Errno::ECONNRESET,
9
- Errno::EHOSTUNREACH
6
+ Errno::EHOSTUNREACH,
7
+ HTTPX::ConnectionError,
8
+ HTTPX::TimeoutError,
9
+ Savon::HTTPError
10
10
  ].freeze
11
11
 
12
+ WSDL_CACHE_HEADERS = ['cache-control', 'etag', 'expires', 'last-modified'].freeze
13
+ WSDL_EXPIRES_IN = 1.day
14
+ WSDL_NAMESPACE = 'freight_kit/soap_client/wsdl'.freeze
15
+
12
16
  def initialize(carrier:, action:, client_args:, call_args:, soap_operation:)
13
17
  @carrier = carrier
14
18
  @action = action
@@ -26,7 +30,7 @@ module FreightKit
26
30
  # For testing and debugging
27
31
  # client_args.merge!(log: true, pretty_print_xml: true)
28
32
 
29
- Savon.client(**client_args).call(soap_operation, **call_args).body
33
+ Savon.client(**savon_args).call(soap_operation, **call_args).body
30
34
  rescue *api_exceptions => e
31
35
  response = build_response_class(action:)
32
36
  response.error = ResponseError.new("Network Error: #{e}")
@@ -64,5 +68,26 @@ module FreightKit
64
68
  when :pickup then PickupResponse.new(request:, response: nil)
65
69
  end
66
70
  end
71
+
72
+ def fetch_wsdl(url)
73
+ key = "#{WSDL_NAMESPACE}/#{Digest::SHA256.hexdigest(url)}"
74
+ cached = FreightKit.cache.read(key)
75
+ return cached if cached
76
+
77
+ response = HTTPClient.get(url)
78
+ raise Wasabi::Resolver::HTTPError.new("Error: #{response.code} for url #{url}", response) unless (200..299).cover?(response.code)
79
+
80
+ if WSDL_CACHE_HEADERS.none? { |field| response.headers.key?(field) }
81
+ FreightKit.cache.write(key, response.body, expires_in: WSDL_EXPIRES_IN)
82
+ end
83
+
84
+ response.body
85
+ end
86
+
87
+ def savon_args
88
+ args = client_args.merge(adapter: HTTPClient::HTTPIAdapter::NAME)
89
+ args[:wsdl] = fetch_wsdl(args[:wsdl]) if args[:wsdl].to_s.match?(%r{\Ahttps?://})
90
+ args
91
+ end
67
92
  end
68
93
  end
@@ -61,6 +61,10 @@ module FreightKit
61
61
  false
62
62
  end
63
63
 
64
+ # The directed lanes the carrier serves, for carriers that serve only some origins to some destinations.
65
+ # @return [Array<FreightKit::Lane>]
66
+ def lanes = []
67
+
64
68
  # The carrier's registered legal name, with its entity suffix (e.g. "Saia Motor Freight Line LLC"), when known.
65
69
  # {.name} is the name the carrier does business as.
66
70
  # @return [String, nil]
@@ -72,16 +76,23 @@ module FreightKit
72
76
  # @param package [FreightKit::Package]
73
77
  # @return [Measured::Length]
74
78
  def longest_dimension(package)
75
- [
76
- Measured::Length.new(package.length(:inches), :inches),
77
- Measured::Length.new(package.width(:inches), :inches)
78
- ].max
79
+ [Measured::Length.new(package.length(:inches), :inches), Measured::Length.new(package.width(:inches), :inches)].max
79
80
  end
80
81
 
81
82
  # FreightKit accessorials the carrier prices, mapped to the carrier's codes.
82
83
  # @return [Hash{Symbol => Object}]
83
84
  def mappable_accessorials = {}
84
85
 
86
+ # The carrier's lanes that go from the origin to the destination, most specific first.
87
+ # @param destination [FreightKit::Location]
88
+ # @param origin [FreightKit::Location]
89
+ # @return [Array<FreightKit::Lane>]
90
+ def matching_lanes(origin, destination)
91
+ lanes
92
+ .select { |lane| lane.include?(origin, destination) }
93
+ .sort_by.with_index { |lane, index| [-lane.specificity, index] }
94
+ end
95
+
85
96
  # The maximum height the carrier will accept.
86
97
  # @return [Measured::Length]
87
98
  def maximum_height = Measured::Length.new(105, :inches)
@@ -146,6 +157,18 @@ module FreightKit
146
157
  # @return [String, nil]
147
158
  def scac = nil
148
159
 
160
+ # Whether the carrier serves a shipment from the origin to the destination: a lane matches, or both locations are
161
+ # inside its territories. A carrier without lanes or territories serves everywhere.
162
+ # @param destination [FreightKit::Location]
163
+ # @param origin [FreightKit::Location]
164
+ # @return [Boolean]
165
+ def serve?(origin, destination)
166
+ return true if lanes.blank? && territories.blank?
167
+
168
+ matching_lanes(origin, destination).any? ||
169
+ [origin, destination].all? { |location| territories.any? { |territory| territory.include?(location) } }
170
+ end
171
+
149
172
  # Raises {UnserviceableAccessorialsError} for accessorials the carrier refuses, or that it neither maps nor serves
150
173
  # unpriced. Returns false when the carrier maps no accessorials.
151
174
  # @return [Boolean]
@@ -170,6 +193,10 @@ module FreightKit
170
193
  # @return [Array<FreightKit::Terminal>]
171
194
  def terminals = []
172
195
 
196
+ # The areas the carrier picks up from and delivers to, in any combination.
197
+ # @return [Array<FreightKit::Territory>]
198
+ def territories = []
199
+
173
200
  # The template URL for tracking one of carrier's `NUMBERS` publicly. A template URL is a URL containing the token
174
201
  # "%s" that can be replaced to generate a valid URL.
175
202
  #
@@ -254,9 +281,7 @@ module FreightKit
254
281
  [package.height(:inches), package.length(:inches), package.width(:inches)].any?(&:zero?)
255
282
  end
256
283
 
257
- uncovered_overlength = packages.any? do |package|
258
- overlength?(package) && overlength_rule_for(tariff, package).nil?
259
- end
284
+ uncovered_overlength = packages.any? { |package| overlength?(package) && overlength_rule_for(tariff, package).nil? }
260
285
 
261
286
  if missing_dimensions
262
287
  message << 'item dimensions are required'
@@ -432,6 +457,10 @@ module FreightKit
432
457
 
433
458
  protected
434
459
 
460
+ # Proxy for HTTP requests, from the optional `:api_proxy` credential.
461
+ # @return [String|NilClass]
462
+ def proxy_url = fetch_credential(:api_proxy)&.proxy_url
463
+
435
464
  # Use after building the request to save for later inspection.
436
465
  # @return [void]
437
466
  def save_request(request) = @last_request = request
@@ -19,6 +19,17 @@ module FreightKit
19
19
  def id = 'e899224d-f3c9-47b5-9e2f-61c9c0d8c497'
20
20
  def name = 'A1 Express'
21
21
  def scac = 'AOXQ'
22
+
23
+ # Southern California, plus Las Vegas and all of Clark County, Nevada, by ZIP prefix.
24
+ def territories
25
+ country = Countries.find_by(iso31661_alpha2: 'US')
26
+ southern_california = [*'900'..'908', *'910'..'928', '930', '931', '935', '93225', '93243', '93420']
27
+
28
+ [
29
+ Territory.new(country:, postal_codes: southern_california, region_abbreviation: 'CA'),
30
+ Territory.new(country:, postal_codes: ['889', '890', '891'], region_abbreviation: 'NV')
31
+ ]
32
+ end
22
33
  end
23
34
  end
24
35
  end
@@ -32,9 +32,7 @@ module FreightKit
32
32
  def scac = 'ABFS'
33
33
 
34
34
  def serviceable_accessorials?(accessorials)
35
- unsupported_accessorials = unserviceable_accessorials.select do |key|
36
- accessorials.include?(key)
37
- end.sort!
35
+ unsupported_accessorials = unserviceable_accessorials.select { |key| accessorials.include?(key) }.sort!
38
36
 
39
37
  message = "#{unsupported_accessorials.join(', ')} unserviceable"
40
38
  raise FreightKit::UnserviceableError, message if unsupported_accessorials.any?
@@ -105,9 +103,7 @@ module FreightKit
105
103
  # query params
106
104
  raise FreightKit::UnserviceableError, 'Too many packages' if packages.count > 15
107
105
 
108
- unsupported_packaging_types = packages.map(&:packaging).map(&:type).select do |type|
109
- PACKAGE_TYPES.keys.exclude?(type)
110
- end.sort!
106
+ unsupported_packaging_types = packages.map(&:packaging).map(&:type).select { |type| PACKAGE_TYPES.keys.exclude?(type) }.sort!
111
107
 
112
108
  message = "#{unsupported_packaging_types.join(', ').upcase_first} unserviceable"
113
109
  raise FreightKit::UnserviceableError, message if unsupported_packaging_types.any?
@@ -305,9 +301,7 @@ module FreightKit
305
301
  end
306
302
 
307
303
  other_options = {}.tap do |builder|
308
- alpha2_codes = [shipment.destination.country, shipment.origin.country].map do |country|
309
- country.code(:alpha2).value
310
- end
304
+ alpha2_codes = [shipment.destination.country, shipment.origin.country].map { |country| country.code(:alpha2).value }
311
305
 
312
306
  builder['Acc_ARR'] = 'Y' if shipment.accessorials.include?(:appointment_delivery)
313
307
 
@@ -329,25 +323,15 @@ module FreightKit
329
323
  builder['Acc_HAZ'] = 'Y' if shipment.packages.any?(&:hazmat?)
330
324
  builder['Acc_PALLET'] = 'Y' if shipment.packages.map(&:packaging).all?(&:pallet?)
331
325
 
332
- unless shipment.accessorials.intersect?(%i[
333
- church_pickup
334
- inside_pickup
335
- liftgate_pickup
336
- residential_pickup
337
- restaurant_pickup
338
- ])
326
+ unless shipment.accessorials.intersect?(%i[church_pickup inside_pickup liftgate_pickup residential_pickup restaurant_pickup])
339
327
  builder['Acc_SL'] = 'Y'
340
328
  end
341
329
 
342
330
  builder['Acc_SS'] = 'Y'
343
331
 
344
- longest_dimension_in = if shipment.packages.all? do |package|
345
- package.length(:inch).present? && package.width(:inch).present?
346
- end
332
+ longest_dimension_in = if shipment.packages.all? { |package| package.length(:inch).present? && package.width(:inch).present? }
347
333
 
348
- shipment.packages.map do |package|
349
- [package.length(:in), package.width(:in)].max
350
- end.max.ceil
334
+ shipment.packages.map { |package| [package.length(:in), package.width(:in)].max }.max.ceil
351
335
  end
352
336
 
353
337
  if longest_dimension_in.present?
@@ -367,8 +351,7 @@ module FreightKit
367
351
  end
368
352
  end
369
353
 
370
- params = [account, commodities, consignee, delivery, other_options, pickup, shipper, specifics, third_party]
371
- .reduce({}, :merge)
354
+ params = [account, commodities, consignee, delivery, other_options, pickup, shipper, specifics, third_party].reduce({}, :merge)
372
355
 
373
356
  build_request(:rates, { params: })
374
357
  end
@@ -394,9 +377,9 @@ module FreightKit
394
377
  url = request[:url]
395
378
 
396
379
  response = if method == :post
397
- HTTPClient.post(url, headers:, body:)
380
+ HTTPClient.post(url, headers:, body:, proxy_url:)
398
381
  else
399
- HTTPClient.get(url, headers:)
382
+ HTTPClient.get(url, headers:, proxy_url:)
400
383
  end
401
384
 
402
385
  response.deep_transform_keys! { |key| key.downcase.to_sym }[:abf] if response&.parsed_response
@@ -17,11 +17,7 @@ module FreightKit
17
17
 
18
18
  def contacts
19
19
  [
20
- Contact.new(
21
- department: 'Rating',
22
- email: 'rates@alohafreight.com',
23
- id: '5de89baa-e0df-4374-a3be-018251dd6f4e'
24
- )
20
+ Contact.new(department: 'Rating', email: 'rates@alohafreight.com', id: '5de89baa-e0df-4374-a3be-018251dd6f4e')
25
21
  ]
26
22
  end
27
23
 
@@ -4,11 +4,7 @@ module FreightKit
4
4
  class << self
5
5
  def contacts
6
6
  [
7
- Contact.new(
8
- department: 'Dispatch',
9
- email: 'la.dispatch@amadotrucking.com',
10
- id: 'c5dab2fd-b178-41f7-bc2b-3f53f8717c01'
11
- )
7
+ Contact.new(department: 'Dispatch', email: 'la.dispatch@amadotrucking.com', id: 'c5dab2fd-b178-41f7-bc2b-3f53f8717c01')
12
8
  ]
13
9
  end
14
10
 
@@ -274,9 +274,7 @@ module FreightKit
274
274
  end
275
275
 
276
276
  def parse_amount(amount)
277
- ['$', ','].each do |char|
278
- amount = amount.sub(char, '')
279
- end
277
+ ['$', ','].each { |char| amount = amount.sub(char, '') }
280
278
 
281
279
  return 0 if amount.blank?
282
280
 
@@ -312,13 +310,10 @@ module FreightKit
312
310
 
313
311
  # Hack to get around JavaScript messing up our input
314
312
  sleep(1)
315
- from.chars.each do |char|
316
- browser.text_field(name: 'txtFromDate').append(char)
317
- end
313
+ from.chars.each { |char| browser.text_field(name: 'txtFromDate').append(char) }
318
314
 
319
315
  browser.text_field(name: 'txtToDate').click
320
- browser.element(xpath: '/html/body/form/div[3]/div[4]/div[3]/div[2]/div/div/div[3]/div').wait_until(&:present?)
321
- .click
316
+ browser.element(xpath: '/html/body/form/div[3]/div[4]/div[3]/div[2]/div/div/div[3]/div').wait_until(&:present?).click
322
317
 
323
318
  browser.button(name: 'btnSubmit').click
324
319
 
@@ -335,9 +330,7 @@ module FreightKit
335
330
  return document_response
336
331
  end
337
332
 
338
- browser.element(xpath: '/html/body/form/div[3]/div[4]/div[8]/div/table/tbody/tr/td[12]/a')
339
- .wait_until(&:present?)
340
- .click
333
+ browser.element(xpath: '/html/body/form/div[3]/div[4]/div[8]/div/table/tbody/tr/td[12]/a').wait_until(&:present?).click
341
334
 
342
335
  browser.switch_window
343
336
 
@@ -376,7 +369,7 @@ module FreightKit
376
369
  document_response.request = URI.parse(url)
377
370
 
378
371
  begin
379
- response = HTTPClient.get(url)
372
+ response = HTTPClient.get(url, proxy_url:)
380
373
  rescue StandardError => e
381
374
  document_response.error = e
382
375
  return document_response
@@ -409,9 +402,7 @@ module FreightKit
409
402
 
410
403
  if error.present?
411
404
  if error.include?('do not service this lane')
412
- rate_response.error = UnserviceableError.new(
413
- 'Incorrect ZIP code or no service available at origin and/or destination'
414
- )
405
+ rate_response.error = UnserviceableError.new('Incorrect ZIP code or no service available at origin and/or destination')
415
406
  return rate_response
416
407
  end
417
408
 
@@ -4,11 +4,7 @@ module FreightKit
4
4
  class << self
5
5
  def contacts
6
6
  [
7
- Contact.new(
8
- department: 'Dispatch',
9
- email: 'dispatch@cplexpress.com',
10
- id: 'ba43e014-2e59-43d6-8f39-acb80128b8c9'
11
- ),
7
+ Contact.new(department: 'Dispatch', email: 'dispatch@cplexpress.com', id: 'ba43e014-2e59-43d6-8f39-acb80128b8c9'),
12
8
  Contact.new(department: 'Main', id: 'a7daa1e5-4abb-48de-9893-493e91806a83', phone: '+13104189008')
13
9
  ]
14
10
  end
@@ -128,7 +128,7 @@ module FreightKit
128
128
  def minimum_length_for_overlength_fees = Measured::Length.new(6, :feet)
129
129
  def name = 'CrossCountry Freight Solutions'
130
130
  def overlength_fees_require_tariff? = false
131
- def required_credential_types = %i[api_key api_proxy]
131
+ def required_credential_types = %i[api_key]
132
132
  def requirements = %i[credentials]
133
133
  def scac = 'CCYQ'
134
134
  def unquotable_accessorials = %i[athletic_facility_delivery dock_dropoff dock_pickup]
@@ -174,9 +174,7 @@ module FreightKit
174
174
 
175
175
  next if longest_dimension < 96
176
176
 
177
- package.quantity.times do
178
- accessorials << { Code: 'EXLEN', Factor: longest_dimension }
179
- end
177
+ package.quantity.times { accessorials << { Code: 'EXLEN', Factor: longest_dimension } }
180
178
  end
181
179
 
182
180
  shipment.accessorials.map do |accessorial|
@@ -266,16 +264,8 @@ module FreightKit
266
264
 
267
265
  def build_request(action, body: {}, query: {})
268
266
  api_key = fetch_credential(:api_key).api_key
269
- proxy_url = fetch_credential(:api_proxy).proxy_url
270
-
271
- request = {
272
- url: build_url(action),
273
- headers: { APIKEY: api_key },
274
- method: API.dig(:methods, action),
275
- body:,
276
- query:,
277
- proxy_url:
278
- }.compact
267
+
268
+ request = { url: build_url(action), headers: { APIKEY: api_key }, method: API.dig(:methods, action), body:, query: }.compact
279
269
 
280
270
  save_request(request)
281
271
  request
@@ -291,7 +281,7 @@ module FreightKit
291
281
  headers: request[:headers].merge(JSON_HEADERS),
292
282
  body: request[:body],
293
283
  query: request[:query],
294
- proxy: request[:proxy_url]
284
+ proxy_url:
295
285
  )
296
286
 
297
287
  unless response.code == 200
@@ -377,8 +367,7 @@ module FreightKit
377
367
  expires_at = ::Time.iso8601(response['QuoteExpiryDate'])
378
368
 
379
369
  transit_days = (
380
- ::Time.iso8601(response['EarliestDeliveryDate']).to_date -
381
- ::Time.iso8601(response['PickupDate']).to_date
370
+ ::Time.iso8601(response['EarliestDeliveryDate']).to_date - ::Time.iso8601(response['PickupDate']).to_date
382
371
  ).to_i
383
372
 
384
373
  prices = []
@@ -155,10 +155,7 @@ module FreightKit
155
155
  },
156
156
  use_ssl: { rates: false, track: false }
157
157
  }.freeze
158
- CITY_STATES = {
159
- ca: ['Los Angeles', 'Mammoth Lakes', 'Sacramento', 'Redding', 'West Sacramento'],
160
- nv: ['Reno', 'Sparks']
161
- }.freeze
158
+ CITY_STATES = { ca: ['Los Angeles', 'Mammoth Lakes', 'Sacramento', 'Redding', 'West Sacramento'], nv: ['Reno', 'Sparks'] }.freeze
162
159
  EVENTS = {
163
160
  types: {
164
161
  arrived_at_terminal: 'linehaul arrived',
@@ -180,8 +177,7 @@ module FreightKit
180
177
  country_codes = [shipment.destination.country.code(:alpha2).value, shipment.origin.country.code(:alpha2).value]
181
178
 
182
179
  if country_codes.reject { |c| c.upcase == 'US' }.any?
183
- raise UnserviceableError,
184
- "No service from #{shipment.origin.postal_code} to #{shipment.destination.postal_code}"
180
+ raise UnserviceableError, "No service from #{shipment.origin.postal_code} to #{shipment.destination.postal_code}"
185
181
  end
186
182
 
187
183
  accessorials = []
@@ -262,9 +258,7 @@ module FreightKit
262
258
  def parse_amount(amount)
263
259
  negative = amount.include?('(') && amount.include?(')')
264
260
 
265
- ['$', ',', '(', ')'].each do |char|
266
- amount = amount.sub(char, '')
267
- end
261
+ ['$', ',', '(', ')'].each { |char| amount = amount.sub(char, '') }
268
262
 
269
263
  return 0 if amount.blank?
270
264
 
@@ -333,8 +327,7 @@ module FreightKit
333
327
  browser.button(name: 'ctl00$ContentPlaceHolder1$btnSubmit').click
334
328
 
335
329
  begin
336
- browser.element(xpath: '//*[@id="ContentPlaceHolder1_GridView1"]/tbody/tr[2]/td[2]/a')
337
- .click
330
+ browser.element(xpath: '//*[@id="ContentPlaceHolder1_GridView1"]/tbody/tr[2]/td[2]/a').click
338
331
  rescue Watir::Exception::UnknownObjectException
339
332
  document_response.error = DocumentNotFoundError.new
340
333
  return document_response
@@ -373,7 +366,7 @@ module FreightKit
373
366
  document_response.request = URI.parse(url)
374
367
 
375
368
  begin
376
- response = HTTPClient.get(url)
369
+ response = HTTPClient.get(url, proxy_url:)
377
370
  rescue StandardError => e
378
371
  document_response.error = e
379
372
  return document_response
@@ -438,12 +431,7 @@ module FreightKit
438
431
 
439
432
  prices = []
440
433
 
441
- shipment_details = response.dig(
442
- :get_rates_response,
443
- :get_rates_result,
444
- :shipment_detail_response,
445
- :shipment_detail_row
446
- )
434
+ shipment_details = response.dig(:get_rates_response, :get_rates_result, :shipment_detail_response, :shipment_detail_row)
447
435
 
448
436
  shipment_details.each do |shipment_detail|
449
437
  next if shipment_detail[:charge].blank?
@@ -316,22 +316,14 @@ module FreightKit
316
316
  end
317
317
 
318
318
  def build_document_request(doc_id:, tracking_number:)
319
- request = {
320
- url: build_url(:document, doc_id:, tracking_number:),
321
- headers: build_headers,
322
- method: API.dig(:methods, :documents)
323
- }
319
+ request = { url: build_url(:document, doc_id:, tracking_number:), headers: build_headers, method: API.dig(:methods, :documents) }
324
320
 
325
321
  save_request(request)
326
322
  request
327
323
  end
328
324
 
329
325
  def build_documents_request(tracking_number)
330
- request = {
331
- url: build_url(:documents, tracking_number:),
332
- headers: build_headers,
333
- method: API.dig(:methods, :documents)
334
- }
326
+ request = { url: build_url(:documents, tracking_number:), headers: build_headers, method: API.dig(:methods, :documents) }
335
327
 
336
328
  save_request(request)
337
329
  request
@@ -570,9 +562,9 @@ module FreightKit
570
562
 
571
563
  response = case method
572
564
  when :post
573
- HTTPClient.post(url, headers:, body:)
565
+ HTTPClient.post(url, headers:, body:, proxy_url:)
574
566
  else
575
- HTTPClient.get(url, headers:)
567
+ HTTPClient.get(url, headers:, proxy_url:)
576
568
  end
577
569
 
578
570
  if (200..299).exclude?(response.code)
@@ -16,6 +16,19 @@ module FreightKit
16
16
  end
17
17
 
18
18
  def id = '42b3f8f9-c85c-4144-b2e3-172386bc29d4'
19
+
20
+ def lanes
21
+ country = Countries.find_by(iso31661_alpha2: 'US')
22
+
23
+ [
24
+ Lane.new(
25
+ destination: Territory.new(country:, region_abbreviation: 'KS'),
26
+ id: '868188aa-d976-4c9a-8a06-0536bd0dc8f2',
27
+ origin: Territory.new(country:)
28
+ )
29
+ ]
30
+ end
31
+
19
32
  def name = 'GSP Express'
20
33
  def us_mc_number = 1_480_261
21
34
  end