gcal4ruby 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/lib/gcal4ruby/calendar.rb +159 -24
- data/lib/gcal4ruby/service.rb +85 -1
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
#=CHANGELOG
|
2
|
+
#==version 0.2.3
|
3
|
+
#* Implemented to_iframe method for calendars and services to output embeddable iframe text.
|
4
|
+
#* Added switch to turn off ACL check for public calendars. Can increase effeciency if turned off.
|
2
5
|
#==version 0.2.2
|
3
6
|
#* Fixed URL encoding problem in Event.find method.
|
4
7
|
#* cleaned up Event.find method to allow for finding events by id
|
data/lib/gcal4ruby/calendar.rb
CHANGED
@@ -201,6 +201,20 @@ class Calendar
|
|
201
201
|
ret
|
202
202
|
end
|
203
203
|
|
204
|
+
def self.get(service, id)
|
205
|
+
url = 'http://www.google.com/calendar/feeds/default/allcalendars/full/'+id
|
206
|
+
ret = service.send_get(url)
|
207
|
+
puts "==return=="
|
208
|
+
puts ret.body
|
209
|
+
end
|
210
|
+
|
211
|
+
def self.query(service, query_term)
|
212
|
+
url = 'http://www.google.com/calendar/feeds/default/allcalendars/full'+"?q="+CGI.escape(query_term)
|
213
|
+
ret = service.send_get(url)
|
214
|
+
puts "==return=="
|
215
|
+
puts ret.body
|
216
|
+
end
|
217
|
+
|
204
218
|
#Reloads the calendar objects information from the stored server version. Returns true
|
205
219
|
#if successful, otherwise returns false. Any information not saved will be overwritten.
|
206
220
|
def reload
|
@@ -267,39 +281,160 @@ class Calendar
|
|
267
281
|
|
268
282
|
@event_feed = "http://www.google.com/calendar/feeds/#{@id}/private/full"
|
269
283
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
if e.attributes['
|
288
|
-
|
289
|
-
|
290
|
-
|
284
|
+
if @check_public
|
285
|
+
puts "Getting ACL Feed" if @service.debug
|
286
|
+
|
287
|
+
#rescue error on shared calenar ACL list access
|
288
|
+
begin
|
289
|
+
ret = @service.send_get("http://www.google.com/calendar/feeds/#{@id}/acl/full/")
|
290
|
+
rescue Exception => e
|
291
|
+
@public = false
|
292
|
+
@editable = false
|
293
|
+
return true
|
294
|
+
end
|
295
|
+
@editable = true
|
296
|
+
r = REXML::Document.new(ret.read_body)
|
297
|
+
r.root.elements.each("entry") do |ele|
|
298
|
+
ele.elements.each do |e|
|
299
|
+
#puts "e = "+e.to_s if @service.debug
|
300
|
+
#puts "previous element = "+e.previous_element.to_s if @service.debug
|
301
|
+
if e.name == 'role' and e.previous_element.name == 'scope' and e.previous_element.attributes['type'] == 'default'
|
302
|
+
if e.attributes['value'].match('#read')
|
303
|
+
@public = true
|
304
|
+
else
|
305
|
+
@public = false
|
306
|
+
end
|
291
307
|
end
|
292
308
|
end
|
293
309
|
end
|
310
|
+
else
|
311
|
+
@public = false
|
312
|
+
@editable = true
|
294
313
|
end
|
295
314
|
return true
|
296
315
|
end
|
297
316
|
|
298
|
-
#
|
299
|
-
|
300
|
-
|
317
|
+
#Helper function to return the currently loaded calendar formatted iframe embedded google calendar.
|
318
|
+
#1. *params*: a hash of parameters that affect the display of the embedded calendar:
|
319
|
+
# height:: the height of the embedded calendar in pixels
|
320
|
+
# width:: the width of the embedded calendar in pixels
|
321
|
+
# title:: the title to display
|
322
|
+
# bgcolor:: the background color. Limited choices, see google docs for allowable values.
|
323
|
+
# color:: the color of the calendar elements. Limited choices, see google docs for allowable values.
|
324
|
+
# showTitle:: set to 'false' to hide the title
|
325
|
+
# showDate:: set to 'false' to hide the current date
|
326
|
+
# showNav:: set to 'false to hide the navigation tools
|
327
|
+
# showPrint:: set to 'false' to hide the print icon
|
328
|
+
# showTabs:: set to 'false' to hide the tabs
|
329
|
+
# showCalendars:: set to 'false' to hide the calendars selection drop down
|
330
|
+
# showTimezone:: set to 'false' to hide the timezone selection
|
331
|
+
# border:: the border width in pixels
|
332
|
+
# dates:: a range of dates to display in the format of 'yyyymmdd/yyyymmdd'. Example: 20090820/20091001
|
333
|
+
# privateKey:: use to display a private calendar. You can find this key under the calendar settings pane of the Google Calendar website.
|
334
|
+
def to_iframe(params = {})
|
335
|
+
if not self.id
|
336
|
+
raise "The calendar must exist and be saved before you can use this method."
|
337
|
+
end
|
338
|
+
params[:id] = self.id
|
339
|
+
params[:height] ||= "600"
|
340
|
+
params[:width] ||= "600"
|
341
|
+
params[:bgcolor] ||= "#FFFFFF"
|
342
|
+
params[:color] ||= "#2952A3"
|
343
|
+
params[:showTitle] = params[:showTitle] == false ? "showTitle=0" : ''
|
344
|
+
params[:showNav] = params[:showNav] == false ? "showNav=0" : ''
|
345
|
+
params[:showDate] = params[:showDate] == false ? "showDate=0" : ''
|
346
|
+
params[:showPrint] = params[:showPrint] == false ? "showPrint=0" : ''
|
347
|
+
params[:showTabs] = params[:showTabs] == false ? "showTabs=0" : ''
|
348
|
+
params[:showCalendars] = params[:showCalendars] == false ? "showCalendars=0" : ''
|
349
|
+
params[:showTimezone] = params[:showTimezone] == false ? 'showTz=0' : ''
|
350
|
+
params[:border] ||= "0"
|
351
|
+
output = ''
|
352
|
+
params.each do |key, value|
|
353
|
+
case key
|
354
|
+
when :height then output += "height=#{value}"
|
355
|
+
when :width then output += "width=#{value}"
|
356
|
+
when :title then output += "title=#{CGI.escape(value)}"
|
357
|
+
when :bgcolor then output += "bgcolor=#{CGI.escape(value)}"
|
358
|
+
when :color then output += "color=#{CGI.escape(value)}"
|
359
|
+
when :showTitle then output += value
|
360
|
+
when :showDate then output += value
|
361
|
+
when :showNav then output += value
|
362
|
+
when :showPrint then output += value
|
363
|
+
when :showTabs then output += value
|
364
|
+
when :showCalendars then output += value
|
365
|
+
when :showTimezone then output += value
|
366
|
+
when :viewMode then output += "mode=#{value}"
|
367
|
+
when :dates then output += "dates=#{CGI.escape(value)}"
|
368
|
+
when :privateKey then output += "pvttk=#{value}"
|
369
|
+
end
|
370
|
+
output += "&"
|
371
|
+
end
|
372
|
+
|
373
|
+
output += "src=#{params[:id]}&"
|
374
|
+
|
375
|
+
"<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>"
|
301
376
|
end
|
302
377
|
|
378
|
+
#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
|
379
|
+
#service, but does require you know the google calendar id.
|
380
|
+
#1. *id*: the unique google assigned id for the calendar to display.
|
381
|
+
#2. *params*: a hash of parameters that affect the display of the embedded calendar:
|
382
|
+
# height:: the height of the embedded calendar in pixels
|
383
|
+
# width:: the width of the embedded calendar in pixels
|
384
|
+
# title:: the title to display
|
385
|
+
# bgcolor:: the background color. Limited choices, see google docs for allowable values.
|
386
|
+
# color:: the color of the calendar elements. Limited choices, see google docs for allowable values.
|
387
|
+
# showTitle:: set to 'false' to hide the title
|
388
|
+
# showDate:: set to 'false' to hide the current date
|
389
|
+
# showNav:: set to 'false to hide the navigation tools
|
390
|
+
# showPrint:: set to 'false' to hide the print icon
|
391
|
+
# showTabs:: set to 'false' to hide the tabs
|
392
|
+
# showCalendars:: set to 'false' to hide the calendars selection drop down
|
393
|
+
# showTimezone:: set to 'false' to hide the timezone selection
|
394
|
+
# border:: the border width in pixels
|
395
|
+
# dates:: a range of dates to display in the format of 'yyyymmdd/yyyymmdd'. Example: 20090820/20091001
|
396
|
+
# privateKey:: use to display a private calendar. You can find this key under the calendar settings pane of the Google Calendar website.
|
397
|
+
def self.to_iframe(id, params = {})
|
398
|
+
params[:id] = id
|
399
|
+
params[:height] ||= "600"
|
400
|
+
params[:width] ||= "600"
|
401
|
+
params[:bgcolor] ||= "#FFFFFF"
|
402
|
+
params[:color] ||= "#2952A3"
|
403
|
+
params[:showTitle] = params[:showTitle] == false ? "showTitle=0" : ''
|
404
|
+
params[:showNav] = params[:showNav] == false ? "showNav=0" : ''
|
405
|
+
params[:showDate] = params[:showDate] == false ? "showDate=0" : ''
|
406
|
+
params[:showPrint] = params[:showPrint] == false ? "showPrint=0" : ''
|
407
|
+
params[:showTabs] = params[:showTabs] == false ? "showTabs=0" : ''
|
408
|
+
params[:showCalendars] = params[:showCalendars] == false ? "showCalendars=0" : ''
|
409
|
+
params[:showTimezone] = params[:showTimezone] == false ? 'showTz=0' : ''
|
410
|
+
params[:border] ||= "0"
|
411
|
+
output = ''
|
412
|
+
params.each do |key, value|
|
413
|
+
case key
|
414
|
+
when :height then output += "height=#{value}"
|
415
|
+
when :width then output += "width=#{value}"
|
416
|
+
when :title then output += "title=#{CGI.escape(value)}"
|
417
|
+
when :bgcolor then output += "bgcolor=#{CGI.escape(value)}"
|
418
|
+
when :color then output += "color=#{CGI.escape(value)}"
|
419
|
+
when :showTitle then output += value
|
420
|
+
when :showDate then output += value
|
421
|
+
when :showNav then output += value
|
422
|
+
when :showPrint then output += value
|
423
|
+
when :showTabs then output += value
|
424
|
+
when :showCalendars then output += value
|
425
|
+
when :showTimezone then output += value
|
426
|
+
when :viewMode then output += "mode=#{value}"
|
427
|
+
when :dates then output += "dates=#{CGI.escape(value)}"
|
428
|
+
when :privateKey then output += "pvttk=#{value}"
|
429
|
+
end
|
430
|
+
output += "&"
|
431
|
+
end
|
432
|
+
|
433
|
+
output += "src=#{params[:id]}&"
|
434
|
+
|
435
|
+
"<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>"
|
436
|
+
end
|
437
|
+
|
303
438
|
private
|
304
439
|
@xml
|
305
440
|
@exists = false
|
data/lib/gcal4ruby/service.rb
CHANGED
@@ -23,6 +23,15 @@ class Service < Base
|
|
23
23
|
|
24
24
|
# The token returned by the Google servers, used to authorize all subsequent messages
|
25
25
|
attr_reader :auth_token
|
26
|
+
|
27
|
+
# Determines whether GCal4Ruby ensures a calendar is public. Setting this to false can increase speeds by
|
28
|
+
# 50% but can cause errors if you try to do something to a calendar that is not public and you don't have
|
29
|
+
# adequate permissions
|
30
|
+
attr_accessor :check_public
|
31
|
+
|
32
|
+
def initialize
|
33
|
+
@check_public = true
|
34
|
+
end
|
26
35
|
|
27
36
|
# The authenticate method passes the username and password to google servers.
|
28
37
|
# If authentication succeeds, returns true, otherwise raises the AuthenticationFailed error.
|
@@ -56,6 +65,81 @@ class Service < Base
|
|
56
65
|
end
|
57
66
|
return cals
|
58
67
|
end
|
68
|
+
|
69
|
+
#Helper function to return a formatted iframe embedded google calendar. Parameters are:
|
70
|
+
#1. *cals*: either an array of calendar ids, or <em>:all</em> for all calendars, or <em>:first</em> for the first (usally default) calendar
|
71
|
+
#2. *params*: a hash of parameters that affect the display of the embedded calendar:
|
72
|
+
# height:: the height of the embedded calendar in pixels
|
73
|
+
# width:: the width of the embedded calendar in pixels
|
74
|
+
# title:: the title to display
|
75
|
+
# bgcolor:: the background color. Limited choices, see google docs for allowable values.
|
76
|
+
# color:: the color of the calendar elements. Limited choices, see google docs for allowable values.
|
77
|
+
# showTitle:: set to 'false' to hide the title
|
78
|
+
# showDate:: set to 'false' to hide the current date
|
79
|
+
# showNav:: set to 'false to hide the navigation tools
|
80
|
+
# showPrint:: set to 'false' to hide the print icon
|
81
|
+
# showTabs:: set to 'false' to hide the tabs
|
82
|
+
# showCalendars:: set to 'false' to hide the calendars selection drop down
|
83
|
+
# showTimezone:: set to 'false' to hide the timezone selection
|
84
|
+
# border:: the border width in pixels
|
85
|
+
# dates:: a range of dates to display in the format of 'yyyymmdd/yyyymmdd'. Example: 20090820/20091001
|
86
|
+
# privateKey:: use to display a private calendar. You can find this key under the calendar settings pane of the Google Calendar website.
|
87
|
+
def to_iframe(cals, params = {})
|
88
|
+
params[:height] ||= "600"
|
89
|
+
params[:width] ||= "600"
|
90
|
+
params[:title] ||= (self.account ? self.account : '')
|
91
|
+
params[:bgcolor] ||= "#FFFFFF"
|
92
|
+
params[:color] ||= "#2952A3"
|
93
|
+
params[:showTitle] = params[:showTitle] == false ? "showTitle=0" : ''
|
94
|
+
params[:showNav] = params[:showNav] == false ? "showNav=0" : ''
|
95
|
+
params[:showDate] = params[:showDate] == false ? "showDate=0" : ''
|
96
|
+
params[:showPrint] = params[:showPrint] == false ? "showPrint=0" : ''
|
97
|
+
params[:showTabs] = params[:showTabs] == false ? "showTabs=0" : ''
|
98
|
+
params[:showCalendars] = params[:showCalendars] == false ? "showCalendars=0" : ''
|
99
|
+
params[:showTimezone] = params[:showTimezone] == false ? 'showTz=0' : ''
|
100
|
+
params[:border] ||= "0"
|
101
|
+
output = ''
|
102
|
+
puts "params = #{params.inspect}" if self.debug
|
103
|
+
params.each do |key, value|
|
104
|
+
puts "key = #{key} and value = #{value}" if self.debug
|
105
|
+
case key
|
106
|
+
when :height then output += "height=#{value}"
|
107
|
+
when :width then output += "width=#{value}"
|
108
|
+
when :title then output += "title=#{CGI.escape(value)}"
|
109
|
+
when :bgcolor then output += "bgcolor=#{CGI.escape(value)}"
|
110
|
+
when :color then output += "color=#{CGI.escape(value)}"
|
111
|
+
when :showTitle then output += value
|
112
|
+
when :showDate then output += value
|
113
|
+
when :showNav then output += value
|
114
|
+
when :showPrint then output += value
|
115
|
+
when :showTabs then output += value
|
116
|
+
when :showCalendars then output += value
|
117
|
+
when :showTimezone then output += value
|
118
|
+
when :viewMode then output += "mode=#{value}"
|
119
|
+
when :dates then output += "dates=#{CGI.escape(value)}"
|
120
|
+
when :privateKey then output += "pvttk=#{value}"
|
121
|
+
end
|
122
|
+
output += "&"
|
123
|
+
end
|
124
|
+
|
125
|
+
puts "output = #{output}" if self.debug
|
126
|
+
|
127
|
+
if cals.is_a?(Array)
|
128
|
+
for c in cals
|
129
|
+
output += "src=#{c}&"
|
130
|
+
end
|
131
|
+
elsif cals == :all
|
132
|
+
cal_list = calendars()
|
133
|
+
for c in cal_list
|
134
|
+
output += "src=#{c.id}&"
|
135
|
+
end
|
136
|
+
elsif cals == :first
|
137
|
+
cal_list = calendars()
|
138
|
+
output += "src=#{cal_list[0].id}&"
|
139
|
+
end
|
140
|
+
|
141
|
+
"<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>"
|
142
|
+
end
|
59
143
|
end
|
60
144
|
|
61
|
-
end
|
145
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gcal4ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Reich
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-14 00:00:00 +10:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|