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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63c9a467b51f61d550f8c48a37109dbc647d5b599044beffc55333f0bade9e48
4
- data.tar.gz: 12211afbaf407921821f41c2cddcc9c9581ad9e6f8e1ffef20ef83a8ec6df91e
3
+ metadata.gz: 131d576fcb2ae365a296327ed2d3a56f40bea4bc6d56cd71457885b92a973f72
4
+ data.tar.gz: 84955a3b673d18bbed8b7d2cb07a5d7e334cfc53350236c3018e8247bfe34018
5
5
  SHA512:
6
- metadata.gz: 2c0538cf12be2ff1a20f5950206b381537683bf3e5cfe87ee9895e7fe677154bebbd636df6837ed3ad0a136018060f982f697d875d456e1402cc4ef4d57e161a
7
- data.tar.gz: 7874967a9ce9b6a7342e82ca8a5346dbd1fc0ccfe87a099dbeda0ac0201e9765ea9a8fbe3a36f8e9eff1eece1fb4ac12719f8ff5eb9777da2bef98560dfd7be4
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
@@ -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
- if body.include?('success') || body.include?('cancel') || body.length < 1000
308
- log 'Cancellation successful'
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 "Unexpected response: #{body[0..200]}"
312
- { success: false, error: 'Unexpected response from server' }
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}" }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Truenorth
4
- VERSION = '0.2.5'
4
+ VERSION = '0.2.7'
5
5
  end
data/truenorth.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'truenorth'
5
- spec.version = '0.2.5'
5
+ spec.version = '0.2.7'
6
6
  spec.authors = ['usiegj00']
7
7
  spec.email = ['112138+usiegj00@users.noreply.github.com']
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: truenorth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - usiegj00