Skip to content

Commit

Permalink
Minor EWSClient changes: added accessors, fixed variables, added test
Browse files Browse the repository at this point in the history
  • Loading branch information
zenchild committed Nov 20, 2014
1 parent 93de0aa commit f93ba39
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/ews/ews_client.rb
Expand Up @@ -23,7 +23,7 @@ class Viewpoint::EWSClient
include Viewpoint::StringUtils

# The instance of Viewpoint::EWS::SOAP::ExchangeWebService
attr_reader :ews
attr_reader :ews, :endpoint, :username

# Initialize the EWSClient instance.
# @param [String] endpoint The EWS endpoint we will be connecting to
Expand All @@ -37,13 +37,15 @@ class Viewpoint::EWSClient
# Viewpoint::EWS::SOAP::ExchangeWebService.
# @option opts [Object] :http_class specify an alternate HTTP connection class.
# @option opts [Hash] :http_opts options to pass to the connection
def initialize(endpoint, user = nil, pass = nil, opts = {})
def initialize(endpoint, username, password, opts = {})
# dup all. @see ticket https://github.com/zenchild/Viewpoint/issues/68
endpoint, user, pass = endpoint.dup, user.dup, pass.dup
opts = opts.dup
@endpoint = endpoint.dup
@username = username.dup
password = password.dup
opts = opts.dup
http_klass = opts[:http_class] || Viewpoint::EWS::Connection
con = http_klass.new(endpoint, opts[:http_opts] || {})
con.set_auth(user,pass) if(user && pass)
con.set_auth @username, password
@ews = SOAP::ExchangeWebService.new(con, opts)
end

Expand All @@ -53,11 +55,11 @@ def initialize(endpoint, user = nil, pass = nil, opts = {})
# default is to raise a EwsMinimalObjectError.
def set_auto_deepen(deepen, behavior = :raise)
if deepen
@ews.auto_deepen = true
ews.auto_deepen = true
else
behavior = [:raise, :nil].include?(behavior) ? behavior : :raise
@ews.no_auto_deepen_behavior = behavior
@ews.auto_deepen = false
ews.no_auto_deepen_behavior = behavior
ews.auto_deepen = false
end
end

Expand All @@ -69,7 +71,7 @@ def auto_deepen=(deepen)
# @param id [String] Identifier of a Microsoft well known time zone (e.g: 'UTC', 'W. Europe Standard Time')
# @note A list of time zones known by the server can be requested via {EWS::SOAP::ExchangeTimeZones#get_time_zones}
def set_time_zone(microsoft_time_zone_id)
@ews.set_time_zone_context microsoft_time_zone_id
ews.set_time_zone_context microsoft_time_zone_id
end

private
Expand Down
25 changes: 25 additions & 0 deletions spec/ews/ews_client_spec.rb
@@ -0,0 +1,25 @@
require "spec_helper"

describe Viewpoint::EWSClient do

describe "#set_auto_deepen" do
let(:client) { described_class.new "http://www.example.com", "test", "test" }

it "sets autodeepen to true on the web service" do
ews = double "ews"
expect(ews).to receive(:auto_deepen=).with(true) {true}
expect(client).to receive(:ews) {ews}
client.set_auto_deepen true
end

it "sets autodeepen to false on the web service with a behavior of 'raise'" do
ews = double "ews"
expect(ews).to receive(:no_auto_deepen_behavior=).with(:raise) {:raise}
expect(ews).to receive(:auto_deepen=).with(false) {false}
expect(client).to receive(:ews).twice {ews}
client.set_auto_deepen false
end

end

end

0 comments on commit f93ba39

Please sign in to comment.