gcal4ruby 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/lib/gcal4ruby/calendar.rb +7 -4
- data/lib/gcal4ruby/event.rb +46 -5
- data/test/unit.rb +23 -2
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,4 +1,9 @@
|
|
1
1
|
#=CHANGELOG
|
2
|
+
#==version 0.2.2
|
3
|
+
#* Fixed URL encoding problem in Event.find method.
|
4
|
+
#* cleaned up Event.find method to allow for finding events by id
|
5
|
+
#* updated Calendar.find method to add params hash
|
6
|
+
#* added 'published', 'updated', and 'edited' attributes
|
2
7
|
#==version 0.2.1
|
3
8
|
#* fixed Event.find calendar specification
|
4
9
|
#==version 0.2.0
|
data/lib/gcal4ruby/calendar.rb
CHANGED
@@ -179,7 +179,7 @@ class Calendar
|
|
179
179
|
#should be an appropriately authenticated Service. The term parameter can be any string. The
|
180
180
|
#scope parameter may be either :all to return an array of matches, or :first to return
|
181
181
|
#the first match as a Calendar object.
|
182
|
-
def self.find(service, query_term,
|
182
|
+
def self.find(service, query_term=nil, params = {})
|
183
183
|
t = query_term.downcase
|
184
184
|
cals = service.calendars
|
185
185
|
ret = []
|
@@ -187,10 +187,13 @@ class Calendar
|
|
187
187
|
title = cal.title || ""
|
188
188
|
summary = cal.summary || ""
|
189
189
|
id = cal.id || ""
|
190
|
-
if
|
191
|
-
|
190
|
+
if id == query_term
|
191
|
+
return cal
|
192
|
+
end
|
193
|
+
if title.downcase.match(t) or summary.downcase.match(t)
|
194
|
+
if params[:scope] == :first
|
192
195
|
return cal
|
193
|
-
|
196
|
+
else
|
194
197
|
ret << cal
|
195
198
|
end
|
196
199
|
end
|
data/lib/gcal4ruby/event.rb
CHANGED
@@ -73,6 +73,12 @@ module GCal4Ruby
|
|
73
73
|
attr_reader :end
|
74
74
|
#The reminder settings for the event, returned as a hash
|
75
75
|
attr_reader :reminder
|
76
|
+
#The date the event was created
|
77
|
+
attr_reader :published
|
78
|
+
#The date the event was last updated
|
79
|
+
attr_reader :updated
|
80
|
+
#The date the event was last edited
|
81
|
+
attr_reader :edited
|
76
82
|
|
77
83
|
#Sets the reminder options for the event. Parameter must be a hash containing one of
|
78
84
|
#:hours, :minutes and :days, which are simply the number of each before the event start date you'd like to
|
@@ -210,6 +216,7 @@ module GCal4Ruby
|
|
210
216
|
raise EventSaveFailed
|
211
217
|
end
|
212
218
|
end
|
219
|
+
reload
|
213
220
|
return true
|
214
221
|
end
|
215
222
|
|
@@ -279,6 +286,12 @@ module GCal4Ruby
|
|
279
286
|
@etag = xml.root.attributes['etag']
|
280
287
|
xml.root.elements.each(){}.map do |ele|
|
281
288
|
case ele.name
|
289
|
+
when 'updated'
|
290
|
+
@updated = ele.text
|
291
|
+
when 'published'
|
292
|
+
@published = ele.text
|
293
|
+
when 'edited'
|
294
|
+
@edited = ele.text
|
282
295
|
when 'id'
|
283
296
|
@id, @edit_feed = ele.text
|
284
297
|
when 'title'
|
@@ -333,9 +346,9 @@ module GCal4Ruby
|
|
333
346
|
#Reloads the event data from the Google Calendar Service. Returns true if successful,
|
334
347
|
#false otherwise.
|
335
348
|
def reload
|
336
|
-
t = Event.find(@calendar, @id
|
349
|
+
t = Event.find(@calendar, @id)
|
337
350
|
if t
|
338
|
-
if load(t.
|
351
|
+
if load(t.to_xml)
|
339
352
|
return true
|
340
353
|
else
|
341
354
|
return false
|
@@ -345,8 +358,10 @@ module GCal4Ruby
|
|
345
358
|
end
|
346
359
|
end
|
347
360
|
|
348
|
-
#Finds the event that matches a query term in the event title or description.
|
349
|
-
#
|
361
|
+
#Finds the event that matches a query term in the event title or description.
|
362
|
+
#
|
363
|
+
#'query' is a string to perform the search on or an event id.
|
364
|
+
#
|
350
365
|
#The params hash can contain the following hash values
|
351
366
|
#* *scope*: may be :all or :first, indicating whether to return the first record found or an array of all records that match the query. Default is :all.
|
352
367
|
#* *range*: a hash including a :start and :end time to constrain the search by
|
@@ -357,6 +372,32 @@ module GCal4Ruby
|
|
357
372
|
def self.find(calendar, query = '', params = {})
|
358
373
|
query_string = ''
|
359
374
|
|
375
|
+
begin
|
376
|
+
test = URI.parse(query).scheme
|
377
|
+
rescue Exception => e
|
378
|
+
test = nil
|
379
|
+
end
|
380
|
+
|
381
|
+
if test
|
382
|
+
puts "id passed, finding event by id" if calendar.service.debug
|
383
|
+
es = calendar.service.send_get("http://www.google.com/calendar/feeds/#{calendar.id}/private/full")
|
384
|
+
REXML::Document.new(es.read_body).root.elements.each("entry"){}.map do |entry|
|
385
|
+
puts "element = "+entry.name if calendar.service.debug
|
386
|
+
id = ''
|
387
|
+
entry.elements.each("id") {|v| id = v.text}
|
388
|
+
puts "id = #{id}" if calendar.service.debug
|
389
|
+
if id == query
|
390
|
+
entry.attributes["xmlns:gCal"] = "http://schemas.google.com/gCal/2005"
|
391
|
+
entry.attributes["xmlns:gd"] = "http://schemas.google.com/g/2005"
|
392
|
+
entry.attributes["xmlns"] = "http://www.w3.org/2005/Atom"
|
393
|
+
event = Event.new(calendar)
|
394
|
+
event.load("<?xml version='1.0' encoding='UTF-8'?>#{entry.to_s}")
|
395
|
+
return event
|
396
|
+
end
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
|
360
401
|
#parse params hash for values
|
361
402
|
range = params[:range] || nil
|
362
403
|
max_results = params[:max_results] || nil
|
@@ -365,7 +406,7 @@ module GCal4Ruby
|
|
365
406
|
timezone = params[:ctz] || nil
|
366
407
|
|
367
408
|
#set up query string
|
368
|
-
query_string += "q=#{query}" if query
|
409
|
+
query_string += "q=#{CGI.escape(query)}" if query
|
369
410
|
if range
|
370
411
|
if not range.is_a? Hash or (range.size > 0 and (not range[:start].is_a? Time or not range[:end].is_a? Time))
|
371
412
|
raise "The date range must be a hash including the :start and :end date values as Times"
|
data/test/unit.rb
CHANGED
@@ -67,7 +67,15 @@ def calendar_test
|
|
67
67
|
puts "Test 2 Failed"
|
68
68
|
end
|
69
69
|
|
70
|
-
puts "3.
|
70
|
+
puts "3. Find Calendar by ID"
|
71
|
+
c = Calendar.find(@service, cal.id)
|
72
|
+
if c.title == cal.title
|
73
|
+
successful
|
74
|
+
else
|
75
|
+
failed "#{c.title} not equal to #{cal.title}"
|
76
|
+
end
|
77
|
+
|
78
|
+
puts "4. Delete Calendar"
|
71
79
|
if cal.delete and not cal.title
|
72
80
|
successful
|
73
81
|
else
|
@@ -98,7 +106,20 @@ def event_test
|
|
98
106
|
failed
|
99
107
|
end
|
100
108
|
|
101
|
-
puts "3.
|
109
|
+
puts "3. Reload Event"
|
110
|
+
if event.reload
|
111
|
+
successful
|
112
|
+
end
|
113
|
+
|
114
|
+
puts "4. Find Event by id"
|
115
|
+
e = Event.find(@service.calendars[0], event.id)
|
116
|
+
if e.title == event.title
|
117
|
+
successful
|
118
|
+
else
|
119
|
+
failed "Found event doesn't match existing event"
|
120
|
+
end
|
121
|
+
|
122
|
+
puts "5. Delete Event"
|
102
123
|
if event.delete
|
103
124
|
successful
|
104
125
|
else
|
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.2
|
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-07-16 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|