Method: Viewpoint::EWS::GenericFolder#sync_items!

Defined in:
lib/model/generic_folder.rb

#sync_items!(sync_amount = 256, sync_all = false, opts = {}) ⇒ Hash

Syncronize Items in this folder. If this method is issued multiple times it will continue where the last sync completed.

Parameters:

  • sync_amount (Integer) (defaults to: 256)

    The number of items to synchronize per sync

  • sync_all (Boolean) (defaults to: false)

    Whether to sync all the data by looping through. The default is to just sync the first set. You can manually loop through with multiple calls to #sync_items!

Returns:

  • (Hash)

    Returns a hash with keys for each change type that ocurred. Possible key values are (:create/:udpate/:delete). For create and update changes the values are Arrays of Item or a subclass of Item. For deletes an array of ItemIds are returned wich is a Hash in the form: id”, :change_key=>“change key” See: msdn.microsoft.com/en-us/library/aa565609.aspx



384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/model/generic_folder.rb', line 384

def sync_items!(sync_amount = 256, sync_all = false, opts = {})
  item_shape = opts.has_key?(:item_shape) ? opts.delete(:item_shape) : {:base_shape => 'Default'}
  resp = (Viewpoint::EWS::EWS.instance).ews.sync_folder_items(@folder_id, @sync_state, sync_amount, item_shape)
  parms = resp.items.shift
  @sync_state = parms[:sync_state]
  @synced = parms[:includes_last_item_in_range]
  items = {}
  resp.items.each do |i|
    key = i.keys.first
    items[key] = [] unless items[key].is_a?(Array)
    if(key == :delete || key == :read_flag_change)
      items[key] << i[key][:item_id]
    else
      i_type = i[key].keys.first
      items[key] << (eval "#{i_type.to_s.camel_case}.new(i[key][i_type])")
    end
  end
  items
end