Class: Belphanior::Servant::CalendarWatcher::CalendarWatcher
- Inherits:
-
Object
- Object
- Belphanior::Servant::CalendarWatcher::CalendarWatcher
- Defined in:
- lib/belphanior/servant/calendar_watcher/calendar_watcher.rb
Instance Attribute Summary collapse
-
#calendar_url ⇒ Object
Returns the value of attribute calendar_url.
Instance Method Summary collapse
-
#get_calendar ⇒ Object
Retrieves the calendar from the server.
-
#get_events_between_times(start_time, end_time) ⇒ Object
Retrieve all events that happened between start_time and end_time, which are DateTime objects.
-
#initialize(calendar_url) ⇒ CalendarWatcher
constructor
A new instance of CalendarWatcher.
Constructor Details
#initialize(calendar_url) ⇒ CalendarWatcher
Returns a new instance of CalendarWatcher.
11 12 13 |
# File 'lib/belphanior/servant/calendar_watcher/calendar_watcher.rb', line 11 def initialize(calendar_url) @calendar_url = calendar_url end |
Instance Attribute Details
#calendar_url ⇒ Object
Returns the value of attribute calendar_url.
10 11 12 |
# File 'lib/belphanior/servant/calendar_watcher/calendar_watcher.rb', line 10 def calendar_url @calendar_url end |
Instance Method Details
#get_calendar ⇒ Object
Retrieves the calendar from the server.
38 39 40 41 42 43 44 45 46 47 |
# 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) ⇒ Object
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
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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 |