freight_kit 0.1.32 → 0.1.34
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/VERSION +1 -1
- data/lib/freight_kit/carriers/best_overnite_express.rb +1 -0
- data/lib/freight_kit/carriers/numark_transportation.rb +4 -1
- data/lib/freight_kit/carriers/stg.rb +70 -1
- data/lib/freight_kit/carriers/western_regional_delivery_service.rb +13 -11
- data/lib/freight_kit/platforms/the_great_information_factory.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4522fdf8cf8f10256946894b1f170a010a0fbca0f31e59bde4dd7911596142e6
|
|
4
|
+
data.tar.gz: c12f00b6c32d934aba2b22e1da9399940f06152ee6c8fe84146c39e98662d0fd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8c01c2283acf775a73afb16df0c068c56b868cab9655150ea4e0ae13a6e47be16a04428f4439135be0f0bf538263f4dcf4d9a89abe4772dd5a67243d8eff7d4c
|
|
7
|
+
data.tar.gz: 638901575460f6df3d07be5ba785ff3712fb27f5b098b5bbe2dc372bc3ec7cff37f0d112072fcbf5c7ec3ce9be0c7aaffc1b879e2d3d3c94e13c765a78ecdfa6
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.1.
|
|
1
|
+
0.1.34
|
|
@@ -71,6 +71,7 @@ module FreightKit
|
|
|
71
71
|
'LA': { city: 'Los Angeles', province: 'CA', state: 'CA' },
|
|
72
72
|
'MGUL': { city: 'Denver', province: 'CO', state: 'CO' },
|
|
73
73
|
'PDX': { city: 'Portland', province: 'OR', state: 'OR' },
|
|
74
|
+
'RED': { city: 'Redding', province: 'CA', state: 'CA' },
|
|
74
75
|
'SAC': { city: 'Sacramento', province: 'CA', state: 'CA' },
|
|
75
76
|
'SJ': { city: 'San Jose', province: 'CA', state: 'CA' },
|
|
76
77
|
'SLC': { city: 'Salt Lake City', province: 'UT', state: 'UT' }
|
|
@@ -59,7 +59,10 @@ module FreightKit
|
|
|
59
59
|
EVENTS = Platforms::TheGreatInformationFactory::EVENTS.deep_merge(
|
|
60
60
|
locations: {
|
|
61
61
|
'45': { city: 'Fresno', province: 'CA', state: 'CA' },
|
|
62
|
-
'
|
|
62
|
+
'55': { city: 'Stockton', province: 'CA', state: 'CA' },
|
|
63
|
+
'75': { city: 'San Leandro', province: 'CA', state: 'CA' },
|
|
64
|
+
'85': { city: 'Vernon', province: 'CA', state: 'CA' },
|
|
65
|
+
'96': { city: 'Phoenix', province: 'AZ', state: 'AZ' }
|
|
63
66
|
}
|
|
64
67
|
).freeze
|
|
65
68
|
|
|
@@ -129,7 +129,14 @@ module FreightKit
|
|
|
129
129
|
end
|
|
130
130
|
end
|
|
131
131
|
|
|
132
|
-
API = Platforms::CarrierLogistics::API.deep_merge(
|
|
132
|
+
API = Platforms::CarrierLogistics::API.deep_merge(
|
|
133
|
+
carrier_code: 'fro',
|
|
134
|
+
endpoints: { notes: '/scripts/@CARRIER_CODE@.pol/boldetail.htm?' },
|
|
135
|
+
use_ssl: { notes: true }
|
|
136
|
+
).freeze
|
|
137
|
+
NOTE = %r{\A(?<date_time>\d{2}/\d{2}/\d{4} \d{2}:\d{2}) (?<text>.+)\z}
|
|
138
|
+
NOTE_LOCATED = /\ALINE HAUL UNIT CURRENT LOCATION IS (?<city_state>[A-Z][A-Z .'-]*, [A-Z]{2})\b/
|
|
139
|
+
NOTE_TERMINAL = /\A(?:AVAILABLE|COMPLETED TRANSFER) (?<city_state>[A-Z][A-Z .'-]*, [A-Z]{2})\b/
|
|
133
140
|
|
|
134
141
|
# Documents
|
|
135
142
|
|
|
@@ -153,8 +160,70 @@ module FreightKit
|
|
|
153
160
|
|
|
154
161
|
# Tracking
|
|
155
162
|
|
|
163
|
+
# @return [Array<Array(String, String)>] Each note's local date/time and text, oldest first.
|
|
164
|
+
def fetch_notes(tracking_number)
|
|
165
|
+
url = build_url(:notes, query: { language: 'ENGLISH', wbtn: 'PRO', wpro1: tracking_number })
|
|
166
|
+
cell = Nokogiri::HTML(HTTPClient.get(url, proxy_url:).body).at('th:contains("Notes:") + td')
|
|
167
|
+
return [] if cell.nil?
|
|
168
|
+
|
|
169
|
+
notes = cell.xpath('text()').filter_map do |node|
|
|
170
|
+
match = NOTE.match(node.text.squish)
|
|
171
|
+
[::Time.strptime(match[:date_time], '%m/%d/%Y %H:%M').to_fs(:db), match[:text]] if match
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
notes.reverse
|
|
175
|
+
rescue HTTPX::Error
|
|
176
|
+
[]
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def parse_tracking_response(tracking_number, response:)
|
|
180
|
+
tracking_response = super
|
|
181
|
+
return tracking_response if tracking_response.error.present?
|
|
182
|
+
|
|
183
|
+
notes = fetch_notes(tracking_number)
|
|
184
|
+
locate_arrivals(tracking_response.shipment_events, notes)
|
|
185
|
+
|
|
186
|
+
shipment_events = tracking_response.shipment_events + parse_located_events(notes)
|
|
187
|
+
if shipment_events.all? { |event| event.date_time&.date_time_with_zone }
|
|
188
|
+
shipment_events.sort_by! { |event| event.date_time.date_time_with_zone }
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
tracking_response.shipment_events = shipment_events
|
|
192
|
+
tracking_response
|
|
193
|
+
end
|
|
194
|
+
|
|
156
195
|
# protected
|
|
157
196
|
|
|
197
|
+
def locate_arrivals(shipment_events, notes)
|
|
198
|
+
shipment_events.each do |event|
|
|
199
|
+
next if event.type_code != :arrived_at_terminal || event.location.present? || event.date_time.blank?
|
|
200
|
+
|
|
201
|
+
local_date_time = event.date_time.local_date_time
|
|
202
|
+
terminal = notes.lazy.filter_map do |note_date_time, text|
|
|
203
|
+
NOTE_TERMINAL.match(text) if note_date_time.to_date >= local_date_time.to_date
|
|
204
|
+
end.first
|
|
205
|
+
next if terminal.nil?
|
|
206
|
+
|
|
207
|
+
event.location = parse_api_city_state(terminal[:city_state])
|
|
208
|
+
event.date_time = ::FreightKit::DateTime.new(local_date_time:, location: event.location)
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
def parse_located_events(notes)
|
|
213
|
+
events = notes.filter_map do |local_date_time, text|
|
|
214
|
+
match = NOTE_LOCATED.match(text)
|
|
215
|
+
next if match.nil?
|
|
216
|
+
|
|
217
|
+
location = parse_api_city_state(match[:city_state])
|
|
218
|
+
date_time = ::FreightKit::DateTime.new(local_date_time:, location:)
|
|
219
|
+
next if date_time.date_time_with_zone.nil?
|
|
220
|
+
|
|
221
|
+
ShipmentEvent.new(date_time:, location:, type_code: :located)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
events.chunk_while { |a, b| [a.location.city, a.location.province] == [b.location.city, b.location.province] }.map(&:first)
|
|
225
|
+
end
|
|
226
|
+
|
|
158
227
|
# Documents
|
|
159
228
|
|
|
160
229
|
# Rates
|
|
@@ -66,7 +66,6 @@ module FreightKit
|
|
|
66
66
|
domain: 'tracking.wrds.com',
|
|
67
67
|
endpoints: { documents: '/zDocImages.aspx', login: '/zLogin.aspx', track: '/zTrack2.aspx' }
|
|
68
68
|
}.freeze
|
|
69
|
-
DOCUMENT_INDEXES = { bol: 0..0, pod: 2.. }.freeze
|
|
70
69
|
EVENTS = {
|
|
71
70
|
types: {
|
|
72
71
|
arrived_at_terminal: 'arrived',
|
|
@@ -91,23 +90,26 @@ module FreightKit
|
|
|
91
90
|
|
|
92
91
|
protected
|
|
93
92
|
|
|
93
|
+
def dock
|
|
94
|
+
headquarters = self.class.headquarters
|
|
95
|
+
|
|
96
|
+
Location.new(city: headquarters.city, country: ActiveUtils::Country.find('USA'), province: headquarters.region_abbreviation)
|
|
97
|
+
end
|
|
98
|
+
|
|
94
99
|
def document(type, tracking_number)
|
|
95
100
|
document_response = DocumentResponse.new(request: { tracking_number:, type: })
|
|
96
101
|
cookies = HTTPClient.cookie_jar
|
|
97
102
|
details = search(cookies, log_in(cookies), tracking_number)
|
|
98
|
-
|
|
103
|
+
available = details&.at('a[href*="btnImageYes"]').present? && (type == :bol || details.at('#cphMain_lblActDelivery')&.text.present?)
|
|
104
|
+
return document_response.tap { |item| item.error = DocumentNotFoundError.new } unless available
|
|
99
105
|
|
|
100
106
|
submit(cookies, details, '__EVENTTARGET' => 'ctl00$cphMain$btnImageYes')
|
|
101
107
|
viewer = fetch(cookies, request_url(:documents))
|
|
102
|
-
|
|
103
|
-
return document_response.tap { |item| item.error = DocumentNotFoundError.new } if
|
|
104
|
-
|
|
105
|
-
parts = (0..indexes.max).filter_map do |index|
|
|
106
|
-
viewer = submit(cookies, viewer, 'ctl00$cphMain$btnNext' => 'Next') if index.positive?
|
|
107
|
-
download(cookies, viewer.at('#cphMain_imgImage')['src']) if indexes.include?(index)
|
|
108
|
-
end
|
|
108
|
+
count = viewer.at('#cphMain_lblAmount').text.to_i
|
|
109
|
+
return document_response.tap { |item| item.error = DocumentNotFoundError.new } if count < (type == :pod ? 2 : 1)
|
|
109
110
|
|
|
110
|
-
|
|
111
|
+
(type == :pod ? count - 1 : 0).times { viewer = submit(cookies, viewer, 'ctl00$cphMain$btnNext' => 'Next') }
|
|
112
|
+
document_response.tap { |item| item.parts = [download(cookies, viewer.at('#cphMain_imgImage')['src'])] }
|
|
111
113
|
end
|
|
112
114
|
|
|
113
115
|
def download(cookies, path)
|
|
@@ -179,7 +181,7 @@ module FreightKit
|
|
|
179
181
|
|
|
180
182
|
location = unless type_code == :delivery_appointment_scheduled
|
|
181
183
|
city_state = event.downcase.split(text).last.delete(',')
|
|
182
|
-
|
|
184
|
+
city_state.include?('carrier') ? dock : parse_api_city_state(city_state)
|
|
183
185
|
end
|
|
184
186
|
|
|
185
187
|
ShipmentEvent.new(date_time: parse_api_date_time(date_time, location), location:, type_code:)
|
|
@@ -533,7 +533,7 @@ module FreightKit
|
|
|
533
533
|
|
|
534
534
|
break if next_api_event.blank?
|
|
535
535
|
|
|
536
|
-
if next_api_event[:description]
|
|
536
|
+
if next_api_event[:description]&.include?('INTERLINE') && next_api_event[:date] == api_event[:date]
|
|
537
537
|
shipment_events << ShipmentEvent.new(date_time:, location:, type_code: :departed)
|
|
538
538
|
next
|
|
539
539
|
end
|