zimbra 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/zimbra/appointment.rb +56 -17
- data/lib/zimbra/version.rb +1 -1
- metadata +1 -1
data/lib/zimbra/appointment.rb
CHANGED
@@ -156,7 +156,7 @@ module Zimbra
|
|
156
156
|
end
|
157
157
|
|
158
158
|
def last_instance_time
|
159
|
-
instance_times = Zimbra::AppointmentService.
|
159
|
+
instance_times = Zimbra::AppointmentService.find_all_instance_times_of_an_appointment(self)
|
160
160
|
return nil unless instance_times && instance_times.count > 0
|
161
161
|
instance_times.max
|
162
162
|
end
|
@@ -171,25 +171,59 @@ module Zimbra
|
|
171
171
|
|
172
172
|
class AppointmentService < HandsoapAccountService
|
173
173
|
def find_all_by_calendar_id(calendar_id)
|
174
|
-
|
175
|
-
|
174
|
+
appointment_attributes = []
|
175
|
+
cursor = nil
|
176
|
+
while(true) do
|
177
|
+
xml = invoke("n2:SearchRequest") do |message|
|
178
|
+
Builder.find_all_with_query(message, "inid:#{calendar_id}", cursor)
|
179
|
+
end
|
180
|
+
|
181
|
+
new_results = Parser.get_search_response(xml)
|
182
|
+
|
183
|
+
return appointment_attributes if new_results.empty?
|
184
|
+
|
185
|
+
appointment_attributes += new_results
|
186
|
+
|
187
|
+
cursor = new_results.last[:appt][:attributes][:id]
|
176
188
|
end
|
177
|
-
Parser.get_search_response(xml)
|
178
189
|
end
|
179
190
|
|
180
|
-
def
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
191
|
+
def find_all_instance_times_of_an_appointment(appointment)
|
192
|
+
instance_times = []
|
193
|
+
|
194
|
+
cursor = nil
|
195
|
+
while(true) do
|
196
|
+
xml = invoke("n2:SearchRequest") do |message|
|
197
|
+
message.set_attr 'query', "date:#{appointment.date.to_i * 1000}"
|
198
|
+
message.set_attr 'types', 'appointment'
|
199
|
+
message.set_attr 'calExpandInstStart', '1'
|
200
|
+
message.set_attr 'calExpandInstEnd', (Time.now + (86400 * 365 * 10)).to_i * 1000
|
201
|
+
|
202
|
+
if cursor
|
203
|
+
message.add 'cursor' do |cursor_element|
|
204
|
+
cursor_element.set_attr 'id', cursor
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
response_hash = Zimbra::Hash.from_xml(xml.document.to_s)
|
209
|
+
response_hash = response_hash[:Envelope][:Body][:SearchResponse]
|
210
|
+
|
211
|
+
appointments = if response_hash[:appt].nil?
|
212
|
+
[]
|
213
|
+
elsif response_hash[:appt].is_a?(Array)
|
214
|
+
response_hash[:appt]
|
215
|
+
else
|
216
|
+
[response_hash[:appt]]
|
217
|
+
end
|
218
|
+
|
219
|
+
return instance_times if appointments.empty?
|
220
|
+
|
221
|
+
cursor = appointments.last[:attributes][:id]
|
222
|
+
|
223
|
+
appt_hash = appointments.find { |appt| appt[:attributes][:id] == appointment.id }
|
224
|
+
instances = appt_hash[:inst].is_a?(Array) ? appt_hash[:inst] : [appt_hash[:inst]]
|
225
|
+
instance_times += instances.collect { |inst| Time.at(inst[:attributes][:s] / 1000) }
|
186
226
|
end
|
187
|
-
response_hash = Zimbra::Hash.from_xml(xml.document.to_s)
|
188
|
-
response_hash = response_hash[:Envelope][:Body][:SearchResponse]
|
189
|
-
appointments = response_hash[:appt].is_a?(Array) ? response_hash[:appt] : [response_hash[:appt]]
|
190
|
-
appt_hash = appointments.find { |appt| appt[:attributes][:id] == appointment.id }
|
191
|
-
instances = appt_hash[:inst].is_a?(Array) ? appt_hash[:inst] : [appt_hash[:inst]]
|
192
|
-
instances.collect { |inst| Time.at(inst[:attributes][:s] / 1000) }
|
193
227
|
end
|
194
228
|
|
195
229
|
def find_all_by_calendar_id_since(calendar_id, since_date)
|
@@ -231,9 +265,14 @@ module Zimbra
|
|
231
265
|
|
232
266
|
class Builder
|
233
267
|
class << self
|
234
|
-
def find_all_with_query(message, query)
|
268
|
+
def find_all_with_query(message, query, cursor = nil)
|
235
269
|
message.set_attr 'query', query
|
236
270
|
message.set_attr 'types', 'appointment'
|
271
|
+
if cursor
|
272
|
+
message.add 'cursor' do |cursor_element|
|
273
|
+
cursor_element.set_attr 'id', cursor
|
274
|
+
end
|
275
|
+
end
|
237
276
|
end
|
238
277
|
|
239
278
|
def find_by_id(message, id)
|
data/lib/zimbra/version.rb
CHANGED