clio-gcal4ruby 0.3.2 → 0.3.3

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.
@@ -126,6 +126,8 @@ module GCal4Ruby
126
126
  return ret
127
127
  else
128
128
  puts "invalid response received: "+ret.code if @debug
129
+ puts "error: "+ret.body.inspect if @debug
130
+ puts ret.inspect if @debug
129
131
  raise HTTPPostFailed, ret.body
130
132
  end
131
133
  end
@@ -35,7 +35,7 @@ module GCal4Ruby
35
35
  CALENDAR_FEED = "http://www.google.com/calendar/feeds/default/owncalendars/full"
36
36
 
37
37
  attr_accessor :title, :summary, :hidden, :timezone, :color, :where, :selected
38
- attr_reader :service, :id, :event_feed, :editable, :edit_feed
38
+ attr_reader :service, :id, :event_feed, :editable, :edit_feed, :self_feed
39
39
 
40
40
  def initialize(service, attributes = {})
41
41
  super()
@@ -108,7 +108,7 @@ module GCal4Ruby
108
108
  #calendar object is cleared.
109
109
  def delete
110
110
  if @exists
111
- if @service.send_delete(CALENDAR_FEED+"/"+@id)
111
+ if @service.send_delete(@id)
112
112
  @exists = false
113
113
  @title = nil
114
114
  @summary = nil
@@ -171,11 +171,11 @@ module GCal4Ruby
171
171
  ret
172
172
  end
173
173
 
174
- def self.get(service, id)
175
- url = 'http://www.google.com/calendar/feeds/default/allcalendars/full/'+id
176
- ret = service.send_get(url)
177
- puts "==return=="
178
- puts ret.body
174
+ def self.get(service, self_feed)
175
+ ret = service.send_get(self_feed)
176
+ c = Calendar.new(service)
177
+ c.load(ret.body)
178
+ return c
179
179
  end
180
180
 
181
181
  def self.query(service, query_term)
@@ -229,7 +229,7 @@ module GCal4Ruby
229
229
  xml.root.elements.each(){}.map do |ele|
230
230
  case ele.name
231
231
  when "id"
232
- @id = ele.text.gsub("http://www.google.com/calendar/feeds/default/calendars/", "")
232
+ @id = ele.text #ele.text.gsub("http://www.google.com/calendar/feeds/default/calendars/", "")
233
233
  when 'title'
234
234
  @title = ele.text
235
235
  when 'summary'
@@ -245,6 +245,7 @@ module GCal4Ruby
245
245
  when "link"
246
246
  href = ele.attributes['href']
247
247
  case ele.attributes['rel']
248
+ when "self" then @self_feed = href
248
249
  when "edit" then @edit_feed = href
249
250
  when "http://schemas.google.com/gCal/2005#eventFeed" then @event_feed = href
250
251
  when "http://schemas.google.com/acl/2007#accessControlList" then @acl_feed = href
@@ -64,6 +64,9 @@ module GCal4Ruby
64
64
  attr_accessor :id
65
65
  #Flag indicating whether it is an all day event
66
66
  attr_accessor :all_day
67
+
68
+ attr_accessor :clio_id
69
+ attr_accessor :clio_updated_at
67
70
 
68
71
  @attendees
69
72
 
@@ -80,6 +83,7 @@ module GCal4Ruby
80
83
  #The date the event was last edited
81
84
  attr_reader :edited
82
85
 
86
+
83
87
  #Sets the reminder options for the event. Parameter must be a hash containing one of
84
88
  #:hours, :minutes and :days, which are simply the number of each before the event start date you'd like to
85
89
  #receive the reminder.
@@ -189,8 +193,8 @@ module GCal4Ruby
189
193
  end
190
194
  @xml ||= EVENT_XML
191
195
  @calendar ||= calendar
192
- @transparency ||= "http://schemas.google.com/g/2005#event.opaque"
193
- @status ||= "http://schemas.google.com/g/2005#event.confirmed"
196
+ # @transparency ||= "http://schemas.google.com/g/2005#event.opaque"
197
+ # @status ||= "http://schemas.google.com/g/2005#event.confirmed"
194
198
  @attendees ||= []
195
199
  @all_day ||= false
196
200
  end
@@ -219,6 +223,7 @@ module GCal4Ruby
219
223
 
220
224
  #Returns an XML representation of the event.
221
225
  def to_xml()
226
+ updated_clio_id = false
222
227
  xml = REXML::Document.new(@xml)
223
228
  xml.root.elements.each(){}.map do |ele|
224
229
  case ele.name
@@ -278,6 +283,12 @@ module GCal4Ruby
278
283
  w.attributes["endTime"] = @all_day ? @end.strftime("%Y-%m-%d") : @end.xmlschema
279
284
  set_reminder(w)
280
285
  end
286
+ when "extendedProperty"
287
+ ele.attributes["value"] = case ele.attributes["name"]
288
+ when "http://schemas.goclio.com/g/2010#event" then
289
+ updated_clio_id = true
290
+ { :guid => @clio_id, :updated_at => @clio_updated_at }.to_json
291
+ end
281
292
  end
282
293
  end
283
294
  if not @attendees.empty?
@@ -285,6 +296,10 @@ module GCal4Ruby
285
296
  xml.root.add_element("gd:who", {"email" => a[:email], "valueString" => a[:name], "rel" => "http://schemas.google.com/g/2005#event.attendee"})
286
297
  end
287
298
  end
299
+ unless updated_clio_id
300
+ value = { :guid => @clio_id, :updated_at => @clio_updated_at }.to_json
301
+ xml.root.add_element("gd:extendedProperty", {"name" => "http://schemas.goclio.com/g/2010#event", "value"=> value })
302
+ end
288
303
  xml.to_s
289
304
  end
290
305
 
@@ -297,11 +312,11 @@ module GCal4Ruby
297
312
  xml.root.elements.each(){}.map do |ele|
298
313
  case ele.name
299
314
  when 'updated'
300
- @updated = ele.text
315
+ @updated = Time.parse ele.text
301
316
  when 'published'
302
- @published = ele.text
317
+ @published = Time.parse ele.text
303
318
  when 'edited'
304
- @edited = ele.text
319
+ @edited = Time.parse ele.text
305
320
  when 'id'
306
321
  @id, @edit_feed = ele.text
307
322
  when 'title'
@@ -339,18 +354,26 @@ module GCal4Ruby
339
354
  @status = :confirmed
340
355
  when "http://schemas.google.com/g/2005#event.tentative"
341
356
  @status = :tentative
342
- when "http://schemas.google.com/g/2005#event.cancelled"
357
+ when "http://schemas.google.com/g/2005#event.canceled"
343
358
  @status = :cancelled
344
359
  end
345
360
  when 'recurrence'
346
361
  @recurrence = ele.text #Recurrence.new(ele.text)
347
- when "transparency"
362
+ when "gd:transparency"
348
363
  case ele.attributes["value"]
349
364
  when "http://schemas.google.com/g/2005#event.transparent"
350
365
  @transparency = :free
351
366
  when "http://schemas.google.com/g/2005#event.opaque"
352
367
  @transparency = :busy
353
368
  end
369
+ when "extendedProperty"
370
+ case ele.attributes["name"]
371
+ when "http://schemas.goclio.com/g/2010#event" then
372
+ json = ele.attributes["value"]
373
+ json = ActiveSupport::JSON.decode(json)
374
+ @clio_id = json['guid']
375
+ @clio_updated_at = Time.parse json['updated_at']
376
+ end
354
377
  end
355
378
  end
356
379
  end
@@ -393,10 +416,14 @@ module GCal4Ruby
393
416
  if test
394
417
  puts "id passed, finding event by id" if calendar.service.debug
395
418
  puts "id = "+query if calendar.service.debug
396
- event_id = query.gsub("/events/","/private/full/") #fix provided by groesser3
397
-
398
- es = calendar.service.send_get(event_id)
399
- puts es.inspect if calendar.service.debug
419
+ # event_id = query.gsub("/events/","/private/full/") #fix provided by groesser3
420
+ event_id = query
421
+
422
+ begin
423
+ es = calendar.service.send_get(event_id)
424
+ puts es.inspect if calendar.service.debug
425
+ rescue Exception => e
426
+ end
400
427
  if es
401
428
  entry = REXML::Document.new(es.read_body).root
402
429
  puts 'event found' if calendar.service.debug
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clio-gcal4ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 2
10
- version: 0.3.2
9
+ - 3
10
+ version: 0.3.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mike Reich