class CalInvite::Providers::Outlook
Microsoft Outlook Live (outlook.live.com) provider for generating calendar event URLs. This provider generates URLs that open the Outlook.com web calendar with a pre-filled event creation form. Supports both all-day and time-specific events.
Note: This is for personal Outlook.com accounts. For corporate Office 365, use the {Office365} provider instead.
@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” ) outlook = CalInvite::Providers::Outlook.new(event) url = outlook.generate
@example Creating an all-day event URL with attendees event = CalInvite::Event.new( title: “Company Holiday”, 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::Outlook.new(event).generate
@see Office365 For corporate Office 365 calendar URLs
Public Instance Methods
Source
# File lib/cal_invite/providers/outlook.rb 42 def generate 43 if event.all_day 44 generate_all_day_event 45 else 46 generate_single_event 47 end 48 end
Generates an Outlook.com calendar URL for the event. Automatically handles both all-day and time-specific events.
@return [String] The Outlook.com calendar URL @raise [ArgumentError] If required time fields are missing for non-all-day events
Private Instance Methods
Source
# File lib/cal_invite/providers/outlook.rb 118 def add_optional_params(params) 119 description_parts = [] 120 description_parts << format_description if format_description 121 description_parts << "Virtual Meeting URL: #{format_url}" if format_url 122 params[:body] = url_encode(description_parts.join("\n\n")) if description_parts.any? 123 params[:location] = url_encode(format_location) if format_location 124 125 if attendees_list.any? 126 params[:to] = url_encode(attendee_emails.join(';')) 127 end 128 129 params[:freebusy] = event.busy ? 'busy' : 'free' unless event.busy.nil? 130 131 params 132 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/outlook.rb 138 def build_url(params) 139 query = params.map { |k, v| "#{k}=#{v}" }.join('&') 140 "https://outlook.live.com/calendar/deeplink/compose?#{query}" 141 end
Builds the final Outlook.com calendar URL.
@param params [Hash] The parameters to include in the URL @return [String] The complete Outlook.com calendar URL
Source
# File lib/cal_invite/providers/outlook.rb 99 def format_date(time) 100 time.strftime('%Y-%m-%d') 101 end
Formats a time object as a date string for Outlook.com.
@param time [Time] The time to format @return [String] The formatted date (YYYY-MM-DD)
Source
# File lib/cal_invite/providers/outlook.rb 108 def format_time(time) 109 # Always use UTC format, timezone is handled by the calendar 110 time.utc.strftime('%Y-%m-%dT%H:%M:%SZ') 111 end
Formats a time object as a UTC timestamp for Outlook.com. Outlook.com 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/outlook.rb 56 def generate_all_day_event 57 params = { 58 path: '/calendar/action/compose', 59 rru: 'addevent', 60 subject: url_encode(event.title), 61 allday: 'true' 62 } 63 64 # Set start and end dates 65 start_date = event.start_time || Time.now 66 end_date = event.end_time || (start_date + 86400) 67 params[:startdt] = format_date(start_date) 68 params[:enddt] = format_date(end_date) 69 70 add_optional_params(params) 71 build_url(params) 72 end
Generates a URL for an all-day event. Uses simplified date format and sets the allday flag.
@return [String] The Outlook.com calendar URL for an all-day event
Source
# File lib/cal_invite/providers/outlook.rb 79 def generate_single_event 80 params = { 81 path: '/calendar/action/compose', 82 rru: 'addevent', 83 subject: url_encode(event.title) 84 } 85 86 raise ArgumentError, "Start time is required" unless event.start_time 87 raise ArgumentError, "End time is required" unless event.end_time 88 89 params[:startdt] = format_time(event.start_time) 90 params[:enddt] = format_time(event.end_time) 91 add_optional_params(params) 92 build_url(params) 93 end
Generates a URL for a regular (time-specific) event. Includes specific start and end times in UTC format.
@return [String] The Outlook.com calendar URL for a regular event @raise [ArgumentError] If start_time or end_time is missing