class PrintableCalendar::PrintableCalendar
Public Class Methods
new(settings)
click to toggle source
# File lib/printable_calendar.rb, line 11 def initialize(settings) @settings = settings end
Public Instance Methods
calendar_ids()
click to toggle source
# File lib/printable_calendar.rb, line 39 def calendar_ids @settings[:calendar_ids] || abort("No calendars specified") end
client_id()
click to toggle source
# File lib/printable_calendar.rb, line 27 def client_id @settings[:client_id] || ENV["PRINTABLE_CALENDAR_CLIENT_ID"] || abort("No Google client ID specified") end
client_secret()
click to toggle source
# File lib/printable_calendar.rb, line 31 def client_secret @settings[:client_secret] || ENV["PRINTABLE_CALENDAR_CLIENT_SECRET"] || abort("No Google client secret specified") end
generate_auth()
click to toggle source
# File lib/printable_calendar.rb, line 15 def generate_auth Calendar.new(client_id, client_secret).auth end
launch_file(path)
click to toggle source
# File lib/printable_calendar.rb, line 63 def launch_file(path) if path Launchy.open("file://#{path}") else abort("Failed to generate file") end end
refresh_token()
click to toggle source
# File lib/printable_calendar.rb, line 35 def refresh_token @settings[:refresh_token] || ENV["PRINTABLE_CALENDAR_REFRESH_TOKEN"] || abort("No Google refresh token found") end
run()
click to toggle source
# File lib/printable_calendar.rb, line 19 def run starts, ends = Range.compute(@settings[:period] || "work_week", @settings[:starting_from] || Date.today) data = Calendar.new(client_id, client_secret).fetch(starts: starts, ends: ends, refresh_token: refresh_token, calendar_ids: calendar_ids) html = View.new(@settings, starts, ends, data).to_html tempfile = write_tempfile(html) launch_file(tempfile) end
write_tempfile(html)
click to toggle source
# File lib/printable_calendar.rb, line 43 def write_tempfile(html) #there has to be a better way to do this path = nil begin temp = Tempfile.new("printable_calendar") path = temp.path temp.close temp.unlink File.open(path, 'w'){|f| f.write(html)} path ensure temp.close temp.unlink end path end