class Belphanior::Servant::CalendarWatcher::CalendarWatcher
Attributes
calendar_url[RW]
Public Class Methods
new(calendar_url)
click to toggle source
# File lib/belphanior/servant/calendar_watcher/calendar_watcher.rb, line 11 def initialize(calendar_url) @calendar_url = calendar_url end
Public Instance Methods
get_calendar()
click to toggle source
Retrieves the calendar from the server.
# File lib/belphanior/servant/calendar_watcher/calendar_watcher.rb, line 38 def get_calendar uri = URI(@calendar_url) http_session = Net::HTTP.new(uri.host, uri.port) http_session.use_ssl=true http_session.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Get.new(uri.request_uri) response = http_session.request(request) (RiCal.parse_string(response.body))[0] end
get_events_between_times(start_time, end_time)
click to toggle source
Retrieve all events that happened between start_time and end_time,
which are DateTime objects.
Returns: Array of strings which are event names for events between
start_time and end_time
# File lib/belphanior/servant/calendar_watcher/calendar_watcher.rb, line 18 def get_events_between_times(start_time, end_time) filtered_events = [] calendar = get_calendar events = calendar.events events.each do |event| event.occurrences(:overlapping => [start_time, end_time]).each do |occurrence| if occurrence.dtstart >= start_time then puts "Event occurred:" puts occurrence.summary puts "Time:" puts occurrence.dtstart filtered_events << (occurrence.summary) end end end filtered_events end