Skip to content

Commit

Permalink
Incorportate tomav's changes
Browse files Browse the repository at this point in the history
  • Loading branch information
szich committed Jan 21, 2015
1 parent d1a0a96 commit 1eb5717
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/google/calendar.rb
Expand Up @@ -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

Expand Down
25 changes: 20 additions & 5 deletions lib/google/event.rb
Expand Up @@ -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.
Expand All @@ -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

#
Expand All @@ -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'}
Expand All @@ -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

Expand All @@ -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.
#
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
#
Expand Down

0 comments on commit 1eb5717

Please sign in to comment.