vcita-gcal4ruby 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,87 @@
1
+ =CHANGELOG
2
+ ==version 0.7.1
3
+ * Forked by vCita
4
+ ==version 0.6.0
5
+ * Updated Service to work with multiple types of GData4Ruby services
6
+ ==version 0.5.5
7
+ * Fixed calendar::find method. Thanks to AB <a.berezovskiy@gmail.com>.
8
+ * Improved recurrence handling. Thanks to John Paul Narowski <jnarowski@gmail.com>.
9
+ * Fixed documentation bug for event reminders.
10
+ * Changed license to LGPLv3.
11
+ ==version 0.5.4
12
+ * Fixed Serviceto_iframe bgcolor bug
13
+ ==version 0.5.3
14
+ * Fixed bug when loading event attributes when initializing
15
+ ==version 0.5.2
16
+ * Fixed calendar.public functionality for making calendars publicly viewable.
17
+ * Fixed to_iframe output methods
18
+ * Fixed issue with creating new events
19
+ ==version 0.5.1
20
+ * Minor fixes to to_iframe methods
21
+ ==version 0.5.0 - MAJOR CHANGES
22
+ * Now using GData4Ruby library as base class for service, calendar, and event objects. This removed the base.rb class, which is now inherited from
23
+ GData4ruby
24
+ * Added 'events' method to service to get all events for an account.
25
+ * Major interface changes to find methods - these are not backwards compatible changes.
26
+ * Changed Eventfind default behavior to search all calendars.
27
+ * Major interface changes to to_iframe methods - these are not backwards compatible changes.
28
+ * Added support for multiple reminders.
29
+ * Improved object relationship for events. Events are now service-centric, i.e. events are instantiated with a service object.
30
+ * Event calendar is now set through a 'calendar' attribute.
31
+ * Fixes to event recurrence handling and display.
32
+ * Added support for reminders with recurring events.
33
+ * Numerous improvements to performance.
34
+ * Calendar objects no longer have to query ACL feed to determine editability.
35
+ * Added support for event statuses: cancelled, tentative or confirmed.
36
+ ==version 0.3.2
37
+ * Updated the Event.find method to support finding all events by passing :all as the query term.
38
+ ==version 0.3.1
39
+ * Fixed Event.find method to work with secondary calendars and google apps accounts. Fix provided by groesser3.
40
+ * Added max results to Calendar.find.
41
+ ==version 0.3.0
42
+ * Rewrote Event.find to improve performance significantly.
43
+ * Added improvements to event recurrence handling, including loading existing recurrences, changing recurring events to non recurring and vice versa.
44
+ * Added support for initialization attributes to Event, Calendar, Service and Recurrence.
45
+ * Fixed query string typo in Event.find. Fix provided by nat.lownes.
46
+ ==version 0.2.11
47
+ * Added support for GML elements in calendar events. Fix provided by nat.lownes.
48
+ * Fixed event status bug where cancelled events were marked confirmed. Fix provided by rifraf.
49
+ ==version 0.2.10
50
+ * Fixed library support for Google Hosted Apps accounts running in forced SSL mode.
51
+ ==version 0.2.9
52
+ * Fixed small SSL redirect bug due to variable misnaming in base.rb. Fix provided by JohnMetta
53
+ ==version 0.2.8
54
+ * Merged changes from edruder and h13ronim from the unofficial github repo - http://github.com/h13ronim/gcal4ruby/commits/master
55
+ ==version 0.2.7
56
+ * Added fix for finding events in calendars that have more than 25 entries
57
+ ==version 0.2.6
58
+ * Added fix for updated google calendar XML per http://cookingandcoding.wordpress.com/2009/06/08/new-ruby-google-calendar-api-gem-gcal4ruby/comment-183
59
+ ==version 0.2.5
60
+ * Added calendar color support to to_iframe methods in Calendar and Service.
61
+ ==version 0.2.4
62
+ * Fixed bug with ACL check in Calendarload
63
+ ==version 0.2.3
64
+ * Implemented to_iframe method for calendars and services to output embeddable iframe text.
65
+ * Added switch to turn off ACL check for public calendars. Can increase effeciency if turned off.
66
+ ==version 0.2.2
67
+ * Fixed URL encoding problem in Event.find method.
68
+ * cleaned up Event.find method to allow for finding events by id
69
+ * updated Calendar.find method to add params hash
70
+ * added 'published', 'updated', and 'edited' attributes
71
+ ==version 0.2.1
72
+ * fixed Event.find calendar specification
73
+ ==version 0.2.0
74
+ * Fixed redirect URI query params problem
75
+ * Updated syntax for finding events to include most google api parameters, Non-backwards compatible.
76
+ ==version 0.1.4
77
+ * Added additional search criteria for Event.find
78
+ ==version 0.1.3
79
+ * Added support for authenticating with Google Hosted Apps accounts
80
+ * Added flag to indicate whether a calendar is editable
81
+ * Added handling to gracefully throw error when trying to create event on a non-editable (shared) calendar
82
+ ==version 0.1.2
83
+ * Fixed to_xml dump problem with hidden and selected attributes
84
+ ==version 0.1.1
85
+ * Added all_day indicator to event to indicate an all day event
86
+ ==version 0.1.0
87
+ * Initial Version
@@ -0,0 +1,111 @@
1
+ # vcita-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 Calendar 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/ (original GCal4Ruby plugin)
16
+
17
+ ### Description
18
+
19
+ GCal4Ruby has three major components: the service, calendar and event objects. Each service
20
+ has many calendars, which in turn have many events. Each service is the representation of a
21
+ google account, and thus must be successfully authenticated using valid Google Calendar
22
+ account credentials.
23
+
24
+ ## Examples
25
+
26
+ Below are some common usage examples. For more examples, check the documentation.
27
+
28
+ ####Service
29
+
30
+ ##### Authenticate with the AuthSub service (quickest, dirtiest)
31
+ service = Service.new
32
+ service.authenticate({:username => "user@gmail.com", :password => "password"})
33
+
34
+ ##### Authenticate using OAuth (more setup, easier for an app)
35
+ service = Service.new({:GData4RubyService => :OAuthService})
36
+ service.authenticate({:access_token=>my_oauth_accesstoken})
37
+
38
+ See [vcita-GData4Ruby](https://github.com/vcita/GData4Ruby) for more details
39
+
40
+ # Get Calendar List
41
+ calendars = service.calendars
42
+
43
+ ### Calendar
44
+ All usages assume a successfully authenticated Service.
45
+ 1. Create a new Calendar
46
+ cal = Calendar.new(service)
47
+
48
+ 2. Find a calendar by ID
49
+ cal = Calendar.find(service, {:id => cal_id})
50
+
51
+ 3. Get all calendar events
52
+ cal = Calendar.find(service, {:id => cal_id})
53
+ events = cal.events
54
+
55
+ 4. Find an existing calendar by title
56
+ cal = Calendar.find(service, {:title => "New Calendar"})
57
+
58
+ 5. Find all calendars containing a search term
59
+ cal = Calendar.find(service, "Soccer Team")
60
+
61
+ ### Event
62
+
63
+ All usages assume a successfully authenticated Service and valid Calendar.
64
+ 1. Create a new Event
65
+ 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"})
66
+ event.save
67
+
68
+ 2. Find an existing Event by title
69
+ event = Event.find(service, {:title => "Soccer Game"})
70
+
71
+ 3. Find an existing Event by ID
72
+ event = Event.find(service, {:id => event.id})
73
+
74
+ 4. Find all events containing the search term
75
+ event = Event.find(service, "Soccer Game")
76
+
77
+ 5. Find all events on a calendar containing the search term
78
+ event = Event.find(service, "Soccer Game", {:calendar => cal.id})
79
+
80
+ 6. Find events within a date range
81
+ event = Event.find(service, "Soccer Game", {'start-min' => Time.parse("01/01/2010").utc.xmlschema, 'start-max' => Time.parse("06/01/2010").utc.xmlschema})
82
+
83
+ 7. Create a recurring event for every saturday
84
+ event = Event.new(service)
85
+ event.title = "Baseball Game"
86
+ event.calendar = cal
87
+ event.where = "Municipal Stadium"
88
+ event.recurrence = Recurrence.new
89
+ event.recurrence.start_time = Time.parse("06/20/2009 at 4:30 PM")
90
+ event.recurrence.end_time = Time.parse("06/20/2009 at 6:30 PM")
91
+ event.recurrence.frequency = {"weekly" => ["SA"]}
92
+ event.save
93
+
94
+ 8. Create an event with a 15 minute email reminder
95
+ event = Event.new(service)
96
+ event.calendar = cal
97
+ event.title = "Dinner with Kate"
98
+ event.start_time = Time.parse("06/20/2009 at 5 pm")
99
+ event.end_time = Time.parse("06/20/2009 at 8 pm")
100
+ event.where = "Luigi's"
101
+ event.reminder = {:minutes => 15, :method => 'email'}
102
+ event.save
103
+
104
+ 9. Create an event with attendees
105
+ event = Event.new(service)
106
+ event.calendar = cal
107
+ event.title = "Dinner with Kate"
108
+ event.start_time = Time.parse("06/20/2009 at 5 pm")
109
+ event.end_time = Time.parse("06/20/2009 at 8 pm")
110
+ event.attendees => {:name => "Kate", :email => "kate@gmail.com"}
111
+ event.save
@@ -0,0 +1 @@
1
+ require "gcal4ruby/service"
@@ -0,0 +1,379 @@
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
+ log("Not Public")
268
+ @public = false
269
+ return true
270
+ end
271
+
272
+ #rescue error on shared calenar ACL list access
273
+ begin
274
+ log("ACL URI: #{@acl_uri}")
275
+ ret = service.send_request(GData4Ruby::Request.new(:get, @acl_uri))
276
+ rescue Exception => e
277
+ log("ACL Feed Get Failed: #{e.inspect}")
278
+ @public = false
279
+ return true
280
+ end
281
+ r = REXML::Document.new(ret.read_body)
282
+ r.root.elements.each("entry") do |ele|
283
+ e = GData4Ruby::ACL::AccessRule.new(service.gdata_service, self)
284
+ ele = GData4Ruby::Utils.add_namespaces(ele)
285
+ e.load(ele.to_s)
286
+ log('ACL Rule: '+e.inspect)
287
+ @public = (e.role.include? 'read' and e.user == 'default')
288
+ log('Public: '+@public.to_s)
289
+ break if @public
290
+ end
291
+ else
292
+ @public = false
293
+ end
294
+ return true
295
+ end
296
+
297
+ #Helper function to return a formatted iframe embedded google calendar. Parameters are:
298
+ #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:
299
+ # height:: the height of the embedded calendar in pixels
300
+ # width:: the width of the embedded calendar in pixels
301
+ # title:: the title to display
302
+ # bgcolor:: the background color. Limited choices, see google docs for allowable values.
303
+ # color:: the color of the calendar elements. Limited choices, see google docs for allowable values.
304
+ # showTitle:: set to '0' to hide the title
305
+ # showDate:: set to '0' to hide the current date
306
+ # showNav:: set to '0 to hide the navigation tools
307
+ # showPrint:: set to '0' to hide the print icon
308
+ # showTabs:: set to '0' to hide the tabs
309
+ # showCalendars:: set to '0' to hide the calendars selection drop down
310
+ # showTz:: set to '0' to hide the timezone selection
311
+ # border:: the border width in pixels
312
+ # dates:: a range of dates to display in the format of 'yyyymmdd/yyyymmdd'. Example: 20090820/20091001
313
+ # privateKey:: use to display a private calendar. You can find this key under the calendar settings pane of the Google Calendar website.
314
+ # ctz:: The timezone to convert event times to
315
+ def to_iframe(params = {})
316
+ params[:height] ||= "600"
317
+ params[:width] ||= "600"
318
+ params[:title] ||= (self.title ? self.title : '')
319
+ params[:bgcolor] ||= "#FFFFFF"
320
+ params[:color] ||= "#2952A3"
321
+ params[:border] ||= "0"
322
+ params.each{|key, value| params[key] = CGI::escape(value)}
323
+ output = "#{params.to_a.collect{|a| a.join("=")}.join("&")}"
324
+
325
+ output += "&src=#{id}"
326
+
327
+ "<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>"
328
+ end
329
+
330
+ #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
331
+ #service, but does require you know the google calendar id.
332
+ #1. *id*: the unique google assigned id for the calendar to display.
333
+ #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:
334
+ # height:: the height of the embedded calendar in pixels
335
+ # width:: the width of the embedded calendar in pixels
336
+ # title:: the title to display
337
+ # bgcolor:: the background color. Limited choices, see google docs for allowable values.
338
+ # color:: the color of the calendar elements. Limited choices, see google docs for allowable values.
339
+ # showTitle:: set to '0' to hide the title
340
+ # showDate:: set to '0' to hide the current date
341
+ # showNav:: set to '0 to hide the navigation tools
342
+ # showPrint:: set to '0' to hide the print icon
343
+ # showTabs:: set to '0' to hide the tabs
344
+ # showCalendars:: set to '0' to hide the calendars selection drop down
345
+ # showTz:: set to '0' to hide the timezone selection
346
+ # border:: the border width in pixels
347
+ # dates:: a range of dates to display in the format of 'yyyymmdd/yyyymmdd'. Example: 20090820/20091001
348
+ # privateKey:: use to display a private calendar. You can find this key under the calendar settings pane of the Google Calendar website.
349
+ def self.to_iframe(id, params = {})
350
+ params[:height] ||= "600"
351
+ params[:width] ||= "600"
352
+ params[:bgcolor] ||= "#FFFFFF"
353
+ params[:color] ||= "#2952A3"
354
+ params[:border] ||= "0"
355
+ params.each{|key, value| params[key] = CGI::escape(value)}
356
+ output = "#{params.to_a.collect{|a| a.join("=")}.join("&")}"
357
+
358
+ output += "&src=#{id}"
359
+
360
+ "<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>"
361
+ end
362
+
363
+ private
364
+ def self.get_instance(service, d)
365
+ if d.is_a? Net::HTTPOK
366
+ xml = REXML::Document.new(d.read_body).root
367
+ if xml.name == 'feed'
368
+ xml = xml.elements.each("entry"){}[0]
369
+ end
370
+ else
371
+ xml = d
372
+ end
373
+ ele = GData4Ruby::Utils::add_namespaces(xml)
374
+ cal = Calendar.new(service)
375
+ cal.load(ele.to_s)
376
+ cal
377
+ end
378
+ end
379
+ end