cs210-gcal4ruby 0.5.8.5

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