class CalInvite::Providers::Office365
Microsoft Office 365 provider for generating calendar event URLs. This provider generates URLs that open the Office 365 web calendar with a pre-filled event creation form. Supports both all-day and time-specific events with proper timezone handling.
@example Creating a regular event URL event = CalInvite::Event.new( title: “Team Meeting”, start_time: Time.now, end_time: Time.now + 3600, description: “Weekly team sync” ) office365 = CalInvite::Providers::Office365.new(event) url = office365.generate
@example Creating an all-day event URL with attendees event = CalInvite::Event.new( title: “Company Off-Site”, all_day: true, start_time: Date.today, end_time: Date.today + 1, attendees: [“john@example.com”, “jane@example.com”], show_attendees: true ) url = CalInvite::Providers::Office365.new(event).generate
Public Instance Methods
Source
# File lib/cal_invite/providers/office365.rb 37 def generate 38 if event.all_day 39 generate_all_day_event 40 else 41 generate_single_event 42 end 43 end
Generates an Office 365 calendar URL for the event. Automatically handles both all-day and time-specific events.
@return [String] The Office 365 calendar URL @raise [ArgumentError] If required time fields are missing for non-all-day events
Private Instance Methods
Source
# File lib/cal_invite/providers/office365.rb 113 def add_optional_params(params) 114 description_parts = [] 115 description_parts << format_description if format_description 116 description_parts << "Virtual Meeting URL: #{format_url}" if format_url 117 params[:body] = url_encode(description_parts.join("\n\n")) if description_parts.any? 118 params[:location] = url_encode(format_location) if format_location 119 120 if attendees_list.any? 121 params[:to] = url_encode(attendee_emails.join(';')) 122 end 123 124 params[:freebusy] = event.busy ? 'busy' : 'free' unless event.busy.nil? 125 126 params 127 end
Adds optional parameters to the URL parameters hash. Handles description, virtual meeting URL, location, and attendees.
@param params [Hash] The parameters hash to update @return [Hash] The updated parameters hash
Source
# File lib/cal_invite/providers/office365.rb 133 def build_url(params) 134 query = params.map { |k, v| "#{k}=#{v}" }.join('&') 135 "https://outlook.office.com/calendar/deeplink/compose?#{query}" 136 end
Builds the final Office 365 calendar URL.
@param params [Hash] The parameters to include in the URL @return [String] The complete Office 365 calendar URL
Source
# File lib/cal_invite/providers/office365.rb 94 def format_date(time) 95 time.strftime('%Y-%m-%d') 96 end
Formats a time object as a date string for Office 365.
@param time [Time] The time to format @return [String] The formatted date (YYYY-MM-DD)
Source
# File lib/cal_invite/providers/office365.rb 103 def format_time(time) 104 # Always use UTC format, timezone is handled by the calendar 105 time.utc.strftime('%Y-%m-%dT%H:%M:%SZ') 106 end
Formats a time object as a UTC timestamp for Office 365. Office 365 handles timezone conversion on their end.
@param time [Time] The time to format @return [String] The formatted UTC time (YYYY-MM-DDThh:mm:ssZ)
Source
# File lib/cal_invite/providers/office365.rb 51 def generate_all_day_event 52 params = { 53 subject: url_encode(event.title), 54 path: '/calendar/action/compose', 55 rru: 'addevent', 56 allday: 'true' 57 } 58 59 # Use current date if no start_time specified 60 start_date = event.start_time || Time.now 61 end_date = event.end_time || (start_date + 86400) # Add one day if no end_time 62 63 params[:startdt] = url_encode(format_date(start_date)) 64 params[:enddt] = url_encode(format_date(end_date)) 65 add_optional_params(params) 66 build_url(params) 67 end
Generates a URL for an all-day event. Uses simplified date format and sets the allday flag.
@return [String] The Office 365 calendar URL for an all-day event
Source
# File lib/cal_invite/providers/office365.rb 74 def generate_single_event 75 params = { 76 subject: url_encode(event.title), 77 path: '/calendar/action/compose', 78 rru: 'addevent' 79 } 80 81 raise ArgumentError, "Start time is required" unless event.start_time 82 raise ArgumentError, "End time is required" unless event.end_time 83 84 params[:startdt] = url_encode(format_time(event.start_time)) 85 params[:enddt] = url_encode(format_time(event.end_time)) 86 add_optional_params(params) 87 build_url(params) 88 end
Generates a URL for a regular (time-specific) event. Includes specific start and end times in UTC format.
@return [String] The Office 365 calendar URL for a regular event @raise [ArgumentError] If start_time or end_time is missing