Class: PrintableCalendar::Calendar
- Inherits:
-
Object
- Object
- PrintableCalendar::Calendar
- Defined in:
- lib/printable_calendar/calendar.rb
Instance Method Summary collapse
- #auth ⇒ Object
- #fetch(starts:, ends:, refresh_token:, calendar_ids:) ⇒ Object
-
#initialize(client_id, client_secret) ⇒ Calendar
constructor
A new instance of Calendar.
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
#auth ⇒ Object
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. puts "\nCopy the code that Google returned and paste it here:" refresh_token = cal.login_with_auth_code($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 |