diff --git a/lib/google/calendar.rb b/lib/google/calendar.rb index 02f5537..90a1748 100644 --- a/lib/google/calendar.rb +++ b/lib/google/calendar.rb @@ -155,7 +155,7 @@ def find_future_events(options={}) # an array of events if many found. # def find_event_by_id(id) - return nil unless id && id.strip != '' + return nil unless id event_lookup("/#{id}") end diff --git a/lib/google/event.rb b/lib/google/event.rb index 6976ca5..8654735 100644 --- a/lib/google/event.rb +++ b/lib/google/event.rb @@ -8,7 +8,7 @@ module Google # # === Attributes # - # * +id+ - The google assigned id of the event (nil until saved). Read only. + # * +id+ - The google assigned id of the event (nil until saved). Read Write. # * +status+ - The status of the event (confirmed, tentative or cancelled). Read only. # * +title+ - The title of the event. Read Write. # * +description+ - The content of the event. Read Write. @@ -28,7 +28,7 @@ module Google # * +visibility+ - The visibility of the event (*'default'*, 'public', 'private', 'confidential'). Read Write. # class Event - attr_reader :id, :raw, :html_link, :status + attr_reader :raw, :html_link, :status attr_accessor :id, :title, :location, :calendar, :quickadd, :transparency, :attendees, :description, :reminders, :recurrence, :visibility # @@ -38,6 +38,7 @@ class Event # # event = Google::Event.new # event.calendar = AnInstanceOfGoogleCalendaer + # event.id = "0123456789abcdefghijklmopqrstuv" # event.start_time = Time.now # event.end_time = Time.now + (60 * 60) # event.recurrence = {'freq' => 'monthly'} @@ -53,7 +54,7 @@ class Event # ] # def initialize(params = {}) - [:id, :status, :raw, :html_link, :title, :location, :calendar, :quickadd, :attendees, :description, :reminders, :recurrence, :start_time, :end_time, ].each do |attribute| + [:id, :status, :raw, :html_link, :title, :location, :calendar, :quickadd, :attendees, :description, :reminders, :recurrence, :start_time, :end_time].each do |attribute| instance_variable_set("@#{attribute}", params[attribute]) end @@ -62,6 +63,13 @@ def initialize(params = {}) self.all_day = params[:all_day] if params[:all_day] end + # + # Sets the id of the Event. + # + def id=(id) + @id = Event.parse_id(id) unless id.nil? + end + # # Sets the start time of the Event. Must be a Time object or a parse-able string representation of a time. # @@ -364,8 +372,8 @@ def self.new_from_feed(e, calendar) #:nodoc: :updated => e['updated'], :reminders => e['reminders'], :attendees => e['attendees'], - :visibility => e['visibility'], - :recurrence => Event.parse_recurrence_rule(e['recurrence']) ) + :recurrence => Event.parse_recurrence_rule(e['recurrence']), + :visibility => e['visibility'] ) end @@ -411,6 +419,13 @@ def self.parse_time(time) #:nodoc (time.is_a? String) ? Time.parse(time) : time.dup.utc end + # + # Validates id format + # + def self.parse_id(id) + raise ArgumentError, "Event ID is invalid. Please check Google documentation: https://developers.google.com/google-apps/calendar/v3/reference/events/insert" unless id.gsub(/(^[a-v0-9]{5,1024}$)/o) + end + # # Validates visibility value #