class CalInvite::Event
Attributes
Public Class Methods
Source
# File lib/cal_invite/event.rb 95 def initialize(attributes = {}) 96 @show_attendees = attributes.delete(:show_attendees) || false 97 @timezone = attributes.delete(:timezone) || 'UTC' 98 @multi_day_sessions = attributes.delete(:multi_day_sessions) || [] 99 @all_day = attributes.delete(:all_day) || false 100 @uid = attributes.delete(:uid) || generate_uid 101 @sequence = attributes.delete(:sequence) || 0 102 @busy = attributes.key?(:busy) ? attributes.delete(:busy) : true 103 @visibility = attributes.delete(:visibility) || :public 104 @allow_counter = attributes.key?(:allow_counter) ? attributes.delete(:allow_counter) : true 105 106 attributes.each do |key, value| 107 send("#{key}=", value) if respond_to?("#{key}=") 108 end 109 110 validate! 111 end
Initializes a new Event instance with the given attributes.
@param attributes [Hash] The attributes to initialize the event with @option attributes [String] :title The event title @option attributes [Time] :start_time The event start time @option attributes [Time] :end_time The event end time @option attributes [String] :description The event description @option attributes [String] :location The event location @option attributes [String] :url The event URL @option attributes [Array<String>] :attendees The event attendees @option attributes [String] :timezone (‘UTC’) The event timezone @option attributes [Boolean] :show_attendees (false) Whether to show attendees @option attributes [String] :notes Additional notes @option attributes [Array<Hash>] :multi_day_sessions Multi-day session details @option attributes [Boolean] :all_day (false) Whether it’s an all-day event @option attributes [Hash] :organizer The event organizer, e.g. { name: “Jane Doe”, email: “jane@example.com” } @option attributes [String] :uid A stable identifier for this event. If omitted, a random one is generated and memoized on this instance. To update or cancel a previously sent invite, you MUST pass the same :uid used originally — mail/calendar clients match REQUEST/CANCEL messages to an existing event by UID, not by content. @option attributes [Integer] :sequence (0) RFC 5545 SEQUENCE number. Increment it yourself each time you re-send a REQUEST or a CANCEL for the same :uid. @option attributes [Array<Float>, Hash] :geo Location coordinates, e.g. [37.4595, -122.1418] or { lat:, lng: } @option attributes [Array<Integer>] :reminders Minutes-before-start values; one VALARM per entry @option attributes [Boolean] :busy (true) Whether this event shows as busy on free/busy lookups @option attributes [Symbol, String] :visibility (:public) :public, :private, or :confidential @option attributes [String] :rrule A raw RFC 5545 recurrence rule value, e.g. “FREQ=WEEKLY;COUNT=5” @option attributes [String] :calendar_name Calendar-level display name (X-WR-CALNAME) @option attributes [Symbol, String] :importance :low, :normal, or :high @option attributes [Boolean] :allow_counter (true) false emits X-MICROSOFT-DISALLOW-COUNTER
@raise [ArgumentError] If required attributes are missing
Public Instance Methods
Source
# File lib/cal_invite/event.rb 149 def generate_calendar_url(provider, method: :publish) 150 validate! 151 152 if caching_enabled? 153 cache_key = cache_key_for(provider, method) 154 cached_url = fetch_from_cache(cache_key) 155 return cached_url if cached_url 156 end 157 158 # Generate the URL 159 provider_class = CalInvite::Providers.const_get(capitalize_provider(provider.to_s)) 160 generator = provider_class.new(self, method: method) 161 url = generator.generate 162 163 # Cache the result if caching is enabled 164 write_to_cache(cache_key, url) if caching_enabled? 165 166 url 167 end
Generates a calendar URL (or, for the ics/ical/ics_content providers, raw iCalendar content) for the specified provider.
@param provider [Symbol] The calendar provider to generate the URL for @param method [Symbol] The iCalendar METHOD to use (:publish, :request, :cancel, :reply, :counter, or :decline_counter). Only honored by the ics-family providers (ics, ical, ics_content); ignored by URL-based providers. - :request (with an {#organizer} set) produces an invite that mail clients (Gmail, Outlook, Apple Mail) recognize and render with Accept/Decline actions rather than as a plain attachment. - :cancel produces a cancellation (STATUS:CANCELLED) for a previously sent :request. Reuse the same {#uid} and bump {#sequence} so clients match it to the original invite instead of creating a new event. - :reply carries an attendee’s own PARTSTAT back to the organizer. - :counter carries an attendee’s proposed new {#start_time}/{#end_time} back to the organizer, keeping the original {#uid}/{#sequence}. Client support for rendering this as an actionable UI is inconsistent — see CONFIGURATION.md’s “Attendee-proposed reschedules (COUNTER)”. - :decline_counter is the organizer rejecting a :counter proposal. @return [String] The generated calendar URL or content @raise [ArgumentError] If required event attributes are missing
@example Generate a Google Calendar URL event.generate_calendar_url(:google)
@example Generate an Outlook Calendar URL event.generate_calendar_url(:outlook)
@example Generate an RFC 5545 meeting request for emailing as an invite event.organizer = { name: “Jane Doe”, email: “jane@example.com” } event.generate_calendar_url(:ics, method: :request)
@example Cancel a previously sent invite event.uid = “the-original-uid@cal-invite” # must match the original REQUEST event.sequence = 1 # incremented from the original event.generate_calendar_url(:ics, method: :cancel)
Source
# File lib/cal_invite/event.rb 180 def update_attributes(new_attributes) 181 new_attributes.each do |key, value| 182 send("#{key}=", value) if respond_to?("#{key}=") 183 end 184 185 invalidate_cache if caching_enabled? 186 validate! 187 end
Updates the event attributes with new values.
@param new_attributes [Hash] The new attributes to update @return [void] @raise [ArgumentError] If the updated attributes make the event invalid
@example Update event title and time event.update_attributes( title: “Updated Meeting”, start_time: Time.now + 3600 )