Class: PrintableCalendar::Calendar

Inherits:
Object
  • Object
show all
Defined in:
lib/printable_calendar/calendar.rb

Instance Method Summary collapse

Constructor Details

#initialize(client_id, client_secret) ⇒ Calendar

Returns a new instance of Calendar.



7
8
9
10
# File 'lib/printable_calendar/calendar.rb', line 7

def initialize(client_id, client_secret)
  @client_id = client_id
  @client_secret = client_secret
end

Instance Method Details

#authObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/printable_calendar/calendar.rb', line 12

def auth
  cal = Google::Calendar.new(client_id: @client_id, client_secret: @client_secret, redirect_url: "urn:ietf:wg:oauth:2.0:oob")

  puts "Visit the following web page in your browser and approve access."
  puts cal.authorize_url
  puts "\nCopy the code that Google returned and paste it here:"

  refresh_token = cal.($stdin.gets.chomp)

  puts "Your refresh token is:\n\t#{refresh_token}\n. Copy that into your JSON config file."
end

#fetch(starts:, ends:, refresh_token:, calendar_ids:) ⇒ Object



25
26
27
28
29
30
# File 'lib/printable_calendar/calendar.rb', line 25

def fetch(starts:, ends:, refresh_token:, calendar_ids: )
  calendar_ids.map do |id|
    client = Google::Calendar.new(client_id: @client_id, client_secret: @client_secret, refresh_token: refresh_token, calendar: id)
    client.find_events_in_range(starts, ends)
  end.flatten.sort{|a, b| a.start_time <=> b.end_time}
end