clio-gcal4ruby 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -68,6 +68,7 @@ module GCal4Ruby
68
68
  attr_accessor :clio_id
69
69
  attr_accessor :clio_updated_at
70
70
 
71
+
71
72
  @attendees
72
73
 
73
74
  #The event start time
@@ -83,7 +84,6 @@ module GCal4Ruby
83
84
  #The date the event was last edited
84
85
  attr_reader :edited
85
86
 
86
-
87
87
  #Sets the reminder options for the event. Parameter must be a hash containing one of
88
88
  #:hours, :minutes and :days, which are simply the number of each before the event start date you'd like to
89
89
  #receive the reminder.
@@ -119,12 +119,36 @@ module GCal4Ruby
119
119
  #Sets the event's recurrence information to a Recurrence object. Returns the recurrence if successful,
120
120
  #false otherwise
121
121
  def recurrence=(r)
122
- if r.is_a?(Recurrence) or r.nil?
123
- r.event = self unless r.nil?
122
+ if r.is_a?(RiCal.Event.class)
124
123
  @recurrence = r
124
+ elsif r.nil?
125
+ @recurrence = nil
125
126
  else
126
127
  return false
127
128
  end
129
+ if (@recurrence)
130
+ @start = @recurrence.dtstart
131
+ @end = @recurrence.dtend
132
+ if @recurrence.dtstart.is_a?(Date) && @recurrence.dtend.is_a?(Date)
133
+ @all_day = true
134
+ else
135
+ @all_day = false
136
+ end
137
+ end
138
+ @recurrence
139
+ end
140
+
141
+ def recurrence_to_google
142
+ @recurrence.to_s.gsub("BEGIN:VEVENT\n","").gsub("END:VEVENT\n","")
143
+ end
144
+
145
+ def recurrence_from_google(rec)
146
+ rec = "BEGIN:VEVENT\n#{rec}" unless (rec.starts_with? "BEGIN:VEVENT")
147
+ rec = "#{rec}END:VEVENT\n" unless (rec.ends_with? "END:VEVENT\n")
148
+
149
+ rrule = RiCal.parse_string(rec)
150
+ rrule = [rrule].flatten.first
151
+ self.recurrence = rrule
128
152
  end
129
153
 
130
154
  #Returns a duplicate of the current event as a new Event object
@@ -142,6 +166,8 @@ module GCal4Ruby
142
166
  @start = Time.parse(str)
143
167
  elsif str.is_a?Time
144
168
  @start = str
169
+ elsif str.is_a?Date
170
+ @start = str.to_time
145
171
  else
146
172
  raise "Start Time must be either Time or String"
147
173
  end
@@ -154,6 +180,8 @@ module GCal4Ruby
154
180
  @end = Time.parse(str)
155
181
  elsif str.is_a?Time
156
182
  @end = str
183
+ elsif str.is_a?Date
184
+ @end = str.to_time
157
185
  else
158
186
  raise "End Time must be either Time or String"
159
187
  end
@@ -241,7 +269,7 @@ module GCal4Ruby
241
269
  else
242
270
  if not @reminder
243
271
  xml.root.delete_element("/entry/gd:when")
244
- xml.root.add_element("gd:recurrence").text = @recurrence.to_s
272
+ xml.root.add_element("gd:recurrence").text = self.recurrence_to_google
245
273
  else
246
274
  ele.delete_attribute('startTime')
247
275
  ele.delete_attribute('endTime')
@@ -274,7 +302,7 @@ module GCal4Ruby
274
302
  puts 'recurrence element found' if @calendar.service.debug
275
303
  if @recurrence
276
304
  puts 'setting recurrence' if @calendar.service.debug
277
- ele.text = @recurrence.to_s
305
+ ele.text = self.recurrence_to_google
278
306
  else
279
307
  puts 'no recurrence, adding when' if @calendar.service.debug
280
308
  w = xml.root.add_element("gd:when")
@@ -293,7 +321,8 @@ module GCal4Ruby
293
321
  end
294
322
  if not @attendees.empty?
295
323
  @attendees.each do |a|
296
- xml.root.add_element("gd:who", {"email" => a[:email], "valueString" => a[:name], "rel" => "http://schemas.google.com/g/2005#event.attendee"})
324
+ a = xml.root.add_element("gd:who", {"email" => a[:email], "valueString" => a[:name], "rel" => "http://schemas.google.com/g/2005#event.attendee"})
325
+ a.add_element("gd:attendeeStatus", {"value" => "http://schemas.google.com/g/2005#event.accepted"})
297
326
  end
298
327
  end
299
328
  unless updated_clio_id
@@ -329,6 +358,12 @@ module GCal4Ruby
329
358
  ele.elements.each("gd:reminder") do |r|
330
359
  @reminder = {:minutes => r.attributes['minutes'] ? r.attributes['minutes'] : 0, :hours => r.attributes['hours'] ? r.attributes['hours'] : 0, :days => r.attributes['days'] ? r.attributes['days'] : 0, :method => r.attributes['method'] ? r.attributes['method'] : ''}
331
360
  end
361
+
362
+ puts "#{@start.strftime("%Y-%m-%d")} == #{ele.attributes['startTime']} && #{@end.strftime("%Y-%m-%d")} == #{ele.attributes['endTime']}" if @calendar.service.debug
363
+ if @start.strftime("%Y-%m-%d") == ele.attributes['startTime'] && @end.strftime("%Y-%m-%d") == ele.attributes['endTime']
364
+ puts "ALL DAY" if @calendar.service.debug
365
+ @all_day = true
366
+ end
332
367
  when "where"
333
368
  @where = ele.attributes['valueString']
334
369
  when "link"
@@ -358,7 +393,7 @@ module GCal4Ruby
358
393
  @status = :cancelled
359
394
  end
360
395
  when 'recurrence'
361
- @recurrence = ele.text #Recurrence.new(ele.text)
396
+ self.recurrence_from_google(ele.text) #Recurrence.new(ele.text)
362
397
  when "gd:transparency"
363
398
  case ele.attributes["value"]
364
399
  when "http://schemas.google.com/g/2005#event.transparent"
@@ -14,6 +14,8 @@ module GCal4Ruby
14
14
  #The Recurrence class stores information on an Event's recurrence. The class implements
15
15
  #the RFC 2445 iCalendar recurrence description.
16
16
  class Recurrence
17
+ include RiCal
18
+
17
19
  #The event start date/time
18
20
  attr_reader :start
19
21
  #The event end date/time
@@ -27,6 +29,8 @@ module GCal4Ruby
27
29
  #True if the event is all day (i.e. no start/end time)
28
30
  attr_accessor :all_day
29
31
 
32
+ attr_accessor :rrule
33
+
30
34
  #Accepts an optional attributes hash or a string containing a properly formatted ISO 8601 recurrence rule. Returns a new Recurrence object
31
35
  def initialize(vars = {})
32
36
  if vars.is_a? Hash
@@ -41,101 +45,150 @@ module GCal4Ruby
41
45
 
42
46
  #Accepts a string containing a properly formatted ISO 8601 recurrence rule and loads it into the recurrence object
43
47
  def load(rec)
44
- attrs = rec.split("\n")
45
- attrs.each do |val|
46
- key, value = val.split(":")
47
- case key
48
- when 'DTSTART'
49
- @start = Time.parse_complete(value)
50
- when 'DTSTART;VALUE=DATE'
51
- @start = Time.parse(value)
52
- @all_day = true
53
- when 'DTSTART;VALUE=DATE-TIME'
54
- @start = Time.parse_complete(value)
55
- when 'DTEND'
56
- @end = Time.parse_complete(value)
57
- when 'DTEND;VALUE=DATE'
58
- @end = Time.parse(value)
59
- when 'DTEND;VALUE=DATE-TIME'
60
- @end = Time.parse_complete(value)
61
- when 'RRULE'
62
- vals = value.split(";")
63
- key = ''
64
- by = ''
65
- int = nil
66
- vals.each do |rr|
67
- a, h = rr.split("=")
68
- case a
69
- when 'FREQ'
70
- key = h.downcase.capitalize
71
- when 'INTERVAL'
72
- int = h
73
- when 'UNTIL'
74
- @repeat_until = Time.parse(value)
75
- else
76
- by = h.split(",")
77
- end
78
- end
79
- @frequency = {key => by}
80
- @frequency.merge({'interval' => int}) if int
81
- end
48
+ rec = "BEGIN:VEVENT\n#{rec}" unless (rec.starts_with? "BEGIN:VEVENT")
49
+ rec = "#{rec}END:VEVENT\n" unless (rec.ends_with? "END:VEVENT\n")
50
+
51
+ @rrule = RiCal.parse_string(rec)
52
+ if @rrule.is_a? Array
53
+ @rrule = @rrule.first
82
54
  end
55
+ # attrs = rec.split("\n")
56
+ # attrs.each do |val|
57
+ # key, value = val.split(":")
58
+ # case key
59
+ # when 'DTSTART'
60
+ # @start = Time.parse_complete(value)
61
+ # when 'DTSTART;VALUE=DATE'
62
+ # @start = Time.parse(value)
63
+ # @all_day = true
64
+ # when 'DTSTART;VALUE=DATE-TIME'
65
+ # @start = Time.parse_complete(value)
66
+ # when 'DTEND'
67
+ # @end = Time.parse_complete(value)
68
+ # when 'DTEND;VALUE=DATE'
69
+ # @end = Time.parse(value)
70
+ # when 'DTEND;VALUE=DATE-TIME'
71
+ # @end = Time.parse_complete(value)
72
+ # when 'RRULE'
73
+ # vals = value.split(";")
74
+ # key = ''
75
+ # by = ''
76
+ # int = nil
77
+ # vals.each do |rr|
78
+ # a, h = rr.split("=")
79
+ # case a
80
+ # when 'FREQ'
81
+ # key = h.downcase.capitalize
82
+ # when 'INTERVAL'
83
+ # int = h
84
+ # when 'UNTIL'
85
+ # @repeat_until = Time.parse(value)
86
+ # else
87
+ # by = h.split(",")
88
+ # end
89
+ # end
90
+ # @frequency = {key => by}
91
+ # @frequency.merge({'interval' => int}) if int
92
+ # end
93
+ # end
83
94
  end
84
95
 
85
96
  #Returns a string with the correctly formatted ISO 8601 recurrence rule
86
97
  def to_s
87
-
88
- output = ''
89
- if @all_day
90
- output += "DTSTART;VALUE=DATE:#{@start.utc.strftime("%Y%m%d")}\n"
91
- else
92
- output += "DTSTART;VALUE=DATE-TIME:#{@start.complete}\n"
93
- end
94
- if @all_day
95
- output += "DTEND;VALUE=DATE:#{@end.utc.strftime("%Y%m%d")}\n"
96
- else
97
- output += "DTEND;VALUE=DATE-TIME:#{@end.complete}\n"
98
- end
99
- output += "RRULE:"
100
- if @frequency
101
- f = 'FREQ='
102
- i = ''
103
- by = ''
104
- @frequency.each do |key, v|
105
- if v.is_a?(Array)
106
- if v.size > 0
107
- value = v.join(",")
108
- else
109
- value = nil
110
- end
111
- else
112
- value = v
113
- end
114
- f += "#{key.upcase};" if key != 'interval'
115
- case key.downcase
116
- when "secondly"
117
- by += "BYSECOND=#{value};"
118
- when "minutely"
119
- by += "BYMINUTE=#{value};"
120
- when "hourly"
121
- by += "BYHOUR=#{value};"
122
- when "weekly"
123
- by += "BYDAY=#{value};" if value
124
- when "monthly"
125
- by += "BYDAY=#{value};"
126
- when "yearly"
127
- by += "BYYEARDAY=#{value};"
128
- when 'interval'
129
- i += "INTERVAL=#{value};"
130
- end
131
- end
132
- output += f+i+by
133
- end
134
- if @repeat_until
135
- output += "UNTIL=#{@repeat_until.strftime("%Y%m%d")}"
136
- end
137
-
138
- output += "\n"
98
+ return @rrule.to_s.gsub("BEGIN:VEVENT\n","").gsub("END:VEVENT\n","")
99
+ #
100
+ # output = ''
101
+ # if @all_day
102
+ # output += "DTSTART;VALUE=DATE:#{@start.utc.strftime("%Y%m%d")}\n"
103
+ # else
104
+ # output += "DTSTART;VALUE=DATE-TIME:#{@start.complete}\n"
105
+ # end
106
+ # if @all_day
107
+ # output += "DTEND;VALUE=DATE:#{@end.utc.strftime("%Y%m%d")}\n"
108
+ # else
109
+ # output += "DTEND;VALUE=DATE-TIME:#{@end.complete}\n"
110
+ # end
111
+ # output += "RRULE:"
112
+ # if @frequency
113
+ # f = 'FREQ='
114
+ # i = ''
115
+ # by = ''
116
+ # @frequency.each do |key, v|
117
+ # if v.is_a?(Array)
118
+ # if v.size > 0
119
+ # value = v.join(",")
120
+ # else
121
+ # value = nil
122
+ # end
123
+ # else
124
+ # value = v
125
+ # end
126
+ # f += "#{key.upcase};" if key != 'interval'
127
+ # case key.downcase
128
+ # when "secondly"
129
+ # by += "BYSECOND=#{value};"
130
+ # when "minutely"
131
+ # by += "BYMINUTE=#{value};"
132
+ # when "hourly"
133
+ # by += "BYHOUR=#{value};"
134
+ # when "weekly"
135
+ # by += "BYDAY=#{value};" if value
136
+ # when "monthly"
137
+ # by += "BYDAY=#{value};"
138
+ # when "yearly"
139
+ # by += "BYYEARDAY=#{value};"
140
+ # when 'interval'
141
+ # i += "INTERVAL=#{value};"
142
+ # end
143
+ # end
144
+ # output += f+i+by
145
+ # end
146
+ # if @repeat_until
147
+ # output += "UNTIL=#{@repeat_until.strftime("%Y%m%d")}"
148
+ # end
149
+ #
150
+ # output += "\n"
151
+ end
152
+
153
+ def to_clio_s
154
+ # output = ""
155
+ # if @frequency
156
+ # f = 'FREQ='
157
+ # i = ''
158
+ # by = ''
159
+ # @frequency.each do |key, v|
160
+ # if v.is_a?(Array)
161
+ # if v.size > 0
162
+ # value = v.join(",")
163
+ # else
164
+ # value = nil
165
+ # end
166
+ # else
167
+ # value = v
168
+ # end
169
+ # f += "#{key.upcase};" if key != 'interval'
170
+ # case key.downcase
171
+ # when "secondly"
172
+ # by += "BYSECOND=#{value};"
173
+ # when "minutely"
174
+ # by += "BYMINUTE=#{value};"
175
+ # when "hourly"
176
+ # by += "BYHOUR=#{value};"
177
+ # when "weekly"
178
+ # by += "BYDAY=#{value};" if value
179
+ # when "monthly"
180
+ # by += "BYDAY=#{value};"
181
+ # when "yearly"
182
+ # by += "BYYEARDAY=#{value};"
183
+ # when 'interval'
184
+ # i += "INTERVAL=#{value};"
185
+ # end
186
+ # end
187
+ # output += f+i+by
188
+ # end
189
+ # if @repeat_until
190
+ # output += "UNTIL=#{@repeat_until.strftime("%Y%m%d")}"
191
+ # end
139
192
  end
140
193
 
141
194
  #Sets the start date/time. Must be a Time object.
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: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 4
10
- version: 0.3.4
9
+ - 5
10
+ version: 0.3.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mike Reich