freight_kit 0.1.33 → 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 +7 -1
- 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
|
|
@@ -90,6 +90,12 @@ module FreightKit
|
|
|
90
90
|
|
|
91
91
|
protected
|
|
92
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
|
+
|
|
93
99
|
def document(type, tracking_number)
|
|
94
100
|
document_response = DocumentResponse.new(request: { tracking_number:, type: })
|
|
95
101
|
cookies = HTTPClient.cookie_jar
|
|
@@ -175,7 +181,7 @@ module FreightKit
|
|
|
175
181
|
|
|
176
182
|
location = unless type_code == :delivery_appointment_scheduled
|
|
177
183
|
city_state = event.downcase.split(text).last.delete(',')
|
|
178
|
-
|
|
184
|
+
city_state.include?('carrier') ? dock : parse_api_city_state(city_state)
|
|
179
185
|
end
|
|
180
186
|
|
|
181
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
|