Skip to content

Commit

Permalink
Merge pull request #217 from Thoughtwright-LLC/gf
Browse files Browse the repository at this point in the history
Fixed get_item and get_items to accept :occurrence_item_id
  • Loading branch information
stephenbinns authored Jan 11, 2017
2 parents 6b45466 + 3da89c3 commit e8fec4a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
15 changes: 13 additions & 2 deletions lib/ews/item_accessors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,20 @@ def get_item_args(item_id, opts)
}
default_args[:item_ids] = case item_id
when Hash
[{:item_id => item_id}]
if item_id.keys.index(:id)
[{:item_id => item_id}]
else
[item_id]
end
when Array
item_id.map{|i| {:item_id => {:id => i}}}
item_id.map do |i|
case i
when Hash
i
else
{:item_id => {:id => i}}
end
end
else
[{:item_id => {:id => item_id}}]
end
Expand Down
5 changes: 2 additions & 3 deletions lib/ews/soap/builders/ews_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1186,10 +1186,9 @@ def dispatch_item_id!(iid)
when :item_id
item_id!(item)
when :occurrence_item_id
occurrence_item_id!(
item[:recurring_master_id], item[:change_key], item[:instance_index])
occurrence_item_id!(item)
when :recurring_master_item_id
recurring_master_item_id!(item[:occurrence_id], item[:change_key])
recurring_master_item_id!(item)
else
raise EwsBadArgumentError, "Bad ItemId type. #{type}"
end
Expand Down
37 changes: 37 additions & 0 deletions spec/unit/item_accessors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,41 @@ def self.folders
end
end

context "get_item_args should handle :occurrence_item_id" do
class GetItemArgsAccessor
include Viewpoint::EWS::ItemAccessors
def call_get_item_args(*args)
get_item_args(*args)
end
end

it "should handle an :occurrence_item_id hash" do
occurrence_item_id = {:occurrence_item_id => {:recurring_master_id => 'rid1', :change_key => 'ck', :instance_index => 1}}
result = GetItemArgsAccessor.new.call_get_item_args(occurrence_item_id, {})
result[:item_ids].should eq [occurrence_item_id]
end

it "should handle an Array of :occurrence_item_id hashes" do
occurrences = [
{:occurrence_item_id => {:recurring_master_id => 'rid1', :change_key => 'ck1', :instance_index => 1}},
{:occurrence_item_id => {:recurring_master_id => 'rid2', :change_key => 'ck2', :instance_index => 2}},
{:occurrence_item_id => {:recurring_master_id => 'rid3', :change_key => 'ck3', :instance_index => 3}},
]
result = GetItemArgsAccessor.new.call_get_item_args(occurrences, {})
result[:item_ids].should eq occurrences
end

it "should handle an :id hash" do
id = {:id => 'id1', :change_key => 'ck1'}
result = GetItemArgsAccessor.new.call_get_item_args(id, {})
result[:item_ids].should eq [{:item_id => {:id => 'id1', :change_key => 'ck1'}}]
end

it "should handle an Array of id strings" do
ids = ['id1', 'id2', 'id3']
result = GetItemArgsAccessor.new.call_get_item_args(ids, {})
result[:item_ids].should eq [{:item_id=>{:id => 'id1'}},{:item_id=>{:id => 'id2'}},{:item_id=>{:id => 'id3'}}]
end
end

end

0 comments on commit e8fec4a

Please sign in to comment.