Skip to content

Commit

Permalink
Added "visibility" to Event writable attributes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomav committed Jan 19, 2015
1 parent d987206 commit 5a42336
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 25 additions & 1 deletion lib/google/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ module Google
# * +duration+ - The duration of the event in seconds. Read only.
# * +html_link+ - An absolute link to this event in the Google Calendar Web UI. Read only.
# * +raw+ - The full google json representation of the event. Read only.
# * +visibility+ - The visibility of the event (*'default'*, 'public', 'private', 'confidential'). Read Write.
#
class Event
attr_reader :id, :raw, :html_link, :status
attr_accessor :title, :location, :calendar, :quickadd, :transparency, :attendees, :description, :reminders, :recurrence
attr_accessor :id, :title, :location, :calendar, :quickadd, :transparency, :attendees, :description, :reminders, :recurrence, :visibility

#
# Create a new event, and optionally set it's attributes.
Expand All @@ -44,6 +45,7 @@ class Event
# event.description = "The polar bear plunge"
# event.location = "In the arctic ocean"
# event.transparency = "opaque"
# event.visibility = "public"
# event.reminders = {'useDefault' => false, 'overrides' => ['minutes' => 10, 'method' => "popup"]}
# event.attendees = [
# {'email' => 'some.a.one@gmail.com', 'displayName' => 'Some A One', 'responseStatus' => 'tentative'},
Expand All @@ -55,6 +57,7 @@ def initialize(params = {})
instance_variable_set("@#{attribute}", params[attribute])
end

self.visibility = params[:visibility]
self.transparency = params[:transparency]
self.all_day = params[:all_day] if params[:all_day]
end
Expand Down Expand Up @@ -197,6 +200,17 @@ def opaque?
@transparency == "opaque"
end

#
# Sets the visibility of the Event.
#
def visibility=(val)
if val
@visibility = Event.parse_visibility(val)
else
@visibility = "default"
end
end

#
# Convenience method used to build an array of events from a Google feed.
#
Expand All @@ -211,6 +225,7 @@ def self.build_from_google_feed(response, calendar)
def to_json
"{
\"summary\": \"#{title}\",
\"visibility\": \"#{visibility}\",
\"description\": \"#{description}\",
\"location\": \"#{location}\",
\"start\": {
Expand Down Expand Up @@ -349,6 +364,7 @@ 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']) )

end
Expand Down Expand Up @@ -395,5 +411,13 @@ def self.parse_time(time) #:nodoc
(time.is_a? String) ? Time.parse(time) : time.dup.utc
end

#
# Validates visibility value
#
def self.parse_visibility(visibility)
raise ArgumentError, "Event visibility must be 'default', 'public', 'private' or 'confidential'." unless ['default', 'public', 'private', 'confidential'].include?(visibility)
return visibility
end

end
end
2 changes: 2 additions & 0 deletions test/test_google_calendar.rb
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ class TestGoogleCalendar < Minitest::Test

expected_structure = {
"summary" => "Go Swimming",
"visibility"=>"default",
"description" => "The polar bear plunge",
"location" => "In the arctic ocean",
"start" => {"dateTime" => "#{@event.start_time}"},
Expand Down Expand Up @@ -371,6 +372,7 @@ class TestGoogleCalendar < Minitest::Test
@event.recurrence = {freq: "monthly", count: "5", interval: "2"}
expected_structure = {
"summary" => "Go Swimming",
"visibility"=>"default",
"description" => "The polar bear plunge",
"location" => "In the arctic ocean",
"start" => {"dateTime" => "#{@event.start_time}", "timeZone" => "#{Time.now.getlocal.zone}"},
Expand Down

0 comments on commit 5a42336

Please sign in to comment.