Permalink
Browse files

added item_id! and folder_id! to the builder

  • Loading branch information...
1 parent 04ef57d commit e89e5145cf7935272c8bdcf13b1f54d2a420f587 Jeremy Burks committed Dec 18, 2009
Showing with 91 additions and 40 deletions.
  1. +21 −5 lib/ews/builder.rb
  2. +4 −11 lib/ews/service.rb
  3. +66 −24 spec/ews/builder_spec.rb
View
@@ -6,6 +6,18 @@ def base_shape!(shape, opts = {})
shape.add 't:BaseShape', opts[:base_shape]
end
+ # @see http://msdn.microsoft.com/en-us/library/aa580234(EXCHG.80).aspx
+ # ItemId
+ def item_id!(parent, item_id, opts = {})
+ id_element! parent, 't:ItemId', item_id, opts
+ end
+
+ # @see http://msdn.microsoft.com/en-us/library/aa579461(EXCHG.80).aspx
+ # FolderId
+ def folder_id!(parent, folder_id, opts = {})
+ id_element! parent, 't:FolderId', folder_id, opts
+ end
+
# @param parent [Handsoap::XmlMason::Node]
#
# @param folder_name Can only be Exchange named folders. See
@@ -17,11 +29,15 @@ def base_shape!(shape, opts = {})
# @see http://msdn.microsoft.com/en-us/library/aa580808(EXCHG.80).aspx
# DistinguishedFolderId
def distinguished_folder_id!(parent, folder_name, opts = {})
- parent.add('t:DistinguishedFolderId') do |folder_id|
- folder_id.set_attr 'Id', folder_name.to_s.downcase
- if opts[:change_key]
- folder_id.set_attr 'ChangeKey', opts[:change_key]
- end
+ normalized_id = folder_name.to_s.downcase
+ id_element! parent, 't:DistinguishedFolderId', normalized_id, opts
+ end
+
+ private
+ def id_element!(parent, id_name, id, opts = {})
+ parent.add(id_name) do |folder_id|
+ folder_id.set_attr 'Id', id
+ folder_id.set_attr 'ChangeKey', opts[:change_key] if opts[:change_key]
end
end
View
@@ -287,13 +287,8 @@ def get_item(item_id, opts = {})
builder.base_shape! shape, opts
shape.add 't:IncludeMimeContent', false
end
- get_item.add('tns:ItemIds') do |ids|
- ids.add('t:ItemId') do |item|
- item.set_attr 'Id', item_id
- if opts[:change_key]
- item.set_attr 'ChangeKey', opts[:change_key]
- end
- end
+ get_item.add('tns:ItemIds') do |item_ids|
+ builder.item_id! item_ids, item_id, opts
end
end
parser.parse_get_item response.document
@@ -357,10 +352,8 @@ def move_item!(folder_id, item_ids)
folder_id_node.set_attr 'Id', folder_id
end
end
- move_item.add('tns:ItemIds') do |ids|
- item_ids.each do |item_id|
- ids.add('t:ItemId') {|item_node| item_node.set_attr 'Id', item_id }
- end
+ move_item.add('tns:ItemIds') do |ids|
+ item_ids.each {|item_id| builder.item_id! ids, item_id }
end
end
end
View
@@ -7,8 +7,14 @@
@doc.xml_header = nil
EWS::Service.register_aliases! @doc
end
-
+
+ TNS = %q|xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"|
+
context "#base_shape!" do
+ def expected_base_shape(shape)
+ %Q|<t:BaseShape #{TNS}>#{shape}</t:BaseShape>|
+ end
+
it "should build a BaseShape node with 'Default'" do
@builder.base_shape!(@doc)
@doc.to_s.should == expected_base_shape('Default')
@@ -23,36 +29,72 @@
@builder.base_shape!(@doc, :base_shape => 'IdOnly')
@doc.to_s.should == expected_base_shape('IdOnly')
end
+ end
+
+ context '#item_id! should build ItemId' do
+ def expected_item_id
+ %Q|<t:ItemId #{TNS} Id="XYZ" />|
+ end
- context "#distinguished_folder_id! should build a DistinguishedFolderId" do
- it "given a symbol as the folder name " do
- @builder.distinguished_folder_id!(@doc, :inbox)
- @doc.to_s.should == expected_distinguished_folder_id
- end
-
- it "givne a capitalized string as the folder name " do
- @builder.distinguished_folder_id!(@doc, 'Inbox')
- @doc.to_s.should == expected_distinguished_folder_id
- end
+ def expected_item_id_with_change_key
+ %Q|<t:ItemId #{TNS} ChangeKey="123" Id="XYZ" />|
+ end
+
+ it "given an id" do
+ @builder.item_id!(@doc, 'XYZ')
+ @doc.to_s.should == expected_item_id
+ end
- it "with a ChangeKey when the :change_key option is given" do
- @builder.distinguished_folder_id!(@doc, :inbox, :change_key => '222')
- @doc.to_s.should == expected_distinguished_folder_id_with_change_key
- end
+ it "with a ChangeKey whe the :change_key option is given" do
+ @builder.item_id!(@doc, 'XYZ', :change_key => '123')
+ @doc.to_s.should == expected_item_id_with_change_key
end
end
-
- TNS = %q|xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types"|
- def expected_base_shape(shape)
- %Q|<t:BaseShape #{TNS}>#{shape}</t:BaseShape>|
- end
+ context '#folder_id! should build FolderId' do
+ def expected_folder_id
+ %Q|<t:FolderId #{TNS} Id="XYZ" />|
+ end
+
+ def expected_folder_id_with_change_key
+ %Q|<t:FolderId #{TNS} ChangeKey="123" Id="XYZ" />|
+ end
+
+ it "given an id" do
+ @builder.folder_id!(@doc, 'XYZ')
+ @doc.to_s.should == expected_folder_id
+ end
- def expected_distinguished_folder_id
- %Q|<t:DistinguishedFolderId #{TNS} Id="inbox" />|
+ it "with a ChangeKey whe the :change_key option is given" do
+ @builder.folder_id!(@doc, 'XYZ', :change_key => '123')
+ @doc.to_s.should == expected_folder_id_with_change_key
+ end
end
+
+ context "#distinguished_folder_id! should build a DistinguishedFolderId" do
+ def expected_distinguished_folder_id
+ %Q|<t:DistinguishedFolderId #{TNS} Id="inbox" />|
+ end
- def expected_distinguished_folder_id_with_change_key
- %Q|<t:DistinguishedFolderId #{TNS} ChangeKey="222" Id="inbox" />|
+ def expected_distinguished_folder_id_with_change_key
+ %Q|<t:DistinguishedFolderId #{TNS} ChangeKey="222" Id="inbox" />|
+ end
+
+ it "given a symbol as the folder name " do
+ @builder.distinguished_folder_id!(@doc, :inbox)
+ @doc.to_s.should == expected_distinguished_folder_id
+ end
+
+ it "givne a capitalized string as the folder name " do
+ @builder.distinguished_folder_id!(@doc, 'Inbox')
+ @doc.to_s.should == expected_distinguished_folder_id
+ end
+
+ it "with a ChangeKey when the :change_key option is given" do
+ @builder.distinguished_folder_id!(@doc, :inbox, :change_key => '222')
+ @doc.to_s.should == expected_distinguished_folder_id_with_change_key
+ end
end
+
+
end

0 comments on commit e89e514

Please sign in to comment.