edave-gcal4ruby 0.6.0

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