groesser3-gcal4ruby 0.5.51

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -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,371 @@
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 = "https://www.google.com/calendar/feeds/default/owncalendars/full/"
46
+ CALENDAR_QUERY_FEED = "https://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
+ attr_reader :cal_id
80
+
81
+ #Accepts a Service object and an optional attributes hash for initialization. Returns the new Calendar
82
+ #if successful, otherwise raises the InvalidService error.
83
+ def initialize(service, attributes = {})
84
+ super(service, attributes)
85
+ if !service.is_a?(Service)
86
+ raise InvalidService
87
+ end
88
+ @xml = CALENDAR_XML
89
+ @service ||= service
90
+ @exists = false
91
+ @title ||= ""
92
+ @summary ||= ""
93
+ @public ||= false
94
+ @hidden ||= false
95
+ @timezone ||= "America/Los_Angeles"
96
+ @color ||= "#2952A3"
97
+ @where ||= ""
98
+ attributes.each do |key, value|
99
+ self.send("#{key}=", value)
100
+ end
101
+ return true
102
+ end
103
+
104
+ #Returns true if the calendar exists on the Google Calendar system (i.e. was
105
+ #loaded or has been saved). Otherwise returns false.
106
+ def exists?
107
+ return @exists
108
+ end
109
+
110
+ #Returns true if the calendar is publically accessable, otherwise returns false.
111
+ def public?
112
+ return @public
113
+ end
114
+
115
+ #Returns an array of Event objects corresponding to each event in the calendar.
116
+ def events
117
+ events = []
118
+ ret = @service.send_request(GData4Ruby::Request.new(:get, @content_uri))
119
+ REXML::Document.new(ret.body).root.elements.each("entry"){}.map do |entry|
120
+ entry = GData4Ruby::Utils.add_namespaces(entry)
121
+ e = Event.new(service)
122
+ if e.load(entry.to_s)
123
+ events << e
124
+ end
125
+ end
126
+ return events
127
+ end
128
+
129
+
130
+ #Saves the calendar.
131
+ def save
132
+ public = @public
133
+ ret = super
134
+ return ret if public == @public
135
+ if public
136
+ puts 'setting calendar to public' if service.debug
137
+ rule = GData4Ruby::ACL::AccessRule.new(service, self)
138
+ rule.role = 'http://schemas.google.com/gCal/2005#read'
139
+ rule.save
140
+ else
141
+ rule = GData4Ruby::ACL::AccessRule.find(service, self, {:user => 'default'})
142
+ rule.delete if rule
143
+ end
144
+ reload
145
+ end
146
+
147
+ #Set the calendar to public (p = true) or private (p = false). Publically viewable
148
+ #calendars can be accessed by anyone without having to log in to google calendar. See
149
+ #Calendar#to_iframe on how to display a public calendar in a webpage.
150
+ def public=(p)
151
+ @public = p
152
+ end
153
+
154
+ #Creates a new instance of the object
155
+ def create
156
+ return service.send_request(GData4Ruby::Request.new(:post, CALENDAR_FEED, to_xml()))
157
+ end
158
+
159
+ #Finds a Calendar based on a text query or by an id. Parameters are:
160
+ #*service*:: A valid Service object to search.
161
+ #*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.
162
+ #*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:
163
+ # {'max-results' => '100'}
164
+ #If an ID is specified, a single instance of the calendar is returned if found, otherwise false.
165
+ #If a query term or title text is specified, and array of matching results is returned, or an empty array if nothing
166
+ #was found.
167
+ def self.find(service, query, args = {})
168
+ raise ArgumentError, 'query must be a hash or string' if not query.is_a? Hash and not query.is_a? String
169
+ if query.is_a? Hash and query[:id]
170
+ id = query[:id]
171
+ puts "id passed, finding calendar by id" if service.debug
172
+ puts "id = "+id if service.debug
173
+ #p id.id
174
+ d = service.send_request(GData4Ruby::Request.new(:get, CALENDAR_FEED+id, {"If-Not-Match" => "*"}))
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("https://www.google.com/calendar/feeds/default/calendars/", "")
241
+ #p @id #??
242
+ @cal_id = ele.text.gsub("http://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
+ puts "Getting ACL Feed" if @service.debug
264
+
265
+ #rescue error on shared calenar ACL list access
266
+ begin
267
+ ret = @service.send_request(GData4Ruby::Request.new(:get, @acl_uri))
268
+ rescue Exception => e
269
+ puts "ACL Feed Get Failed: #{e.inspect}" if @service.debug
270
+ @public = false
271
+ return true
272
+ end
273
+ r = REXML::Document.new(ret.read_body)
274
+ r.root.elements.each("entry") do |ele|
275
+ e = GData4Ruby::ACL::AccessRule.new(service, self)
276
+ ele = GData4Ruby::Utils.add_namespaces(ele)
277
+ e.load(ele.to_s)
278
+ puts 'acl rule = '+e.inspect if service.debug
279
+ @public = (e.role.include? 'read' and e.user == 'default')
280
+ puts 'public = '+@public.to_s if service.debug
281
+ break if @public
282
+ end
283
+ else
284
+ @public = false
285
+ end
286
+ return true
287
+ end
288
+
289
+ #Helper function to return a formatted iframe embedded google calendar. Parameters are:
290
+ #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:
291
+ # height:: the height of the embedded calendar in pixels
292
+ # width:: the width of the embedded calendar in pixels
293
+ # title:: the title to display
294
+ # bgcolor:: the background color. Limited choices, see google docs for allowable values.
295
+ # color:: the color of the calendar elements. Limited choices, see google docs for allowable values.
296
+ # showTitle:: set to '0' to hide the title
297
+ # showDate:: set to '0' to hide the current date
298
+ # showNav:: set to '0 to hide the navigation tools
299
+ # showPrint:: set to '0' to hide the print icon
300
+ # showTabs:: set to '0' to hide the tabs
301
+ # showCalendars:: set to '0' to hide the calendars selection drop down
302
+ # showTz:: set to '0' to hide the timezone selection
303
+ # border:: the border width in pixels
304
+ # dates:: a range of dates to display in the format of 'yyyymmdd/yyyymmdd'. Example: 20090820/20091001
305
+ # privateKey:: use to display a private calendar. You can find this key under the calendar settings pane of the Google Calendar website.
306
+ # ctz:: The timezone to convert event times to
307
+ def to_iframe(params = {})
308
+ params[:height] ||= "600"
309
+ params[:width] ||= "600"
310
+ params[:title] ||= (self.title ? self.title : '')
311
+ params[:bgcolor] ||= "#FFFFFF"
312
+ params[:color] ||= "#2952A3"
313
+ params[:border] ||= "0"
314
+ params.each{|key, value| params[key] = CGI::escape(value)}
315
+ output = "#{params.to_a.collect{|a| a.join("=")}.join("&")}"
316
+
317
+ output += "&src=#{id}"
318
+
319
+ "<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>"
320
+ end
321
+
322
+ #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
323
+ #service, but does require you know the google calendar id.
324
+ #1. *id*: the unique google assigned id for the calendar to display.
325
+ #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:
326
+ # height:: the height of the embedded calendar in pixels
327
+ # width:: the width of the embedded calendar in pixels
328
+ # title:: the title to display
329
+ # bgcolor:: the background color. Limited choices, see google docs for allowable values.
330
+ # color:: the color of the calendar elements. Limited choices, see google docs for allowable values.
331
+ # showTitle:: set to '0' to hide the title
332
+ # showDate:: set to '0' to hide the current date
333
+ # showNav:: set to '0 to hide the navigation tools
334
+ # showPrint:: set to '0' to hide the print icon
335
+ # showTabs:: set to '0' to hide the tabs
336
+ # showCalendars:: set to '0' to hide the calendars selection drop down
337
+ # showTz:: set to '0' to hide the timezone selection
338
+ # border:: the border width in pixels
339
+ # dates:: a range of dates to display in the format of 'yyyymmdd/yyyymmdd'. Example: 20090820/20091001
340
+ # privateKey:: use to display a private calendar. You can find this key under the calendar settings pane of the Google Calendar website.
341
+ def self.to_iframe(id, params = {})
342
+ params[:height] ||= "600"
343
+ params[:width] ||= "600"
344
+ params[:bgcolor] ||= "#FFFFFF"
345
+ params[:color] ||= "#2952A3"
346
+ params[:border] ||= "0"
347
+ params.each{|key, value| params[key] = CGI::escape(value)}
348
+ output = "#{params.to_a.collect{|a| a.join("=")}.join("&")}"
349
+
350
+ output += "&src=#{id}"
351
+
352
+ "<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>"
353
+ end
354
+
355
+ private
356
+ def self.get_instance(service, d)
357
+ if d.is_a? Net::HTTPOK
358
+ xml = REXML::Document.new(d.read_body).root
359
+ if xml.name == 'feed'
360
+ xml = xml.elements.each("entry"){}[0]
361
+ end
362
+ else
363
+ xml = d
364
+ end
365
+ ele = GData4Ruby::Utils::add_namespaces(xml)
366
+ cal = Calendar.new(service)
367
+ cal.load(ele.to_s)
368
+ cal
369
+ end
370
+ end
371
+ end