Class: Achoo::ICal
- Inherits:
-
Object
- Object
- Achoo::ICal
- Defined in:
- lib/achoo/ical.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(ics_str) ⇒ ICal
constructor
A new instance of ICal.
- #print_events(date, io = $stdout) ⇒ Object
Constructor Details
#initialize(ics_str) ⇒ ICal
Returns a new instance of ICal.
25 26 27 |
# File 'lib/achoo/ical.rb', line 25 def initialize(ics_str) @calendar = RiCal.parse_string(ics_str).first end |
Class Method Details
.from_http_request(params) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/achoo/ical.rb', line 12 def self.from_http_request(params) http = Net::HTTP.new(params[:host], params[:port]) http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE ics = http.start do |http| request = Net::HTTP::Get.new(params[:path]) request.basic_auth(params[:user], params[:pass]) response = http.request(request) response.body end self.new(ics) end |
Instance Method Details
#print_events(date, io = $stdout) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/achoo/ical.rb', line 29 def print_events(date, io=$stdout) arg_start = date arg_end = date + 1 @calendar.events.each do |e| begin if !e.x_properties['X-MICROSOFT-CDO-ALLDAYEVENT'].empty? && e.x_properties['X-MICROSOFT-CDO-ALLDAYEVENT'].first.value == 'TRUE' # FIX handle this elsif e.recurs? e.occurrences({:overlapping => [arg_start, arg_end]}).each do |o| print_event(o, io) end elsif e.dtstart >= arg_start && e.dtstart <= arg_end \ || e.dtend >= arg_start && e.dtend <= arg_end print_event(e, io) end rescue Exception => e handle_exception("Failed to process calendar event", e) end end end |