Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement resolve names #274

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ews/ews_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'ews/calendar_accessors'
require 'ews/room_accessors'
require 'ews/roomlist_accessors'
require 'ews/resolve_names_accessors'
require 'ews/convert_accessors'
require 'ews/meeting_accessors'

Expand All @@ -20,6 +21,7 @@ class Viewpoint::EWSClient
include Viewpoint::EWS::CalendarAccessors
include Viewpoint::EWS::RoomAccessors
include Viewpoint::EWS::RoomlistAccessors
include Viewpoint::EWS::ResolveNamesAccessors
include Viewpoint::EWS::ConvertAccessors
include Viewpoint::EWS::MeetingAccessors
include Viewpoint::StringUtils
Expand Down
57 changes: 57 additions & 0 deletions lib/ews/resolve_names_accessors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
=begin
This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.

Copyright © 2013 Camille Baldock <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=end

module Viewpoint::EWS::ResolveNamesAccessors
include Viewpoint::EWS

# Resolves a contact's name given an email address.
# @see https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/resolvenames-operation
def resolve_names(name, full_contact_data = true)
resp = ews.resolve_names(name, full_contact_data)
resp
end

def mailbox(resolved)
resolved.response_message[:elems][:resolution_set][:elems].first[:resolution][:elems][0][:mailbox][:elems]
end

def contact(resolved)
resolved.response_message[:elems][:resolution_set][:elems].first[:resolution][:elems][1][:contact][:elems]
end

[:display_name, :given_name, :initials, :office_location, :department, :surname, :job_title].each do |item_sym|
define_method(item_sym) do |resolved|
contact_item(contact(resolved), item_sym)
end
end

private

def contact_item(contact, sym)
contact.find{|h| h.first.first == sym}[sym][:text]
end

def get_resolve_names_parser(resp)
if resp.success?
resp
else
raise EwsError, "ResolveNames produced an error: #{resp.code}: #{resp.message}"
end
end

end # Viewpoint::EWS::ResolveNamesAccessors
6 changes: 6 additions & 0 deletions lib/ews/soap/builders/ews_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,12 @@ def room_lists!
@nbuild[NS_EWS_MESSAGES].GetRoomLists
end

def resolve_names!(name, full_contact_data)
@nbuild[NS_EWS_MESSAGES].ResolveNames('ReturnFullContactData' => full_contact_data) {
@nbuild[NS_EWS_MESSAGES].UnresolvedEntry(name)
}
end

def accept_item!(opts)
@nbuild[NS_EWS_TYPES].AcceptItem {
sensitivity!(opts)
Expand Down
38 changes: 38 additions & 0 deletions lib/ews/soap/ews_soap_resolve_names_response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
=begin
This file is a contribution to Viewpoint; the Ruby library for Microsoft Exchange Web Services.

Copyright © 2013 Camille Baldock <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=end

module Viewpoint::EWS::SOAP

# A class for resolve names SOAP returns.
# @attr_reader [String] :message The text from the EWS element <m:ResponseCode>
class EwsSoapResolveNamesResponse < EwsSoapResponse

def response_messages
key = response.keys.first
subresponse = response[key][:elems][0]
response_class = subresponse.keys.first # :response_messages
subresponse[response_class][:elems]
end

def success?
response_messages.first[:resolve_names_response_message][:attribs][:response_class] == "Success"
end

end # EwsSoapResolveNamesResponse

end # Viewpoint::EWS::SOAP
12 changes: 12 additions & 0 deletions lib/ews/soap/exchange_web_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ def get_room_lists
do_soap_request(req, response_class: EwsSoapRoomlistResponse)
end

# Resolves a contact's name given an email address.
# @see https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/resolvenames-operation
def resolve_names(name, full_contact_data)
req = build_soap! do |type, builder|
if(type == :header)
else
builder.resolve_names!(name, full_contact_data)
end
end
do_soap_request(req, response_class: EwsSoapResolveNamesResponse)
end

# Send the SOAP request to the endpoint and parse it.
# @param [String] soapmsg an XML formatted string
# @todo make this work for Viewpoint (imported from SPWS)
Expand Down
1 change: 1 addition & 0 deletions lib/viewpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
require 'ews/soap/ews_soap_free_busy_response'
require 'ews/soap/ews_soap_room_response'
require 'ews/soap/ews_soap_roomlist_response'
require 'ews/soap/ews_soap_resolve_names_response'
require 'ews/soap/builders/ews_builder'
require 'ews/soap/parsers/ews_parser'
require 'ews/soap/parsers/ews_sax_document'
Expand Down
11 changes: 11 additions & 0 deletions spec/soap_data/resolve_names_request.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
<soap:Header>
<t:RequestServerVersion Version="Exchange2010_SP2"/>
</soap:Header>
<soap:Body>
<m:ResolveNames ReturnFullContactData="true">
<m:UnresolvedEntry>[email protected]</m:UnresolvedEntry>
</m:ResolveNames>
</soap:Body>
</soap:Envelope>
21 changes: 21 additions & 0 deletions spec/unit/ews_resolve_names_operation_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require_relative '../spec_helper'

describe "Resolve Names operation on Exchange Data Services" do

#let(:ecli) { Viewpoint::EWSClient.new('dontcare', 'dontcare', 'dontcare') }
before do
con = double('Connection')
@ews = Viewpoint::EWS::SOAP::ExchangeWebService.new con,
{:server_version => Viewpoint::EWS::SOAP::VERSION_2010_SP2}
@ews.stub(:do_soap_request)
end

it "generates ResolveNames XML" do
@ews.should_receive(:do_soap_request) do |request_document|
doc = request_document.to_s.gsub(%r{>\s+}, '>')
doc.should eq load_soap("resolve_names", :request)
end.and_return(double(:resp))
@ews.resolve_names('[email protected]', true)
end

end