Class: Gcal::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/utilities/gcal/cli.rb

Direct Known Subclasses

Mcpeasy::GcalCommands

Instance Method Summary collapse

Instance Method Details

#calendarsObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/utilities/gcal/cli.rb', line 59

def calendars
  result = tool.list_calendars
  calendars = result[:calendars]

  if calendars.empty?
    puts "📋 No calendars found"
  else
    puts "📋 Found #{result[:count]} calendar(s):"
    calendars.each_with_index do |calendar, index|
      puts "   #{index + 1}. #{calendar[:summary]}"
      puts "      ID: #{calendar[:id]}"
      puts "      Description: #{calendar[:description]}" if calendar[:description]
      puts "      Time Zone: #{calendar[:time_zone]}"
      puts "      Access Role: #{calendar[:access_role]}"
      puts "      Primary: Yes" if calendar[:primary]
      puts
    end
  end
rescue RuntimeError => e
  warn "❌ Failed to list calendars: #{e.message}"
  exit 1
end

#eventsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/utilities/gcal/cli.rb', line 29

def events
  result = tool.list_events(
    start_date: options[:start_date],
    end_date: options[:end_date],
    max_results: options[:max_results],
    calendar_id: options[:calendar_id] || "primary"
  )
  events = result[:events]

  if events.empty?
    puts "📅 No events found for the specified date range"
  else
    puts "📅 Found #{result[:count]} event(s):"
    events.each_with_index do |event, index|
      puts "   #{index + 1}. #{event[:summary] || "No title"}"
      puts "      Start: #{format_datetime(event[:start])}"
      puts "      End: #{format_datetime(event[:end])}"
      puts "      Description: #{event[:description]}" if event[:description]
      puts "      Location: #{event[:location]}" if event[:location]
      puts "      Attendees: #{event[:attendees].join(", ")}" if event[:attendees]&.any?
      puts "      Link: #{event[:html_link]}"
      puts
    end
  end
rescue RuntimeError => e
  warn "❌ Failed to list events: #{e.message}"
  exit 1
end

#search(query) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/utilities/gcal/cli.rb', line 86

def search(query)
  result = tool.search_events(
    query,
    start_date: options[:start_date],
    end_date: options[:end_date],
    max_results: options[:max_results]
  )
  events = result[:events]

  if events.empty?
    puts "🔍 No events found matching '#{query}'"
  else
    puts "🔍 Found #{result[:count]} event(s) matching '#{query}':"
    events.each_with_index do |event, index|
      puts "   #{index + 1}. #{event[:summary] || "No title"}"
      puts "      Start: #{format_datetime(event[:start])}"
      puts "      End: #{format_datetime(event[:end])}"
      puts "      Description: #{event[:description]}" if event[:description]
      puts "      Location: #{event[:location]}" if event[:location]
      puts "      Calendar: #{event[:calendar_id]}"
      puts "      Link: #{event[:html_link]}"
      puts
    end
  end
rescue RuntimeError => e
  warn "❌ Failed to search events: #{e.message}"
  exit 1
end

#testObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/utilities/gcal/cli.rb', line 10

def test
  response = tool.test_connection

  if response[:ok]
    puts "✅ Successfully connected to Google Calendar"
    puts "   User: #{response[:user]} (#{response[:email]})"
  else
    warn "❌ Connection test failed"
  end
rescue RuntimeError => e
  puts "❌ Failed to connect to Google Calendar: #{e.message}\n\n#{e.backtrace.join("\n")}"
  exit 1
end