gcal4ruby 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,4 +1,7 @@
1
1
  #=CHANGELOG
2
+ #==version 0.2.0
3
+ #* Fixed redirect URI query params problem
4
+ #* Updated syntax for finding events to include most google api parameters, Non-backwards compatible.
2
5
  #==version 0.1.4
3
6
  #* Added additional search criteria for Event.find
4
7
  #==version 0.1.3
@@ -120,7 +120,7 @@ module GCal4Ruby
120
120
  end
121
121
  puts "Starting post\nHeader: #{header}\nContent: #{content}" if @debug
122
122
  https.start do |http|
123
- ret = http.post(location.path, content, header)
123
+ ret = http.post(location.to_s, content, header)
124
124
  end
125
125
  while ret.is_a?(Net::HTTPRedirection)
126
126
  puts "Redirect recieved, resending post" if @debug
@@ -153,7 +153,7 @@ module GCal4Ruby
153
153
  end
154
154
  puts "Starting post\nHeader: #{header}\nContent: #{content}" if @debug
155
155
  https.start do |http|
156
- ret = http.put(location.path, content, header)
156
+ ret = http.put(location.to_s, content, header)
157
157
  end
158
158
  while ret.is_a?(Net::HTTPRedirection)
159
159
  puts "Redirect recieved, resending post" if @debug
@@ -186,10 +186,10 @@ module GCal4Ruby
186
186
  end
187
187
  puts "Starting post\nHeader: #{header}\n" if @debug
188
188
  http.start do |http|
189
- ret = http.get(location.path, header)
189
+ ret = http.get(location.to_s, header)
190
190
  end
191
191
  while ret.is_a?(Net::HTTPRedirection)
192
- puts "Redirect recieved, resending post" if @debug
192
+ puts "Redirect recieved, resending get to #{ret['location']}" if @debug
193
193
  http.start do |http|
194
194
  ret = http.get(ret['location'], header)
195
195
  end
@@ -198,7 +198,7 @@ module GCal4Ruby
198
198
  puts "20x response recieved\nResponse: \n"+ret.read_body if @debug
199
199
  return ret
200
200
  else
201
- puts "Redirect recieved, resending post" if @debug
201
+ puts "Error recieved, resending get" if @debug
202
202
  raise HTTPGetFailed, ret.body
203
203
  end
204
204
  end
@@ -219,7 +219,7 @@ module GCal4Ruby
219
219
  end
220
220
  puts "Starting post\nHeader: #{header}\n" if @debug
221
221
  https.start do |http|
222
- ret = http.delete(location.path, header)
222
+ ret = http.delete(location.to_s, header)
223
223
  end
224
224
  while ret.is_a?(Net::HTTPRedirection)
225
225
  puts "Redirect recieved, resending post" if @debug
@@ -14,7 +14,7 @@ module GCal4Ruby
14
14
  # event.save
15
15
  #
16
16
  #2. Find an existing Event
17
- # event = Event.find(cal, "Soccer Game", :first)
17
+ # event = Event.find(cal, "Soccer Game", {:scope => :first})
18
18
  #
19
19
  #3. Find all events containing the search term
20
20
  # event = Event.find(cal, "Soccer Game")
@@ -345,19 +345,43 @@ module GCal4Ruby
345
345
  end
346
346
  end
347
347
 
348
- #Finds the event that matches search_term in title or description full text search.
349
- #* The scope parameter can be either :all to return an array of all matches, or :first to return the first match as an Event.
350
- #* The range parameter must be a hash containing a :start and :end values as Times specifying the date range to query by. Defaults to all dates.
351
- def self.find(calendar, search_term = '', scope = :all, range = {})
348
+ #Finds the event that matches a query term in the event title or description.
349
+ #'query' is a string to perform the search on.
350
+ #The params hash can contain the following hash values
351
+ #* *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
+ #* *range*: a hash including a :start and :end time to constrain the search by
353
+ #* *max_results*: an integer indicating the number of results to return. Default is 25.
354
+ #* *sort_order*: either 'ascending' or 'descending'.
355
+ #* *single_events*: either 'true' to return all recurring events as a single entry, or 'false' to return all recurring events as a unique event for each recurrence.
356
+ #* *ctz*: the timezone to return the event times in
357
+ def self.find(calendar, query = '', params = {})
358
+ query_string = ''
359
+
360
+ #parse params hash for values
361
+ range = params[:range] || nil
362
+ max_results = params[:max_results] || nil
363
+ sort_order = params[:sortorder] || nil
364
+ single_events = params[:singleevents] || nil
365
+ timezone = params[:ctz] || nil
366
+
367
+ #set up query string
368
+ query_string += "q=#{query}" if query
369
+ if range
352
370
  if not range.is_a? Hash or (range.size > 0 and (not range[:start].is_a? Time or not range[:end].is_a? Time))
353
371
  raise "The date range must be a hash including the :start and :end date values as Times"
354
372
  else
355
373
  date_range = ''
356
374
  if range.size > 0
357
- date_range = "&start-min=#{range[:start].xmlschema}&start-max=#{range[:end].xmlschema}"
375
+ query_string += "&start-min=#{range[:start].xmlschema}&start-max=#{range[:end].xmlschema}"
358
376
  end
359
377
  end
360
- events = calendar.service.send_get("http://www.google.com/calendar/feeds/#{calendar.id}/private/full?q="+CGI.escape(search_term)+date_range)
378
+ end
379
+ query_string += "&max-results=#{max_results}" if max_results
380
+ query_string += "&sortorder=#{sort_order}" if sort_order
381
+ query_string += "&ctz=#{timezone.gsub(" ", "_")}" if timezone
382
+ query_string += "&singleevents#{single_events}" if single_events
383
+ if query_string
384
+ events = calendar.service.send_get("http://www.google.com/calendar/feeds/default/private/full?"+query_string)
361
385
  ret = []
362
386
  REXML::Document.new(events.read_body).root.elements.each("entry"){}.map do |entry|
363
387
  entry.attributes["xmlns:gCal"] = "http://schemas.google.com/gCal/2005"
@@ -366,13 +390,13 @@ module GCal4Ruby
366
390
  event = Event.new(calendar)
367
391
  event.load("<?xml version='1.0' encoding='UTF-8'?>#{entry.to_s}")
368
392
  ret << event
393
+ end
369
394
  end
370
- if scope == :all
371
- return ret
372
- elsif scope == :first
395
+ if params[:scope] == :first
373
396
  return ret[0]
397
+ else
398
+ return ret
374
399
  end
375
- return false
376
400
  end
377
401
 
378
402
  #Returns true if the event exists on the Google Calendar Service.
@@ -412,7 +436,6 @@ module GCal4Ruby
412
436
  ele.delete_element("gd:reminder")
413
437
  end
414
438
  end
415
- end
416
-
439
+ end
417
440
  end
418
441
 
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.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Reich