Class: Google::Event
- Inherits:
-
Object
- Object
- Google::Event
- Defined in:
- lib/google/event.rb
Overview
Represents a Google Event.
Attributes
-
id - The google assigned id of the event (nil until saved), read only.
-
title - The title of the event, read/write.
-
content - The content of the event, read/write.
-
start_time - The start time of the event (Time object, defaults to now), read/write.
-
end_time - The end time of the event (Time object, defaults to one hour from now), read/write.
-
calendar - What calendar the event belongs to, read/write.
-
raw_xml - The full google xml representation of the event.
-
html_link - An absolute link to this event in the Google Calendar Web UI. Read-only.
-
published_time - The time of the event creation. Read-only.
-
updated_time - The last update time of the event. Read-only.
Instance Attribute Summary (collapse)
-
- (Object) calendar
Returns the value of attribute calendar.
-
- (Object) content
Returns the value of attribute content.
-
- (Object) html_link
readonly
Returns the value of attribute html_link.
-
- (Object) id
readonly
Returns the value of attribute id.
-
- (Object) published_time
readonly
Returns the value of attribute published_time.
-
- (Object) quickadd
Returns the value of attribute quickadd.
-
- (Object) raw_xml
readonly
Returns the value of attribute raw_xml.
-
- (Object) title
Returns the value of attribute title.
-
- (Object) transparency
Returns the value of attribute transparency.
-
- (Object) updated_time
readonly
Returns the value of attribute updated_time.
-
- (Object) where
Returns the value of attribute where.
Class Method Summary (collapse)
Instance Method Summary (collapse)
- - (Object) all_day=(time)
-
- (Boolean) all_day?
Returns whether the Event is an all-day event, based on whether the event starts at the beginning and ends at the end of the day.
-
- (Object) delete
Deletes an event.
-
- (Object) duration
Duration in seconds.
-
- (Object) end_time
Get the end_time of the event.
-
- (Object) end_time=(time)
Sets the end time of the Event.
-
- (Event) initialize(params = {})
constructor
Create a new event, and optionally set it's attributes.
- - (Boolean) opaque?
-
- (Object) save
Saves an event.
-
- (Object) start_time
Get the start_time of the event.
-
- (Object) start_time=(time)
Sets the start time of the Event.
-
- (Object) to_s
String representation of an event object.
-
- (Object) to_xml
Google XMl representation of an evetn object.
- - (Boolean) transparent?
Constructor Details
- (Event) initialize(params = {})
Create a new event, and optionally set it's attributes.
Example
Event.new(:title => 'Swimming',
:content => 'Do not forget a towel this time',
:where => 'The Ocean',
:start_time => Time.now,
:end_time => Time.now + (60 * 60),
:calendar => calendar_object)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/google/event.rb', line 35 def initialize(params = {}) @id = params[:id] @title = params[:title] @where = params[:where] @raw_xml = params[:raw_xml] @content = params[:content] @calendar = params[:calendar] @end_time = params[:end_time] @quickadd = params[:quickadd] @html_link = params[:html_link] @start_time = params[:start_time] self.all_day = params[:all_day] if params[:all_day] @updated_time = params[:updated] @transparency = params[:transparency] @published_time = params[:published] end |
Instance Attribute Details
- (Object) calendar
Returns the value of attribute calendar
23 24 25 |
# File 'lib/google/event.rb', line 23 def calendar @calendar end |
- (Object) content
Returns the value of attribute content
23 24 25 |
# File 'lib/google/event.rb', line 23 def content @content end |
- (Object) html_link (readonly)
Returns the value of attribute html_link
22 23 24 |
# File 'lib/google/event.rb', line 22 def html_link @html_link end |
- (Object) id (readonly)
Returns the value of attribute id
22 23 24 |
# File 'lib/google/event.rb', line 22 def id @id end |
- (Object) published_time (readonly)
Returns the value of attribute published_time
22 23 24 |
# File 'lib/google/event.rb', line 22 def published_time @published_time end |
- (Object) quickadd
Returns the value of attribute quickadd
23 24 25 |
# File 'lib/google/event.rb', line 23 def quickadd @quickadd end |
- (Object) raw_xml (readonly)
Returns the value of attribute raw_xml
22 23 24 |
# File 'lib/google/event.rb', line 22 def raw_xml @raw_xml end |
- (Object) title
Returns the value of attribute title
23 24 25 |
# File 'lib/google/event.rb', line 23 def title @title end |
- (Object) transparency
Returns the value of attribute transparency
23 24 25 |
# File 'lib/google/event.rb', line 23 def transparency @transparency end |
- (Object) updated_time (readonly)
Returns the value of attribute updated_time
22 23 24 |
# File 'lib/google/event.rb', line 22 def updated_time @updated_time end |
- (Object) where
Returns the value of attribute where
23 24 25 |
# File 'lib/google/event.rb', line 23 def where @where end |
Class Method Details
+ (Object) build_from_google_feed(xml, calendar)
113 114 115 |
# File 'lib/google/event.rb', line 113 def self.build_from_google_feed(xml, calendar) Nokogiri::XML(xml).xpath("//xmlns:entry").collect {|e| new_from_xml(e, calendar)} end |
Instance Method Details
- (Object) all_day=(time)
91 92 93 94 95 96 97 |
# File 'lib/google/event.rb', line 91 def all_day=(time) if time.class == String time = Time.parse(time) end @start_time = time.strftime("%Y-%m-%d") @end_time = (time + 24*60*60).strftime("%Y-%m-%d") end |
- (Boolean) all_day?
Returns whether the Event is an all-day event, based on whether the event starts at the beginning and ends at the end of the day.
86 87 88 89 |
# File 'lib/google/event.rb', line 86 def all_day? time = Time.parse(@start_time) duration % (24 * 60 * 60) == 0 && time == Time.local(time.year,time.month,time.day) end |
- (Object) delete
Deletes an event.
Note: If using this on an event you created without using a calendar object,
make sure to set the calendar before calling this method.
158 159 160 161 |
# File 'lib/google/event.rb', line 158 def delete @calendar.delete_event(self) @id = nil end |
- (Object) duration
Duration in seconds
100 101 102 |
# File 'lib/google/event.rb', line 100 def duration Time.parse(end_time) - Time.parse(start_time) end |
- (Object) end_time
Get the end_time of the event.
If no time is set (i.e. new event) it defaults to one hour in the future.
71 72 73 74 |
# File 'lib/google/event.rb', line 71 def end_time @end_time ||= Time.now.utc + (60 * 60) # seconds * min (@end_time.is_a? String) ? @end_time : @end_time.xmlschema end |
- (Object) end_time=(time)
Sets the end time of the Event. Must be a Time object or a parsable string representation of a time.
78 79 80 81 82 |
# File 'lib/google/event.rb', line 78 def end_time=(time) @end_time = parse_time(time) raise ArgumentError, "End Time must be either Time or String" unless (time.is_a?(String) || time.is_a?(Time)) @end_time = (time.is_a? String) ? Time.parse(time) : time.dup.utc end |
- (Boolean) opaque?
108 109 110 |
# File 'lib/google/event.rb', line 108 def opaque? transparency == "opaque" end |
- (Object) save
Saves an event.
Note: If using this on an event you created without using a calendar object,
make sure to set the calendar before calling this method.
150 151 152 |
# File 'lib/google/event.rb', line 150 def save update_after_save(@calendar.save_event(self)) end |
- (Object) start_time
Get the start_time of the event.
If no time is set (i.e. new event) it defaults to the current time.
62 63 64 65 |
# File 'lib/google/event.rb', line 62 def start_time @start_time ||= Time.now.utc (@start_time.is_a? String) ? @start_time : @start_time.xmlschema end |
- (Object) start_time=(time)
Sets the start time of the Event. Must be a Time object or a parsable string representation of a time.
54 55 56 |
# File 'lib/google/event.rb', line 54 def start_time=(time) @start_time = parse_time(time) end |
- (Object) to_s
String representation of an event object.
140 141 142 143 144 |
# File 'lib/google/event.rb', line 140 def to_s s = "#{title} (#{self.id})\n\t#{start_time}\n\t#{end_time}\n\t#{where}\n\t#{content}" s << "\n\t#{quickadd}" if quickadd s end |
- (Object) to_xml
Google XMl representation of an evetn object.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/google/event.rb', line 119 def to_xml unless quickadd "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'> <category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/g/2005#event'></category> <title type='text'>#{title}</title> <content type='text'>#{content}</content> <gd:transparency value='http://schemas.google.com/g/2005#event.#{transparency}'></gd:transparency> <gd:eventStatus value='http://schemas.google.com/g/2005#event.confirmed'></gd:eventStatus> <gd:where valueString=\"#{where}\"></gd:where> <gd:when startTime=\"#{start_time}\" endTime=\"#{end_time}\"></gd:when> </entry>" else %Q{<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gCal='http://schemas.google.com/gCal/2005'> <content type="html">#{content}</content> <gCal:quickadd value="true"/> </entry>} end end |
- (Boolean) transparent?
104 105 106 |
# File 'lib/google/event.rb', line 104 def transparent? transparency == "transparent" end |