Skip to content

Commit

Permalink
Added accessor methods for meeting actions
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenbinns committed Oct 19, 2016
1 parent a20277d commit d73cf56
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/ews/ews_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
require 'ews/room_accessors'
require 'ews/roomlist_accessors'
require 'ews/convert_accessors'
require 'ews/meeting_accessors'

# This class is the glue between the Models and the Web Service.
class Viewpoint::EWSClient
Expand All @@ -20,6 +21,7 @@ class Viewpoint::EWSClient
include Viewpoint::EWS::RoomAccessors
include Viewpoint::EWS::RoomlistAccessors
include Viewpoint::EWS::ConvertAccessors
include Viewpoint::EWS::MeetingAccessors
include Viewpoint::StringUtils

# The instance of Viewpoint::EWS::SOAP::ExchangeWebService
Expand Down
35 changes: 35 additions & 0 deletions lib/ews/meeting_accessors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module Viewpoint::EWS::MeetingAccessors
include Viewpoint::EWS

def accept_meeting(opts)
ews.create_item({
message_disposition: 'SendOnly',
items: [ { accept_item: opts_to_item(opts) } ]
})
end

def decline_meeting(opts)
ews.create_item({
message_disposition: 'SendOnly',
items: [ { decline_item: opts_to_item(opts) } ]
})
end

def tentatively_accept_meeting(opts)
ews.create_item({
message_disposition: 'SendOnly',
items: [ { tentatively_accept_item: opts_to_item(opts) } ]
})
end

private

def opts_to_item(opts)
{
id: opts[:id],
change_key: opts[:change_key],
text: opts[:text],
sensitivity: opts[:sensitivity]
}
end
end
27 changes: 27 additions & 0 deletions lib/ews/soap/builders/ews_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,33 @@ def room_lists!
@nbuild[NS_EWS_MESSAGES].GetRoomLists
end

def accept_item!(opts)
@nbuild[NS_EWS_TYPES].AcceptItem {
reference_item_id!(opts)
body!(opts)
sensitivity!(opts)
}
end

def tentatively_accept_item!(opts)
@nbuild[NS_EWS_TYPES].TentativelyAcceptItem {
reference_item_id!(opts)
body!(opts)
sensitivity!(opts)
}
end

def decline_item!(opts)
@nbuild[NS_EWS_TYPES].DeclineItem {
reference_item_id!(opts)
body!(opts)
sensitivity!(opts)
}
end

def sensitivity!(value)
nbuild[NS_EWS_TYPES].Sensitivity(value[:sensitivity])
end

private

Expand Down
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
require 'turn/autorun'
require_relative 'xml_matcher'

RSpec.configure do |c|
RSpec.configure do |rspec|
rspec.mock_with :rspec do |mocks|
mocks.yield_receiver_to_any_instance_implementation_blocks = false
end
end

Turn.config.format = :outline
Expand Down
92 changes: 92 additions & 0 deletions spec/unit/meeting_accessors_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
require_relative '../spec_helper'

describe Viewpoint::EWS::MeetingAccessors do
let(:ecli) { Viewpoint::EWSClient.new('dontcare', 'dontcare', 'dontcare') }

let(:default_opts) do
{
id: 'foo-id',
change_key: 'change-key',
text: 'example text',
sensitivity: 'Private',
}
end

context "#accept_meeting" do
let(:create_item_request) do
"<soap:Body>
<CreateItem xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\" MessageDisposition=\"SendOnly\">
<Items>
<t:AcceptItem>
<t:ReferenceItemId Id=\"foo-id\" ChangeKey=\"change-key\"/>
<t:Body>example text</t:Body>
<t:Sensitivity>Private</t:Sensitivity>
</t:AcceptItem>
</Items>
</CreateItem>
</soap:Body>"
end

it "should form valid accept item request" do
Viewpoint::EWS::SOAP::ExchangeWebService.any_instance.
should_receive(:do_soap_request) do |request_document|
request_document.at_xpath('//soap:Envelope/soap:Body').to_s.should eq create_item_request
end.
and_return(double(:resp, :status => 'Success'))

ecli.accept_meeting(default_opts)
end
end

context "#decline_meeting" do
let(:create_item_request) do
"<soap:Body>
<CreateItem xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\" MessageDisposition=\"SendOnly\">
<Items>
<t:DeclineItem>
<t:ReferenceItemId Id=\"foo-id\" ChangeKey=\"change-key\"/>
<t:Body>example text</t:Body>
<t:Sensitivity>Private</t:Sensitivity>
</t:DeclineItem>
</Items>
</CreateItem>
</soap:Body>"
end

it "should form valid accept item request" do
Viewpoint::EWS::SOAP::ExchangeWebService.any_instance.
should_receive(:do_soap_request) do |request_document|
request_document.at_xpath('//soap:Envelope/soap:Body').to_s.should eq create_item_request
end.
and_return(double(:resp, :status => 'success'))

ecli.decline_meeting(default_opts)
end
end

context "#tentatively_accept_meeting" do
let(:create_item_request) do
"<soap:Body>
<CreateItem xmlns=\"http://schemas.microsoft.com/exchange/services/2006/messages\" MessageDisposition=\"SendOnly\">
<Items>
<t:TentativelyAcceptItem>
<t:ReferenceItemId Id=\"foo-id\" ChangeKey=\"change-key\"/>
<t:Body>example text</t:Body>
<t:Sensitivity>Private</t:Sensitivity>
</t:TentativelyAcceptItem>
</Items>
</CreateItem>
</soap:Body>"
end

it "should form valid accept item request" do
Viewpoint::EWS::SOAP::ExchangeWebService.any_instance.
should_receive(:do_soap_request) do |request_document|
request_document.at_xpath('//soap:Envelope/soap:Body').to_s.should eq create_item_request
end.
and_return(double(:resp, :status => 'success'))

ecli.tentatively_accept_meeting(default_opts)
end
end
end

0 comments on commit d73cf56

Please sign in to comment.