truenorth 0.2.5 → 0.2.7
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/lib/truenorth/cli.rb +58 -1
- data/lib/truenorth/client.rb +37 -5
- data/lib/truenorth/version.rb +1 -1
- data/truenorth.gemspec +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: 131d576fcb2ae365a296327ed2d3a56f40bea4bc6d56cd71457885b92a973f72
|
|
4
|
+
data.tar.gz: 84955a3b673d18bbed8b7d2cb07a5d7e334cfc53350236c3018e8247bfe34018
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d855f7fd99a257b1634f26b3b1d2c318d64ad727189a87b0f3d958673f3422ec8db13837ec0ecd197353a8c8e235c209d152f4802272aeb8fc0751c78eaa1288
|
|
7
|
+
data.tar.gz: 3bcab5c590187397b26e9c0bbe95ee9d3023e8dbfddd761b0a01d87f37592dc9a64319f19fe94cef59094adc6cb74d206bbcb483aa63cc4271b7895ebbb7fa09
|
data/lib/truenorth/cli.rb
CHANGED
|
@@ -97,6 +97,12 @@ module Truenorth
|
|
|
97
97
|
end
|
|
98
98
|
rescue Error => e
|
|
99
99
|
say "Error: #{e.message}", :red
|
|
100
|
+
|
|
101
|
+
# If no slot available, show nearby available times
|
|
102
|
+
if e.message.include?('No slot available')
|
|
103
|
+
show_nearby_availability(client, date, time, activity)
|
|
104
|
+
end
|
|
105
|
+
|
|
100
106
|
exit 1
|
|
101
107
|
end
|
|
102
108
|
|
|
@@ -145,8 +151,9 @@ module Truenorth
|
|
|
145
151
|
desc 'cancel INDEX', 'Cancel a reservation by index (from reservations list)'
|
|
146
152
|
option :dry_run, type: :boolean, aliases: '-n', desc: 'Test without actually canceling'
|
|
147
153
|
option :all, type: :boolean, aliases: '-a', desc: 'Cancel from full list (use with --all view)'
|
|
154
|
+
option :debug, type: :boolean, desc: 'Show debug output'
|
|
148
155
|
def cancel(index)
|
|
149
|
-
client = Client.new
|
|
156
|
+
client = Client.new(debug: options[:debug])
|
|
150
157
|
|
|
151
158
|
say 'Fetching reservations...', :cyan
|
|
152
159
|
results = client.reservations
|
|
@@ -225,6 +232,56 @@ module Truenorth
|
|
|
225
232
|
|
|
226
233
|
private
|
|
227
234
|
|
|
235
|
+
def show_nearby_availability(client, date, requested_time, activity)
|
|
236
|
+
say "\nChecking available times for #{date}...", :cyan
|
|
237
|
+
|
|
238
|
+
begin
|
|
239
|
+
result = client.availability(date, activity: activity)
|
|
240
|
+
|
|
241
|
+
if result[:slots].empty?
|
|
242
|
+
say "No #{activity} slots available on #{date}", :yellow
|
|
243
|
+
else
|
|
244
|
+
say "\nAvailable #{activity} times:", :green
|
|
245
|
+
|
|
246
|
+
# Parse requested time to find nearby slots
|
|
247
|
+
requested_hour = parse_time_to_minutes(requested_time)
|
|
248
|
+
|
|
249
|
+
# Sort slots by proximity to requested time
|
|
250
|
+
sorted_slots = result[:slots].sort_by do |time_str, _courts|
|
|
251
|
+
slot_minutes = parse_time_to_minutes(time_str)
|
|
252
|
+
(slot_minutes - requested_hour).abs
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
# Show up to 10 nearest slots
|
|
256
|
+
sorted_slots.first(10).each do |time_str, courts|
|
|
257
|
+
say " #{time_str}: #{courts.join(', ')}"
|
|
258
|
+
end
|
|
259
|
+
|
|
260
|
+
if result[:slots].length > 10
|
|
261
|
+
say "\n ... and #{result[:slots].length - 10} more times", :cyan
|
|
262
|
+
end
|
|
263
|
+
end
|
|
264
|
+
rescue Error => e
|
|
265
|
+
say "Could not fetch availability: #{e.message}", :yellow
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
def parse_time_to_minutes(time_str)
|
|
270
|
+
# Convert "10:00 AM" or "10am" to minutes since midnight
|
|
271
|
+
if time_str =~ /(\d{1,2}):?(\d{2})?\s*(am|pm)/i
|
|
272
|
+
hour = ::Regexp.last_match(1).to_i
|
|
273
|
+
minute = ::Regexp.last_match(2)&.to_i || 0
|
|
274
|
+
period = ::Regexp.last_match(3).upcase
|
|
275
|
+
|
|
276
|
+
hour = 0 if hour == 12 && period == 'AM'
|
|
277
|
+
hour += 12 if period == 'PM' && hour != 12
|
|
278
|
+
|
|
279
|
+
hour * 60 + minute
|
|
280
|
+
else
|
|
281
|
+
0
|
|
282
|
+
end
|
|
283
|
+
end
|
|
284
|
+
|
|
228
285
|
def display_reservations_table(results)
|
|
229
286
|
# Get terminal width
|
|
230
287
|
term_width = begin
|
data/lib/truenorth/client.rb
CHANGED
|
@@ -302,14 +302,46 @@ module Truenorth
|
|
|
302
302
|
response = post_ajax(ajax_url, form_data)
|
|
303
303
|
|
|
304
304
|
if response.is_a?(Net::HTTPSuccess)
|
|
305
|
-
# Check for success indicators in response
|
|
306
305
|
body = response.body
|
|
307
|
-
|
|
308
|
-
|
|
306
|
+
|
|
307
|
+
# Log response for debugging
|
|
308
|
+
log "Response length: #{body.length}"
|
|
309
|
+
log "Response preview: #{body[0..500]}"
|
|
310
|
+
|
|
311
|
+
# Check for specific PrimeFaces success indicators
|
|
312
|
+
# Look for actual cancellation confirmation messages
|
|
313
|
+
success_indicators = [
|
|
314
|
+
/cancelled.*successfully/i,
|
|
315
|
+
/reservation.*cancelled/i,
|
|
316
|
+
/successfully.*cancelled/i,
|
|
317
|
+
/<update.*id=".*growl"/i # PrimeFaces growl messages usually indicate success/error
|
|
318
|
+
]
|
|
319
|
+
|
|
320
|
+
# Check for error indicators
|
|
321
|
+
error_indicators = [
|
|
322
|
+
/error/i,
|
|
323
|
+
/failed/i,
|
|
324
|
+
/unable/i,
|
|
325
|
+
/cannot.*cancel/i
|
|
326
|
+
]
|
|
327
|
+
|
|
328
|
+
has_error = error_indicators.any? { |pattern| body =~ pattern }
|
|
329
|
+
has_success = success_indicators.any? { |pattern| body =~ pattern }
|
|
330
|
+
|
|
331
|
+
if has_error
|
|
332
|
+
# Extract error message if present
|
|
333
|
+
error_msg = body[/error[^<]*|failed[^<]*/i] || 'Cancellation may have failed'
|
|
334
|
+
log "Error detected: #{error_msg}"
|
|
335
|
+
{ success: false, error: error_msg }
|
|
336
|
+
elsif has_success || body.length < 500
|
|
337
|
+
# Very short response likely means success (no error message)
|
|
338
|
+
log 'Cancellation appears successful'
|
|
309
339
|
{ success: true, message: 'Reservation cancelled' }
|
|
310
340
|
else
|
|
311
|
-
log
|
|
312
|
-
|
|
341
|
+
# Ambiguous - log full response for analysis
|
|
342
|
+
log "Ambiguous response (#{body.length} bytes)"
|
|
343
|
+
log "Full response: #{body}"
|
|
344
|
+
{ success: false, error: 'Uncertain if cancellation succeeded - please verify' }
|
|
313
345
|
end
|
|
314
346
|
else
|
|
315
347
|
{ success: false, error: "HTTP #{response.code}" }
|
data/lib/truenorth/version.rb
CHANGED
data/truenorth.gemspec
CHANGED