gcal4ruby-aunderwo 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,83 @@
1
+ #=CHANGELOG
2
+ #==version 0.5.5
3
+ #* Fixed calendar::find method. Thanks to AB <a.berezovskiy@gmail.com>.
4
+ #* Improved recurrence handling. Thanks to John Paul Narowski <jnarowski@gmail.com>.
5
+ #* Fixed documentation bug for event reminders.
6
+ #* Changed license to LGPLv3.
7
+ #==version 0.5.4
8
+ #* Fixed Service#to_iframe bgcolor bug
9
+ #==version 0.5.3
10
+ #* Fixed bug when loading event attributes when initializing
11
+ #==version 0.5.2
12
+ #* Fixed calendar.public functionality for making calendars publicly viewable.
13
+ #* Fixed to_iframe output methods
14
+ #* Fixed issue with creating new events
15
+ #==version 0.5.1
16
+ #* Minor fixes to to_iframe methods
17
+ #==version 0.5.0 - MAJOR CHANGES
18
+ #* Now using GData4Ruby library as base class for service, calendar, and event objects. This removed the base.rb class, which is now inherited from
19
+ # GData4ruby
20
+ #* Added 'events' method to service to get all events for an account.
21
+ #* Major interface changes to find methods - these are not backwards compatible changes.
22
+ #* Changed Event#find default behavior to search all calendars.
23
+ #* Major interface changes to to_iframe methods - these are not backwards compatible changes.
24
+ #* Added support for multiple reminders.
25
+ #* Improved object relationship for events. Events are now service-centric, i.e. events are instantiated with a service object.
26
+ #* Event calendar is now set through a 'calendar' attribute.
27
+ #* Fixes to event recurrence handling and display.
28
+ #* Added support for reminders with recurring events.
29
+ #* Numerous improvements to performance.
30
+ #* Calendar objects no longer have to query ACL feed to determine editability.
31
+ #* Added support for event statuses: cancelled, tentative or confirmed.
32
+ #==version 0.3.2
33
+ #* Updated the Event.find method to support finding all events by passing :all as the query term.
34
+ #==version 0.3.1
35
+ #* Fixed Event.find method to work with secondary calendars and google apps accounts. Fix provided by groesser3.
36
+ #* Added max results to Calendar.find.
37
+ #==version 0.3.0
38
+ #* Rewrote Event.find to improve performance significantly.
39
+ #* Added improvements to event recurrence handling, including loading existing recurrences, changing recurring events to non recurring and vice versa.
40
+ #* Added support for initialization attributes to Event, Calendar, Service and Recurrence.
41
+ #* Fixed query string typo in Event.find. Fix provided by nat.lownes.
42
+ #==version 0.2.11
43
+ #* Added support for GML elements in calendar events. Fix provided by nat.lownes.
44
+ #* Fixed event status bug where cancelled events were marked confirmed. Fix provided by rifraf.
45
+ #==version 0.2.10
46
+ #* Fixed library support for Google Hosted Apps accounts running in forced SSL mode.
47
+ #==version 0.2.9
48
+ #* Fixed small SSL redirect bug due to variable misnaming in base.rb. Fix provided by JohnMetta
49
+ #==version 0.2.8
50
+ #* Merged changes from edruder and h13ronim from the unofficial github repo - http://github.com/h13ronim/gcal4ruby/commits/master
51
+ #==version 0.2.7
52
+ #* Added fix for finding events in calendars that have more than 25 entries
53
+ #==version 0.2.6
54
+ #* Added fix for updated google calendar XML per http://cookingandcoding.wordpress.com/2009/06/08/new-ruby-google-calendar-api-gem-gcal4ruby/#comment-183
55
+ #==version 0.2.5
56
+ #* Added calendar color support to to_iframe methods in Calendar and Service.
57
+ #==version 0.2.4
58
+ #* Fixed bug with ACL check in Calendar#load
59
+ #==version 0.2.3
60
+ #* Implemented to_iframe method for calendars and services to output embeddable iframe text.
61
+ #* Added switch to turn off ACL check for public calendars. Can increase effeciency if turned off.
62
+ #==version 0.2.2
63
+ #* Fixed URL encoding problem in Event.find method.
64
+ #* cleaned up Event.find method to allow for finding events by id
65
+ #* updated Calendar.find method to add params hash
66
+ #* added 'published', 'updated', and 'edited' attributes
67
+ #==version 0.2.1
68
+ #* fixed Event.find calendar specification
69
+ #==version 0.2.0
70
+ #* Fixed redirect URI query params problem
71
+ #* Updated syntax for finding events to include most google api parameters, Non-backwards compatible.
72
+ #==version 0.1.4
73
+ #* Added additional search criteria for Event.find
74
+ #==version 0.1.3
75
+ #* Added support for authenticating with Google Hosted Apps accounts
76
+ #* Added flag to indicate whether a calendar is editable
77
+ #* Added handling to gracefully throw error when trying to create event on a non-editable (shared) calendar
78
+ #==version 0.1.2
79
+ #* Fixed to_xml dump problem with hidden and selected attributes
80
+ #==version 0.1.1
81
+ #* Added all_day indicator to event to indicate an all day event
82
+ #==version 0.1.0
83
+ #* Initial Version
data/README ADDED
@@ -0,0 +1,99 @@
1
+ #=GCal4Ruby
2
+ #
3
+ #==Introduction
4
+ #GCal4Ruby is a full featured wrapper for the google calendar API. GCal4Ruby implements
5
+ #all of the functionality available through the Google Calnedar API, including permissions,
6
+ #attendees, reminders and event recurrence.
7
+ #
8
+ #==Author and Contact Information
9
+ #GCal4Ruby was created and is maintained by {Mike Reich}[mailto:mike@seabourneconsulting.com]
10
+ #and is licenses under the LGPL v3. Feel free to use and update, but be sure to contribute your
11
+ #code back to the project and attribute as required by the license. You can find the text of the LGPL
12
+ #here: http://www.gnu.org/licenses/lgpl.html.
13
+ #
14
+ #===Website
15
+ #http://cookingandcoding.com/gcal4ruby/
16
+ #
17
+ #==Description
18
+ #GCal4Ruby has three major components: the service, calendar and event objects. Each service
19
+ #has many calendars, which in turn have many events. Each service is the representation of a
20
+ #google account, and thus must be successfully authenticated using valid Google Calendar
21
+ #account credentials.
22
+ #
23
+ #==Examples
24
+ #Below are some common usage examples. For more examples, check the documentation.
25
+ #===Service
26
+ #1. Authenticate
27
+ # service = Service.new
28
+ # service.authenticate("user@gmail.com", "password")
29
+ #
30
+ #2. Get Calendar List
31
+ # calendars = service.calendars
32
+ #
33
+ #===Calendar
34
+ #All usages assume a successfully authenticated Service.
35
+ #1. Create a new Calendar
36
+ # cal = Calendar.new(service)
37
+ #
38
+ #2. Find a calendar by ID
39
+ # cal = Calendar.find(service, {:id => cal_id})
40
+ #
41
+ #3. Get all calendar events
42
+ # cal = Calendar.find(service, {:id => cal_id})
43
+ # events = cal.events
44
+ #
45
+ #4. Find an existing calendar by title
46
+ # cal = Calendar.find(service, {:title => "New Calendar"})
47
+ #
48
+ #5. Find all calendars containing a search term
49
+ # cal = Calendar.find(service, "Soccer Team")
50
+ #===Event
51
+ #All usages assume a successfully authenticated Service and valid Calendar.
52
+ #1. Create a new Event
53
+ # event = Event.new(service, {:calendar => cal, :title => "Soccer Game", :start => Time.parse("12-06-2009 at 12:30 PM"), :end => Time.parse("12-06-2009 at 1:30 PM"), :where => "Merry Playfields"})
54
+ # event.save
55
+ #
56
+ #2. Find an existing Event by title
57
+ # event = Event.find(service, {:title => "Soccer Game"})
58
+ #
59
+ #3. Find an existing Event by ID
60
+ # event = Event.find(service, {:id => event.id})
61
+ #
62
+ #4. Find all events containing the search term
63
+ # event = Event.find(service, "Soccer Game")
64
+ #
65
+ #5. Find all events on a calendar containing the search term
66
+ # event = Event.find(service, "Soccer Game", {:calendar => cal.id})
67
+ #
68
+ #6. Find events within a date range
69
+ # event = Event.find(service, "Soccer Game", {'start-min' => Time.parse("01/01/2010").utc.xmlschema, 'start-max' => Time.parse("06/01/2010").utc.xmlschema})
70
+ #
71
+ #7. Create a recurring event for every saturday
72
+ # event = Event.new(service)
73
+ # event.title = "Baseball Game"
74
+ # event.calendar = cal
75
+ # event.where = "Municipal Stadium"
76
+ # event.recurrence = Recurrence.new
77
+ # event.recurrence.start_time = Time.parse("06/20/2009 at 4:30 PM")
78
+ # event.recurrence.end_time = Time.parse("06/20/2009 at 6:30 PM")
79
+ # event.recurrence.frequency = {"weekly" => ["SA"]}
80
+ # event.save
81
+ #
82
+ #8. Create an event with a 15 minute email reminder
83
+ # event = Event.new(service)
84
+ # event.calendar = cal
85
+ # event.title = "Dinner with Kate"
86
+ # event.start_time = Time.parse("06/20/2009 at 5 pm")
87
+ # event.end_time = Time.parse("06/20/2009 at 8 pm")
88
+ # event.where = "Luigi's"
89
+ # event.reminder = {:minutes => 15, :method => 'email'}
90
+ # event.save
91
+ #
92
+ #9. Create an event with attendees
93
+ # event = Event.new(service)
94
+ # event.calendar = cal
95
+ # event.title = "Dinner with Kate"
96
+ # event.start_time = Time.parse("06/20/2009 at 5 pm")
97
+ # event.end_time = Time.parse("06/20/2009 at 8 pm")
98
+ # event.attendees => {:name => "Kate", :email => "kate@gmail.com"}
99
+ # event.save
@@ -0,0 +1 @@
1
+ require "gcal4ruby/service"
@@ -0,0 +1,369 @@
1
+ # Author:: Mike Reich (mike@seabourneconsulting.com)
2
+ # Copyright:: Copyright (C) 2010 Mike Reich
3
+ # License:: GPL v2
4
+ #--
5
+ # Licensed under the General Public License (GPL), Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ #
15
+ # Feel free to use and update, but be sure to contribute your
16
+ # code back to the project and attribute as required by the license.
17
+ #++
18
+ require 'gdata4ruby/acl/access_rule'
19
+ module GCal4Ruby
20
+ #The Calendar Class is the representation of a Google Calendar. Each user account
21
+ #can have multiple calendars. You must have an authenticated Service object before
22
+ #using the Calendar object.
23
+ #=Usage
24
+ #All usages assume a successfully authenticated Service.
25
+ #1. Create a new Calendar
26
+ # cal = Calendar.new(service)
27
+ #
28
+ #2. Find a calendar by ID
29
+ # cal = Calendar.find(service, {:id => cal_id})
30
+ #
31
+ #3. Get all calendar events
32
+ # cal = Calendar.find(service, {:id => cal_id})
33
+ # events = cal.events
34
+ #
35
+ #4. Find an existing calendar by title
36
+ # cal = Calendar.find(service, {:title => "New Calendar"})
37
+ #
38
+ #5. Find all calendars containing a search term
39
+ # cal = Calendar.find(service, "Soccer Team")
40
+ #
41
+ #After a calendar object has been created or loaded, you can change any of the
42
+ #attributes like you would any other object. Be sure to save the calendar to write changes
43
+ #to the Google Calendar service.
44
+ class Calendar < GData4Ruby::GDataObject
45
+ CALENDAR_FEED = "http://www.google.com/calendar/feeds/default/owncalendars/full/"
46
+ CALENDAR_QUERY_FEED = "http://www.google.com/calendar/feeds/default/calendars/"
47
+ CALENDAR_XML = "<entry xmlns='http://www.w3.org/2005/Atom'
48
+ xmlns:gd='http://schemas.google.com/g/2005'
49
+ xmlns:gCal='http://schemas.google.com/gCal/2005'>
50
+ <title type='text'></title>
51
+ <summary type='text'></summary>
52
+ <gCal:timezone value='America/Los_Angeles'></gCal:timezone>
53
+ <gCal:hidden value='false'></gCal:hidden>
54
+ <gCal:color value='#2952A3'></gCal:color>
55
+ <gd:where rel='' label='' valueString='Oakland'></gd:where>
56
+ </entry>"
57
+
58
+ #A short description of the calendar
59
+ attr_accessor :summary
60
+
61
+ #Boolean value indicating the calendar visibility
62
+ attr_accessor :hidden
63
+
64
+ #The calendar timezone[http://code.google.com/apis/calendar/docs/2.0/reference.html#gCaltimezone]
65
+ attr_accessor :timezone
66
+
67
+ #The calendar color. Must be one of these[http://code.google.com/apis/calendar/docs/2.0/reference.html#gCalcolor] values.
68
+ attr_accessor :color
69
+
70
+ #The calendar geo location, if any
71
+ attr_accessor :where
72
+
73
+ #A boolean value indicating whether the calendar appears by default when viewed online
74
+ attr_accessor :selected
75
+
76
+ #A flag indicating whether the calendar is editable by this account
77
+ attr_reader :editable
78
+
79
+ #Accepts a Service object and an optional attributes hash for initialization. Returns the new Calendar
80
+ #if successful, otherwise raises the InvalidService error.
81
+ def initialize(service, attributes = {})
82
+ super(service, attributes)
83
+ if !service.is_a?(Service)
84
+ raise InvalidService
85
+ end
86
+ @xml = CALENDAR_XML
87
+ @service ||= service
88
+ @exists = false
89
+ @title ||= ""
90
+ @summary ||= ""
91
+ @public ||= false
92
+ @hidden ||= false
93
+ @timezone ||= "America/Los_Angeles"
94
+ @color ||= "#2952A3"
95
+ @where ||= ""
96
+ attributes.each do |key, value|
97
+ self.send("#{key}=", value)
98
+ end
99
+ return true
100
+ end
101
+
102
+ #Returns true if the calendar exists on the Google Calendar system (i.e. was
103
+ #loaded or has been saved). Otherwise returns false.
104
+ def exists?
105
+ return @exists
106
+ end
107
+
108
+ #Returns true if the calendar is publically accessable, otherwise returns false.
109
+ def public?
110
+ return @public
111
+ end
112
+
113
+ #Returns an array of Event objects corresponding to each event in the calendar.
114
+ # query_params is a hash of parameters which can be found here
115
+ # http://code.google.com/apis/gdata/docs/2.0/reference.html#Queries
116
+ # e.g {"max-results" => "50"} The default here is 10000
117
+ def events(query_params = {})
118
+ events = []
119
+ ret = @service.send_request(GData4Ruby::Request.new(:get, @content_uri, nil, nil, {"max-results" => "10000"}.merge(query_params)))
120
+ REXML::Document.new(ret.body).root.elements.each("entry"){}.map do |entry|
121
+ entry = GData4Ruby::Utils.add_namespaces(entry)
122
+ e = Event.new(service)
123
+ if e.load(entry.to_s)
124
+ events << e
125
+ end
126
+ end
127
+ return events
128
+ end
129
+
130
+
131
+ #Saves the calendar.
132
+ def save
133
+ public = @public
134
+ ret = super
135
+ return ret if public == @public
136
+ if public
137
+ puts 'setting calendar to public' if service.debug
138
+ rule = GData4Ruby::ACL::AccessRule.new(service, self)
139
+ rule.role = 'http://schemas.google.com/gCal/2005#read'
140
+ rule.save
141
+ else
142
+ rule = GData4Ruby::ACL::AccessRule.find(service, self, {:user => 'default'})
143
+ rule.delete if rule
144
+ end
145
+ reload
146
+ end
147
+
148
+ #Set the calendar to public (p = true) or private (p = false). Publically viewable
149
+ #calendars can be accessed by anyone without having to log in to google calendar. See
150
+ #Calendar#to_iframe on how to display a public calendar in a webpage.
151
+ def public=(p)
152
+ @public = p
153
+ end
154
+
155
+ #Creates a new instance of the object
156
+ def create
157
+ return service.send_request(GData4Ruby::Request.new(:post, CALENDAR_FEED, to_xml()))
158
+ end
159
+
160
+ #Finds a Calendar based on a text query or by an id. Parameters are:
161
+ #*service*:: A valid Service object to search.
162
+ #*query*:: either a string containing a text query to search by, or a hash containing an +id+ key with an associated id to find, or a +query+ key containint a text query to search for, or a +title+ key containing a title to search.
163
+ #*query_params*:: a hash containing optional additional query paramters to use. See http://code.google.com/apis/gdata/docs/2.0/reference.html#Queries for a full list of possible values. Example:
164
+ # {'max-results' => '100'}
165
+ #If an ID is specified, a single instance of the calendar is returned if found, otherwise false.
166
+ #If a query term or title text is specified, and array of matching results is returned, or an empty array if nothing
167
+ #was found.
168
+ def self.find(service, query, args = {})
169
+ raise ArgumentError, 'query must be a hash or string' if not query.is_a? Hash and not query.is_a? String
170
+ if query.is_a? Hash and query[:id]
171
+ id = query[:id]
172
+ puts "id passed, finding calendar by id" if service.debug
173
+ puts "id = "+id if service.debug
174
+ d = service.send_request(GData4Ruby::Request.new(:get, CALENDAR_FEED+id,nil, {"If-None-Match" => "*"}, {"max-results" => "10000"}.merge(query_params)))
175
+ puts d.inspect if service.debug
176
+ if d
177
+ return get_instance(service, d)
178
+ end
179
+ else
180
+ #fugly, but Google doesn't provide a way to query the calendar feed directly
181
+ old_public = service.check_public
182
+ service.check_public = false
183
+ results = []
184
+ cals = service.calendars
185
+ cals.each do |cal|
186
+ if query.is_a?(Hash)
187
+ results << cal if query[:query] and cal.title.downcase.include? query[:query].downcase
188
+ results << cal if query[:title] and cal.title == query[:title]
189
+ else
190
+ results << cal if cal.title.downcase.include? query.downcase
191
+ end
192
+ end
193
+ service.check_public = old_public
194
+ return results
195
+ end
196
+ return false
197
+ end
198
+
199
+ #Reloads the calendar objects information from the stored server version. Returns true
200
+ #if successful, otherwise returns false. Any information not saved will be overwritten.
201
+ def reload
202
+ return false if not @exists
203
+ t = Calendar.find(service, {:id => @id})
204
+ if t
205
+ load(t.to_xml)
206
+ else
207
+ return false
208
+ end
209
+ end
210
+
211
+ #Returns the xml representation of the Calenar.
212
+ def to_xml
213
+ xml = REXML::Document.new(super)
214
+ xml.root.elements.each(){}.map do |ele|
215
+ case ele.name
216
+ when "summary"
217
+ ele.text = @summary
218
+ when "timezone"
219
+ ele.attributes["value"] = @timezone
220
+ when "hidden"
221
+ ele.attributes["value"] = @hidden.to_s
222
+ when "color"
223
+ ele.attributes["value"] = @color
224
+ when "selected"
225
+ ele.attributes["value"] = @selected.to_s
226
+ end
227
+ end
228
+ xml.to_s
229
+ end
230
+
231
+ #Loads the Calendar with returned data from Google Calendar feed. Returns true if successful.
232
+ def load(string)
233
+ super(string)
234
+ @exists = true
235
+ @xml = string
236
+ xml = REXML::Document.new(string)
237
+ xml.root.elements.each(){}.map do |ele|
238
+ case ele.name
239
+ when "id"
240
+ @id = ele.text.gsub("http://www.google.com/calendar/feeds/default/calendars/", "")
241
+ when 'summary'
242
+ @summary = ele.text
243
+ when "color"
244
+ @color = ele.attributes['value']
245
+ when 'hidden'
246
+ @hidden = ele.attributes["value"] == "true" ? true : false
247
+ when 'timezone'
248
+ @timezone = ele.attributes["value"]
249
+ when "selected"
250
+ @selected = ele.attributes["value"] == "true" ? true : false
251
+ when "link"
252
+ if ele.attributes['rel'] == 'edit'
253
+ @edit_feed = ele.attributes['href']
254
+ end
255
+ when 'accesslevel'
256
+ @editable = (ele.attributes["value"] == 'editor' or ele.attributes["value"] == 'owner' or ele.attributes["value"] == 'root')
257
+ end
258
+ end
259
+
260
+ if @service.check_public
261
+ puts "Getting ACL Feed" if @service.debug
262
+
263
+ #rescue error on shared calenar ACL list access
264
+ begin
265
+ ret = @service.send_request(GData4Ruby::Request.new(:get, @acl_uri))
266
+ rescue Exception => e
267
+ puts "ACL Feed Get Failed: #{e.inspect}" if @service.debug
268
+ @public = false
269
+ return true
270
+ end
271
+ r = REXML::Document.new(ret.read_body)
272
+ r.root.elements.each("entry") do |ele|
273
+ e = GData4Ruby::ACL::AccessRule.new(service, self)
274
+ ele = GData4Ruby::Utils.add_namespaces(ele)
275
+ e.load(ele.to_s)
276
+ puts 'acl rule = '+e.inspect if service.debug
277
+ @public = (e.role.include? 'read' and e.user == 'default')
278
+ puts 'public = '+@public.to_s if service.debug
279
+ break if @public
280
+ end
281
+ else
282
+ @public = false
283
+ end
284
+ return true
285
+ end
286
+
287
+ #Helper function to return a formatted iframe embedded google calendar. Parameters are:
288
+ #1. *params*: a hash of parameters that affect the display of the embedded calendar. Accepts any parameter that the google iframe recognizes. Here are the most common:
289
+ # height:: the height of the embedded calendar in pixels
290
+ # width:: the width of the embedded calendar in pixels
291
+ # title:: the title to display
292
+ # bgcolor:: the background color. Limited choices, see google docs for allowable values.
293
+ # color:: the color of the calendar elements. Limited choices, see google docs for allowable values.
294
+ # showTitle:: set to '0' to hide the title
295
+ # showDate:: set to '0' to hide the current date
296
+ # showNav:: set to '0 to hide the navigation tools
297
+ # showPrint:: set to '0' to hide the print icon
298
+ # showTabs:: set to '0' to hide the tabs
299
+ # showCalendars:: set to '0' to hide the calendars selection drop down
300
+ # showTz:: set to '0' to hide the timezone selection
301
+ # border:: the border width in pixels
302
+ # dates:: a range of dates to display in the format of 'yyyymmdd/yyyymmdd'. Example: 20090820/20091001
303
+ # privateKey:: use to display a private calendar. You can find this key under the calendar settings pane of the Google Calendar website.
304
+ # ctz:: The timezone to convert event times to
305
+ def to_iframe(params = {})
306
+ params[:height] ||= "600"
307
+ params[:width] ||= "600"
308
+ params[:title] ||= (self.title ? self.title : '')
309
+ params[:bgcolor] ||= "#FFFFFF"
310
+ params[:color] ||= "#2952A3"
311
+ params[:border] ||= "0"
312
+ params.each{|key, value| params[key] = CGI::escape(value)}
313
+ output = "#{params.to_a.collect{|a| a.join("=")}.join("&")}"
314
+
315
+ output += "&src=#{id}"
316
+
317
+ "<iframe src='http://www.google.com/calendar/embed?#{output}' style='#{params[:border]} px solid;' width='#{params[:width]}' height='#{params[:height]}' frameborder='#{params[:border]}' scrolling='no'></iframe>"
318
+ end
319
+
320
+ #Helper function to return a specified calendar id as a formatted iframe embedded google calendar. This function does not require loading the calendar information from the Google calendar
321
+ #service, but does require you know the google calendar id.
322
+ #1. *id*: the unique google assigned id for the calendar to display.
323
+ #2. *params*: a hash of parameters that affect the display of the embedded calendar. Accepts any parameter that the google iframe recognizes. Here are the most common:
324
+ # height:: the height of the embedded calendar in pixels
325
+ # width:: the width of the embedded calendar in pixels
326
+ # title:: the title to display
327
+ # bgcolor:: the background color. Limited choices, see google docs for allowable values.
328
+ # color:: the color of the calendar elements. Limited choices, see google docs for allowable values.
329
+ # showTitle:: set to '0' to hide the title
330
+ # showDate:: set to '0' to hide the current date
331
+ # showNav:: set to '0 to hide the navigation tools
332
+ # showPrint:: set to '0' to hide the print icon
333
+ # showTabs:: set to '0' to hide the tabs
334
+ # showCalendars:: set to '0' to hide the calendars selection drop down
335
+ # showTz:: set to '0' to hide the timezone selection
336
+ # border:: the border width in pixels
337
+ # dates:: a range of dates to display in the format of 'yyyymmdd/yyyymmdd'. Example: 20090820/20091001
338
+ # privateKey:: use to display a private calendar. You can find this key under the calendar settings pane of the Google Calendar website.
339
+ def self.to_iframe(id, params = {})
340
+ params[:height] ||= "600"
341
+ params[:width] ||= "600"
342
+ params[:bgcolor] ||= "#FFFFFF"
343
+ params[:color] ||= "#2952A3"
344
+ params[:border] ||= "0"
345
+ params.each{|key, value| params[key] = CGI::escape(value)}
346
+ output = "#{params.to_a.collect{|a| a.join("=")}.join("&")}"
347
+
348
+ output += "&src=#{id}"
349
+
350
+ "<iframe src='http://www.google.com/calendar/embed?#{output}' style='#{params[:border]} px solid;' width='#{params[:width]}' height='#{params[:height]}' frameborder='#{params[:border]}' scrolling='no'></iframe>"
351
+ end
352
+
353
+ private
354
+ def self.get_instance(service, d)
355
+ if d.is_a? Net::HTTPOK
356
+ xml = REXML::Document.new(d.read_body).root
357
+ if xml.name == 'feed'
358
+ xml = xml.elements.each("entry"){}[0]
359
+ end
360
+ else
361
+ xml = d
362
+ end
363
+ ele = GData4Ruby::Utils::add_namespaces(xml)
364
+ cal = Calendar.new(service)
365
+ cal.load(ele.to_s)
366
+ cal
367
+ end
368
+ end
369
+ end