freight_kit 0.1.19 → 0.1.20
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 +51 -52
- data/README.md +36 -0
- data/VERSION +1 -1
- data/freight_kit.gemspec +9 -6
- data/lib/freight_kit/carriers/abfs.rb +2 -2
- data/lib/freight_kit/carriers/ccyq.rb +2 -9
- data/lib/freight_kit/carriers/clni.rb +2 -2
- data/lib/freight_kit/carriers/cnwy.rb +3 -3
- data/lib/freight_kit/carriers/dphe.rb +7 -9
- data/lib/freight_kit/carriers/drrq.rb +18 -18
- data/lib/freight_kit/carriers/fwda.rb +3 -3
- data/lib/freight_kit/carriers/otcl.rb +4 -12
- data/lib/freight_kit/carriers/saia.rb +4 -6
- data/lib/freight_kit/carriers/sefl.rb +2 -2
- data/lib/freight_kit/carriers/tqyl.rb +1 -3
- data/lib/freight_kit/carriers/wrds.rb +3 -3
- data/lib/freight_kit/carriers.rb +24 -25
- data/lib/freight_kit/errors/response_error.rb +1 -1
- data/lib/freight_kit/http_client/cache_store.rb +61 -0
- data/lib/freight_kit/http_client/log_device.rb +15 -0
- data/lib/freight_kit/http_client/response.rb +40 -0
- data/lib/freight_kit/http_client/revalidation.rb +27 -0
- data/lib/freight_kit/http_client/safe_retries.rb +25 -0
- data/lib/freight_kit/http_client/zstd.rb +30 -0
- data/lib/freight_kit/http_client.rb +80 -0
- data/lib/freight_kit/package.rb +1 -1
- data/lib/freight_kit/package_item.rb +1 -1
- data/lib/freight_kit/platforms/carrier_logistics.rb +3 -3
- data/lib/freight_kit/platforms/next.rb +2 -2
- data/lib/freight_kit/platforms/the_great_information_factory.rb +1 -2
- data/lib/freight_kit.rb +12 -21
- metadata +102 -42
- data/freight_kit-0.1.18.gem +0 -0
- data/lib/freight_kit/api_clients.rb +0 -3
- data/lib/freight_kit/helpers.rb +0 -6
- data/lib/freight_kit/platforms.rb +0 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1e392cefbfa1b1c12e4d2e621d8d0dc1494c2430e5e0a09a7be19988160451d7
|
|
4
|
+
data.tar.gz: df5d3d666b1a2451743785fdb49d5e122bde1976213bd4d815b340ff3554e936
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 40759f132709d80e55ee140e8b95bcaa91d0f625a850ccc54d517ba38c068021b75844d42faa6bc4cd2f88ce1acb0affa0725174a4698da705a092faf1da4aa0
|
|
7
|
+
data.tar.gz: 7f4b01a90b460b075540b987973635fa9ea6e60c0fd740faad5e8de5f4d455922829382fe76341fe61fc9603f5c9c0f5087f791748046fbbd261779da5c40571
|
data/Gemfile.lock
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
freight_kit (0.1.
|
|
4
|
+
freight_kit (0.1.19)
|
|
5
5
|
active_utils (>= 3.3.1, < 3.7.0)
|
|
6
|
-
activemodel (>= 7.1, < 8.1.
|
|
7
|
-
activesupport (>= 7.1, < 8.1.
|
|
6
|
+
activemodel (>= 7.1, < 8.1.5)
|
|
7
|
+
activesupport (>= 7.1, < 8.1.5)
|
|
8
8
|
benchmark (~> 0.5.0)
|
|
9
9
|
business_time (~> 0.13.0)
|
|
10
10
|
httparty (~> 0.10)
|
|
@@ -12,11 +12,10 @@ PATH
|
|
|
12
12
|
mimemagic (~> 0.4.3)
|
|
13
13
|
nokogiri (>= 1.6, < 1.20)
|
|
14
14
|
place_kit (~> 0.0.6)
|
|
15
|
-
rmagick (>= 4.2.5, < 7.1.0)
|
|
16
15
|
savon (>= 2.17, < 2.18)
|
|
17
16
|
tzinfo-data (~> 1.2023, >= 1.2023.3)
|
|
18
17
|
watir (>= 7.0, < 7.4)
|
|
19
|
-
zeitwerk (>= 2.6.0, < 2.8.
|
|
18
|
+
zeitwerk (>= 2.6.0, < 2.8.4)
|
|
20
19
|
|
|
21
20
|
GEM
|
|
22
21
|
remote: https://rubygems.org/
|
|
@@ -39,20 +38,21 @@ GEM
|
|
|
39
38
|
mutex_m
|
|
40
39
|
securerandom (>= 0.3)
|
|
41
40
|
tzinfo (~> 2.0)
|
|
42
|
-
addressable (2.
|
|
43
|
-
public_suffix (>= 2.0.2, <
|
|
44
|
-
akami (1.3.
|
|
41
|
+
addressable (2.9.0)
|
|
42
|
+
public_suffix (>= 2.0.2, < 8.0)
|
|
43
|
+
akami (1.3.3)
|
|
44
|
+
base64
|
|
45
45
|
gyoku (>= 0.4.0)
|
|
46
46
|
nokogiri
|
|
47
|
-
ast (2.4.
|
|
47
|
+
ast (2.4.2)
|
|
48
48
|
base64 (0.3.0)
|
|
49
49
|
benchmark (0.5.0)
|
|
50
|
-
bigdecimal (
|
|
51
|
-
builder (3.
|
|
50
|
+
bigdecimal (3.3.1)
|
|
51
|
+
builder (3.3.0)
|
|
52
52
|
business_time (0.13.0)
|
|
53
53
|
activesupport (>= 3.2.0)
|
|
54
54
|
tzinfo
|
|
55
|
-
concurrent-ruby (1.
|
|
55
|
+
concurrent-ruby (1.3.6)
|
|
56
56
|
connection_pool (3.0.2)
|
|
57
57
|
csv (3.3.5)
|
|
58
58
|
date (3.5.1)
|
|
@@ -60,7 +60,7 @@ GEM
|
|
|
60
60
|
drb (2.2.3)
|
|
61
61
|
faker (3.8.0)
|
|
62
62
|
i18n (>= 1.8.11, < 2)
|
|
63
|
-
faraday (2.14.
|
|
63
|
+
faraday (2.14.2)
|
|
64
64
|
faraday-net_http (>= 2.0, < 3.5)
|
|
65
65
|
json
|
|
66
66
|
logger
|
|
@@ -77,12 +77,12 @@ GEM
|
|
|
77
77
|
mutex_m
|
|
78
78
|
nkf
|
|
79
79
|
rack (>= 2.0, < 4)
|
|
80
|
-
i18n (1.14.
|
|
80
|
+
i18n (1.14.8)
|
|
81
81
|
concurrent-ruby (~> 1.0)
|
|
82
|
-
json (2.
|
|
83
|
-
language_server-protocol (3.17.0.
|
|
82
|
+
json (2.7.2)
|
|
83
|
+
language_server-protocol (3.17.0.3)
|
|
84
84
|
logger (1.7.0)
|
|
85
|
-
mail (2.9.
|
|
85
|
+
mail (2.9.0)
|
|
86
86
|
logger
|
|
87
87
|
mini_mime (>= 0.1.1)
|
|
88
88
|
net-imap
|
|
@@ -94,13 +94,15 @@ GEM
|
|
|
94
94
|
nokogiri (~> 1)
|
|
95
95
|
rake
|
|
96
96
|
mini_mime (1.1.5)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
minitest (6.0.6)
|
|
98
|
+
drb (~> 2.0)
|
|
99
|
+
prism (~> 1.5)
|
|
100
|
+
multi_xml (0.7.1)
|
|
101
|
+
bigdecimal (~> 3.1)
|
|
100
102
|
mutex_m (0.3.0)
|
|
101
103
|
net-http (0.9.1)
|
|
102
104
|
uri (>= 0.11.1)
|
|
103
|
-
net-imap (0.6.4
|
|
105
|
+
net-imap (0.6.4)
|
|
104
106
|
date
|
|
105
107
|
net-protocol
|
|
106
108
|
net-pop (0.1.2)
|
|
@@ -109,32 +111,27 @@ GEM
|
|
|
109
111
|
timeout
|
|
110
112
|
net-smtp (0.5.1)
|
|
111
113
|
net-protocol
|
|
112
|
-
nkf (0.
|
|
113
|
-
nokogiri (1.
|
|
114
|
-
mini_portile2 (~> 2.8.0)
|
|
114
|
+
nkf (0.2.0)
|
|
115
|
+
nokogiri (1.19.3-arm64-darwin)
|
|
115
116
|
racc (~> 1.4)
|
|
116
|
-
nori (2.
|
|
117
|
-
|
|
118
|
-
parallel (1.
|
|
119
|
-
parser (3.3.
|
|
117
|
+
nori (2.7.1)
|
|
118
|
+
bigdecimal
|
|
119
|
+
parallel (1.25.1)
|
|
120
|
+
parser (3.3.2.0)
|
|
120
121
|
ast (~> 2.4.1)
|
|
121
122
|
racc
|
|
122
|
-
pkg-config (1.6.5)
|
|
123
123
|
place_kit (0.0.6)
|
|
124
124
|
activesupport (>= 7.1, < 8.1.4)
|
|
125
125
|
csv (~> 3.3)
|
|
126
126
|
prism (1.9.0)
|
|
127
|
-
public_suffix (
|
|
128
|
-
racc (1.
|
|
129
|
-
rack (3.
|
|
127
|
+
public_suffix (7.0.5)
|
|
128
|
+
racc (1.8.1)
|
|
129
|
+
rack (3.2.6)
|
|
130
130
|
rainbow (3.1.1)
|
|
131
131
|
rake (13.4.2)
|
|
132
132
|
redcarpet (3.6.0)
|
|
133
|
-
regexp_parser (2.
|
|
134
|
-
rexml (3.
|
|
135
|
-
rmagick (7.0.5)
|
|
136
|
-
observer (~> 0.1)
|
|
137
|
-
pkg-config (~> 1.4)
|
|
133
|
+
regexp_parser (2.9.0)
|
|
134
|
+
rexml (3.4.4)
|
|
138
135
|
rspec (3.12.0)
|
|
139
136
|
rspec-core (~> 3.12.0)
|
|
140
137
|
rspec-expectations (~> 3.12.0)
|
|
@@ -159,11 +156,10 @@ GEM
|
|
|
159
156
|
rubocop-ast (>= 1.31.1, < 2.0)
|
|
160
157
|
ruby-progressbar (~> 1.7)
|
|
161
158
|
unicode-display_width (>= 2.4.0, < 3.0)
|
|
162
|
-
rubocop-ast (1.
|
|
163
|
-
parser (>= 3.3.
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
rubocop (>= 1.50, < 2)
|
|
159
|
+
rubocop-ast (1.31.3)
|
|
160
|
+
parser (>= 3.3.1.0)
|
|
161
|
+
rubocop-graphql (1.5.2)
|
|
162
|
+
rubocop (>= 0.90, < 2)
|
|
167
163
|
rubocop-next (1.0.7)
|
|
168
164
|
rubocop (>= 1.56, < 1.65)
|
|
169
165
|
rubocop-graphql (>= 1.4, < 1.6)
|
|
@@ -171,14 +167,14 @@ GEM
|
|
|
171
167
|
rubocop-rake (~> 0.6.0)
|
|
172
168
|
rubocop-rspec (>= 2.23.2, < 3.1.0)
|
|
173
169
|
rubocop-shopify (>= 2.14, < 2.16)
|
|
174
|
-
rubocop-rails (2.25.
|
|
170
|
+
rubocop-rails (2.25.0)
|
|
175
171
|
activesupport (>= 4.2.0)
|
|
176
172
|
rack (>= 1.1)
|
|
177
173
|
rubocop (>= 1.33.0, < 2.0)
|
|
178
174
|
rubocop-ast (>= 1.31.1, < 2.0)
|
|
179
175
|
rubocop-rake (0.6.0)
|
|
180
176
|
rubocop (~> 1.0)
|
|
181
|
-
rubocop-rspec (3.0.
|
|
177
|
+
rubocop-rspec (3.0.1)
|
|
182
178
|
rubocop (~> 1.61)
|
|
183
179
|
rubocop-shopify (2.15.1)
|
|
184
180
|
rubocop (~> 1.51)
|
|
@@ -194,31 +190,34 @@ GEM
|
|
|
194
190
|
nori (~> 2.4)
|
|
195
191
|
wasabi (>= 5.1.0, < 6)
|
|
196
192
|
securerandom (0.4.1)
|
|
197
|
-
selenium-webdriver (4.
|
|
193
|
+
selenium-webdriver (4.16.0)
|
|
198
194
|
rexml (~> 3.2, >= 3.2.5)
|
|
199
195
|
rubyzip (>= 1.2.2, < 3.0)
|
|
200
196
|
websocket (~> 1.0)
|
|
201
197
|
timeout (0.6.1)
|
|
202
198
|
tzinfo (2.0.6)
|
|
203
199
|
concurrent-ruby (~> 1.0)
|
|
204
|
-
tzinfo-data (1.2023.
|
|
200
|
+
tzinfo-data (1.2023.3)
|
|
205
201
|
tzinfo (>= 1.0.0)
|
|
206
|
-
unicode-display_width (2.
|
|
202
|
+
unicode-display_width (2.5.0)
|
|
207
203
|
uri (1.1.1)
|
|
208
204
|
wasabi (5.1.0)
|
|
209
205
|
addressable
|
|
210
206
|
faraday (>= 1.9, < 3)
|
|
211
207
|
nokogiri (>= 1.13.9)
|
|
212
|
-
watir (7.
|
|
208
|
+
watir (7.3.0)
|
|
213
209
|
regexp_parser (>= 1.2, < 3)
|
|
214
|
-
selenium-webdriver (~> 4.
|
|
215
|
-
websocket (1.2.
|
|
210
|
+
selenium-webdriver (~> 4.2)
|
|
211
|
+
websocket (1.2.10)
|
|
216
212
|
yard (0.9.34)
|
|
217
|
-
zeitwerk (2.
|
|
213
|
+
zeitwerk (2.6.11)
|
|
218
214
|
|
|
219
215
|
PLATFORMS
|
|
220
216
|
arm64-darwin-22
|
|
217
|
+
arm64-darwin-23
|
|
218
|
+
arm64-darwin-24
|
|
221
219
|
arm64-darwin-25
|
|
220
|
+
arm64-darwin-27
|
|
222
221
|
|
|
223
222
|
DEPENDENCIES
|
|
224
223
|
faker (~> 3.8.0)
|
|
@@ -230,4 +229,4 @@ DEPENDENCIES
|
|
|
230
229
|
yard (~> 0.9.28)
|
|
231
230
|
|
|
232
231
|
BUNDLED WITH
|
|
233
|
-
|
|
232
|
+
4.0.23
|
data/README.md
CHANGED
|
@@ -65,6 +65,42 @@ Or standalone:
|
|
|
65
65
|
$ gem install freight_kit
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
+
## HTTP Client
|
|
69
|
+
|
|
70
|
+
FreightKit sends HTTP requests through `FreightKit::HTTPClient`, a wrapper around HTTPX. The client keeps connections open between requests, and it reuses HTTP/2 connections. If a connection fails, the client retries only idempotent requests, such as GET. It never retries a POST, because the carrier can already have processed it. The client asks carriers for Brotli, Zstandard, gzip, and deflate compression.
|
|
71
|
+
|
|
72
|
+
### Logging
|
|
73
|
+
|
|
74
|
+
The client writes request and response details at the debug level. By default it uses `Rails.logger`, or the Hanami app logger. Outside Rails and Hanami, it logs to standard output at the level in the `LOG_LEVEL` environment variable. The default level is `info`.
|
|
75
|
+
|
|
76
|
+
To use a different logger, set it at boot:
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
FreightKit::HTTPClient.logger = Logger.new($stdout, level: :debug)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Debug output contains request headers and bodies, which include carrier credentials. Do not use the debug level in production.
|
|
83
|
+
|
|
84
|
+
### Cache
|
|
85
|
+
|
|
86
|
+
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`.
|
|
87
|
+
|
|
88
|
+
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`.
|
|
89
|
+
|
|
90
|
+
In Rails, add this line to an initializer:
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
FreightKit::HTTPClient.cache = Rails.cache
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
In Hanami or plain Ruby, give any compatible store:
|
|
97
|
+
|
|
98
|
+
```ruby
|
|
99
|
+
FreightKit::HTTPClient.cache = ActiveSupport::Cache::RedisCacheStore.new(url: ENV.fetch('REDIS_URL'))
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
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`.
|
|
103
|
+
|
|
68
104
|
## Standard Usage
|
|
69
105
|
|
|
70
106
|
Start off by initializing a `Carrier`:
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.20
|
data/freight_kit.gemspec
CHANGED
|
@@ -33,24 +33,27 @@ Gem::Specification.new do |spec|
|
|
|
33
33
|
spec.add_development_dependency('rake', '~> 13.4.2')
|
|
34
34
|
spec.add_development_dependency('redcarpet', '~> 3.6.0') # for yard
|
|
35
35
|
spec.add_development_dependency('rspec', '~> 3.12')
|
|
36
|
-
spec.add_development_dependency('rubocop-next', '~> 1.0.
|
|
36
|
+
spec.add_development_dependency('rubocop-next', '~> 1.0.8')
|
|
37
37
|
spec.add_development_dependency('yard', '~> 0.9.28')
|
|
38
38
|
|
|
39
|
-
spec.add_dependency('activemodel', '>= 7.1', '< 8.1.
|
|
40
|
-
spec.add_dependency('activesupport', '>= 7.1', '< 8.1.
|
|
39
|
+
spec.add_dependency('activemodel', '>= 7.1', '< 8.1.5')
|
|
40
|
+
spec.add_dependency('activesupport', '>= 7.1', '< 8.1.5')
|
|
41
41
|
spec.add_dependency('active_utils', '>= 3.3.1', '< 3.7.0')
|
|
42
42
|
spec.add_dependency('benchmark', '~> 0.5.0')
|
|
43
|
+
spec.add_dependency('brotli', '>= 0.9.2', '< 1') # CVE-2026-111497
|
|
43
44
|
spec.add_dependency('business_time', '~> 0.13.0')
|
|
44
|
-
spec.add_dependency('
|
|
45
|
+
spec.add_dependency('httpx', '>= 1.9.0', '< 2')
|
|
46
|
+
spec.add_dependency('json', '< 3') # measured
|
|
45
47
|
spec.add_dependency('measured', '>= 2.0', '< 3.2.2')
|
|
46
48
|
spec.add_dependency('mimemagic', '~> 0.4.3')
|
|
49
|
+
spec.add_dependency('multi_xml', '>= 0.9.1', '< 1')
|
|
47
50
|
spec.add_dependency('nokogiri', '>= 1.6', '< 1.20')
|
|
48
51
|
spec.add_dependency('place_kit', '~> 0.0.6')
|
|
49
|
-
spec.add_dependency('rmagick', '>= 4.2.5', '< 7.2.0')
|
|
50
52
|
spec.add_dependency('savon', '>= 2.17', '< 2.18')
|
|
51
53
|
spec.add_dependency('tzinfo-data', '~> 1.2023', '>= 1.2023.3')
|
|
52
54
|
spec.add_dependency('watir', '>= 7.0', '< 7.4')
|
|
53
55
|
spec.add_dependency('zeitwerk', '>= 2.6.0', '< 2.8.4')
|
|
56
|
+
spec.add_dependency('zstd-ruby', '>= 2.0.10', '< 3') # bundles libzstd >= 1.5.4 (CVE-2022-4899)
|
|
54
57
|
|
|
55
|
-
spec.required_ruby_version = '>= 3.
|
|
58
|
+
spec.required_ruby_version = '>= 3.3.0'
|
|
56
59
|
end
|
|
@@ -124,9 +124,9 @@ module FreightKit
|
|
|
124
124
|
url = request[:url]
|
|
125
125
|
|
|
126
126
|
response = if method == :post
|
|
127
|
-
|
|
127
|
+
HTTPClient.post(url, headers:, body:)
|
|
128
128
|
else
|
|
129
|
-
|
|
129
|
+
HTTPClient.get(url, headers:)
|
|
130
130
|
end
|
|
131
131
|
|
|
132
132
|
response.deep_transform_keys! { |key| key.downcase.to_sym }[:abf] if response&.parsed_response
|
|
@@ -63,19 +63,13 @@ module FreightKit
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def commit(_action, request)
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
response = HTTParty.send(
|
|
66
|
+
response = HTTPClient.request(
|
|
69
67
|
request[:method],
|
|
70
68
|
request[:url],
|
|
71
69
|
headers: request[:headers].merge(JSON_HEADERS),
|
|
72
70
|
body: request[:body],
|
|
73
71
|
query: request[:query],
|
|
74
|
-
|
|
75
|
-
http_proxyport: proxy_uri.port.to_s,
|
|
76
|
-
http_proxyuser: proxy_uri.user,
|
|
77
|
-
http_proxypass: proxy_uri.password,
|
|
78
|
-
debug_output: $stdout,
|
|
72
|
+
proxy: request[:proxy_url],
|
|
79
73
|
)
|
|
80
74
|
|
|
81
75
|
unless response.code == 200
|
|
@@ -154,7 +148,6 @@ module FreightKit
|
|
|
154
148
|
service:,
|
|
155
149
|
shipment:
|
|
156
150
|
)
|
|
157
|
-
|
|
158
151
|
dispatcher_phone = dispatcher.phone.delete('^0-9')
|
|
159
152
|
receiver_phone = shipment.destination.contact.phone.delete('^0-9')
|
|
160
153
|
|
|
@@ -199,7 +199,7 @@ module FreightKit
|
|
|
199
199
|
sleep(50) # so Chrome can finish downloading, Selenoid default timeout is 60s
|
|
200
200
|
|
|
201
201
|
download_url = "#{selenoid_credential.selenoid_options[:download_url]}/#{browser.driver.session_id}"
|
|
202
|
-
response =
|
|
202
|
+
response = HTTPClient.get("#{download_url}/?json")
|
|
203
203
|
|
|
204
204
|
filename = URI.encode_www_form_component(JSON.parse(response.body)&.last)
|
|
205
205
|
url = "#{download_url}/#{filename}"
|
|
@@ -207,7 +207,7 @@ module FreightKit
|
|
|
207
207
|
document_response.request = URI.parse(url)
|
|
208
208
|
|
|
209
209
|
begin
|
|
210
|
-
response =
|
|
210
|
+
response = HTTPClient.get(url)
|
|
211
211
|
rescue StandardError => e
|
|
212
212
|
document_response.error = e
|
|
213
213
|
return document_response
|
|
@@ -102,9 +102,9 @@ module FreightKit
|
|
|
102
102
|
|
|
103
103
|
response = case method
|
|
104
104
|
when :post
|
|
105
|
-
|
|
105
|
+
HTTPClient.post(url, headers:, body:)
|
|
106
106
|
else
|
|
107
|
-
|
|
107
|
+
HTTPClient.get(url, headers:)
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
begin
|
|
@@ -292,7 +292,7 @@ module FreightKit
|
|
|
292
292
|
days = if comment.blank?
|
|
293
293
|
nil
|
|
294
294
|
else
|
|
295
|
-
comment
|
|
295
|
+
comment[/(\d+) days/, 1]&.to_i
|
|
296
296
|
end
|
|
297
297
|
|
|
298
298
|
expires_at = if days.is_a?(Integer) && days.positive?
|
|
@@ -165,7 +165,7 @@ module FreightKit
|
|
|
165
165
|
sleep(10) # so Chrome can finish downloading
|
|
166
166
|
|
|
167
167
|
download_url = "#{selenoid_credential.selenoid_options[:download_url]}/#{browser.driver.session_id}"
|
|
168
|
-
response =
|
|
168
|
+
response = HTTPClient.get("#{download_url}/?json")
|
|
169
169
|
|
|
170
170
|
filename = URI.encode_www_form_component(JSON.parse(response.body)&.last)
|
|
171
171
|
url = "#{download_url}/#{filename}"
|
|
@@ -173,7 +173,7 @@ module FreightKit
|
|
|
173
173
|
document_response.request = URI.parse(url)
|
|
174
174
|
|
|
175
175
|
begin
|
|
176
|
-
response =
|
|
176
|
+
response = HTTPClient.get(url)
|
|
177
177
|
rescue StandardError => e
|
|
178
178
|
document_response.error = e
|
|
179
179
|
return document_response
|
|
@@ -223,11 +223,9 @@ module FreightKit
|
|
|
223
223
|
|
|
224
224
|
accessorials = accessorials.uniq.join(',')
|
|
225
225
|
|
|
226
|
-
shipment_detail =
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
end
|
|
230
|
-
shipment_detail = shipment_detail.join('|')
|
|
226
|
+
shipment_detail = shipment.packages.map do |package|
|
|
227
|
+
[package.quantity, package.freight_class, package.pounds(:total)].join('|')
|
|
228
|
+
end.join('|')
|
|
231
229
|
|
|
232
230
|
api_credentials = fetch_credential(:api)
|
|
233
231
|
|
|
@@ -386,7 +384,7 @@ module FreightKit
|
|
|
386
384
|
country = ActiveUtils::Country.find('USA')
|
|
387
385
|
|
|
388
386
|
shipper_location = Location.new(
|
|
389
|
-
address1: search_result[:shipperaddress]&.squish&.
|
|
387
|
+
address1: search_result[:shipperaddress]&.squish&.titleize,
|
|
390
388
|
city: search_result[:shipper_city].squish.strip.titleize,
|
|
391
389
|
province: search_result[:shipper_state].strip.upcase,
|
|
392
390
|
postal_code: search_result[:shipper_zip].strip,
|
|
@@ -394,7 +392,7 @@ module FreightKit
|
|
|
394
392
|
)
|
|
395
393
|
|
|
396
394
|
receiver_location = Location.new(
|
|
397
|
-
address1: search_result[:consaddress]&.squish&.
|
|
395
|
+
address1: search_result[:consaddress]&.squish&.titleize,
|
|
398
396
|
city: search_result[:cons_city].squish.strip.titleize,
|
|
399
397
|
province: search_result[:cons_state].strip.upcase,
|
|
400
398
|
postal_code: search_result[:cons_zip].strip,
|
|
@@ -126,9 +126,9 @@ module FreightKit
|
|
|
126
126
|
|
|
127
127
|
case method
|
|
128
128
|
when :post
|
|
129
|
-
|
|
129
|
+
HTTPClient.post(url, headers:, body:)
|
|
130
130
|
else
|
|
131
|
-
|
|
131
|
+
HTTPClient.get(url, headers:)
|
|
132
132
|
end
|
|
133
133
|
end
|
|
134
134
|
|
|
@@ -222,7 +222,8 @@ module FreightKit
|
|
|
222
222
|
rescue Selenium::WebDriver::Error::UnexpectedAlertOpenError => e
|
|
223
223
|
browser.close
|
|
224
224
|
|
|
225
|
-
message = e.message[/{(.*?)}/m, 1]&.split(':')&.last
|
|
225
|
+
message = e.message[/{(.*?)}/m, 1]&.split(':')&.last
|
|
226
|
+
message = message&.squish
|
|
226
227
|
|
|
227
228
|
document_response.error = InvalidCredentialsError.new(message)
|
|
228
229
|
return document_response
|
|
@@ -299,7 +300,7 @@ module FreightKit
|
|
|
299
300
|
end
|
|
300
301
|
|
|
301
302
|
begin
|
|
302
|
-
response =
|
|
303
|
+
response = HTTPClient.get(url)
|
|
303
304
|
rescue StandardError => e
|
|
304
305
|
document_response.error = e
|
|
305
306
|
return document_response
|
|
@@ -472,20 +473,19 @@ module FreightKit
|
|
|
472
473
|
def build_rate_request(shipment:)
|
|
473
474
|
accessorials = build_accessorials(shipment:)
|
|
474
475
|
|
|
475
|
-
items =
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
}
|
|
476
|
+
items = shipment.packages.map do |package|
|
|
477
|
+
{
|
|
478
|
+
Name: package.description,
|
|
479
|
+
FreightClass: package.freight_class.to_s,
|
|
480
|
+
Weight: package.pounds(:total).ceil.to_s,
|
|
481
|
+
WeightUnits: 'lb',
|
|
482
|
+
Width: package.width(:in).ceil,
|
|
483
|
+
Length: package.length(:in).ceil,
|
|
484
|
+
Height: package.height(:in).ceil,
|
|
485
|
+
DimensionUnits: 'in',
|
|
486
|
+
Quantity: package.quantity,
|
|
487
|
+
QuantityUnits: 'PLT' # Check this
|
|
488
|
+
}
|
|
489
489
|
end
|
|
490
490
|
|
|
491
491
|
pickup_event_date = shipment.pickup_at.date_time_with_zone
|
|
@@ -293,9 +293,9 @@ module FreightKit
|
|
|
293
293
|
|
|
294
294
|
response = case method
|
|
295
295
|
when :post
|
|
296
|
-
|
|
296
|
+
HTTPClient.post(url, headers:, body:)
|
|
297
297
|
else
|
|
298
|
-
|
|
298
|
+
HTTPClient.get(url, headers:)
|
|
299
299
|
end
|
|
300
300
|
|
|
301
301
|
if (200..299).exclude?(response.code)
|
|
@@ -308,7 +308,7 @@ module FreightKit
|
|
|
308
308
|
raise FreightKit::ResponseError, message
|
|
309
309
|
end
|
|
310
310
|
|
|
311
|
-
return response if response.
|
|
311
|
+
return response if response.content_type != 'application/json'
|
|
312
312
|
|
|
313
313
|
json = JSON.parse(response.body)
|
|
314
314
|
error = json.is_a?(Array) ? nil : json['errorMessage']
|
|
@@ -166,9 +166,9 @@ module FreightKit
|
|
|
166
166
|
|
|
167
167
|
response = case method
|
|
168
168
|
when :post
|
|
169
|
-
|
|
169
|
+
HTTPClient.post(url, headers:, body:)
|
|
170
170
|
else
|
|
171
|
-
|
|
171
|
+
HTTPClient.get(url, headers:)
|
|
172
172
|
end
|
|
173
173
|
|
|
174
174
|
response.parsed_response if response&.parsed_response
|
|
@@ -201,7 +201,6 @@ module FreightKit
|
|
|
201
201
|
service:,
|
|
202
202
|
shipment:
|
|
203
203
|
)
|
|
204
|
-
|
|
205
204
|
dispatcher_phone = dispatcher.phone.sub('+1', '').delete('^0-9')
|
|
206
205
|
|
|
207
206
|
raise UnserviceableError, 'Palletized freight unsupported' unless shipment.loose?
|
|
@@ -242,7 +241,6 @@ module FreightKit
|
|
|
242
241
|
service:,
|
|
243
242
|
shipment:
|
|
244
243
|
)
|
|
245
|
-
|
|
246
244
|
dispatcher_phone = dispatcher.phone.sub('+1', '').delete('^0-9')
|
|
247
245
|
receiver_phone = shipment.destination.contact.phone.sub('+1', '').delete('^0-9')
|
|
248
246
|
|
|
@@ -379,13 +377,7 @@ module FreightKit
|
|
|
379
377
|
base64_labels = api_shipments&.map { |s| s['Label'] }
|
|
380
378
|
raise FreightKit::ResponseError, 'API Error: Blank label' if base64_labels.blank?
|
|
381
379
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
base64_labels.each do |base64_label|
|
|
385
|
-
labels << Label.new(data: base64_label)
|
|
386
|
-
end
|
|
387
|
-
|
|
388
|
-
labels
|
|
380
|
+
base64_labels.map { |base64_label| Label.new(data: base64_label) }
|
|
389
381
|
end
|
|
390
382
|
|
|
391
383
|
# Rates
|
|
@@ -431,7 +423,7 @@ module FreightKit
|
|
|
431
423
|
parts << "ID#{i}"
|
|
432
424
|
parts << shipment.origin.postal_code
|
|
433
425
|
parts << shipment.destination.postal_code
|
|
434
|
-
parts << shipment.accessorials.include?(:residential_delivery)
|
|
426
|
+
parts << shipment.accessorials.include?(:residential_delivery).to_s
|
|
435
427
|
parts << '0'
|
|
436
428
|
parts << 'false' # Staurday delivery
|
|
437
429
|
parts << declared_value
|
|
@@ -229,10 +229,8 @@ module FreightKit
|
|
|
229
229
|
rate_accessorial_items = result.dig(:rate_accessorials, :rate_accessorial_item)
|
|
230
230
|
rate_accessorial_items = [rate_accessorial_items] if rate_accessorial_items.is_a?(Hash)
|
|
231
231
|
|
|
232
|
-
prices =
|
|
233
|
-
|
|
234
|
-
rate_accessorial_items.each do |rate_accessorial_item|
|
|
235
|
-
prices << Price.new(
|
|
232
|
+
prices = rate_accessorial_items.map do |rate_accessorial_item|
|
|
233
|
+
Price.new(
|
|
236
234
|
blame: :api,
|
|
237
235
|
cents: (rate_accessorial_item[:amount].to_f * 100).to_i,
|
|
238
236
|
description: rate_accessorial_item[:description]&.titleize&.squish,
|
|
@@ -352,7 +350,7 @@ module FreightKit
|
|
|
352
350
|
|
|
353
351
|
shipper_location = Location.new(
|
|
354
352
|
address1:,
|
|
355
|
-
city: search_result.dig(:shipper, :city)&.squish&.
|
|
353
|
+
city: search_result.dig(:shipper, :city)&.squish&.titleize,
|
|
356
354
|
province: search_result.dig(:shipper, :state)&.strip&.upcase,
|
|
357
355
|
postal_code: search_result.dig(:shipper, :zipcode)&.strip,
|
|
358
356
|
country: ActiveUtils::Country.find('USA'),
|
|
@@ -368,7 +366,7 @@ module FreightKit
|
|
|
368
366
|
|
|
369
367
|
receiver_location = Location.new(
|
|
370
368
|
address1:,
|
|
371
|
-
city: search_result.dig(:consignee, :city)&.squish&.
|
|
369
|
+
city: search_result.dig(:consignee, :city)&.squish&.titleize,
|
|
372
370
|
province: search_result.dig(:consignee, :state)&.strip&.upcase,
|
|
373
371
|
postal_code: search_result.dig(:consignee, :zipcode)&.strip,
|
|
374
372
|
country: ActiveUtils::Country.find('USA'),
|
|
@@ -58,13 +58,12 @@ module FreightKit
|
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def commit(request)
|
|
61
|
-
response =
|
|
61
|
+
response = HTTPClient.request(
|
|
62
62
|
request[:method],
|
|
63
63
|
request[:url],
|
|
64
64
|
headers: request[:headers].merge(subscription_key_headers),
|
|
65
65
|
query: request[:query],
|
|
66
66
|
body: request[:body],
|
|
67
|
-
debug_output: $stdout,
|
|
68
67
|
)
|
|
69
68
|
|
|
70
69
|
parsed_response = JSON.parse(response.body)
|
|
@@ -184,7 +183,6 @@ module FreightKit
|
|
|
184
183
|
service:,
|
|
185
184
|
shipment:
|
|
186
185
|
)
|
|
187
|
-
|
|
188
186
|
origin = shipment.origin
|
|
189
187
|
destination = shipment.destination
|
|
190
188
|
shipper_phone = shipment.origin.contact.phone.delete('^0-9')
|