Class: Viewpoint::EWS::Connection

Inherits:
Object
  • Object
show all
Includes:
Viewpoint::EWS, ConnectionHelper
Defined in:
lib/ews/connection.rb

Constant Summary

Constants included from Viewpoint::EWS

ConnectingSID

Instance Attribute Summary collapse

Attributes included from Viewpoint::EWS

#logger

Instance Method Summary collapse

Methods included from Viewpoint::EWS

#remove_impersonation, root_logger, #set_impersonation

Methods included from ConnectionHelper

#init_logging!

Constructor Details

#initialize(endpoint, opts = {}) ⇒ Connection

Returns a new instance of Connection.

Parameters:

  • endpoint (String)

    the URL of the web service. @example https://<site>/ews/Exchange.asmx

  • opts (Hash) (defaults to: {})

    Misc config options (mostly for developement)

Options Hash (opts):

  • :ssl_verify_mode (Fixnum)
  • :receive_timeout (Fixnum)

    override the default receive timeout seconds

  • :connect_timeout (Fixnum)

    override the default connect timeout seconds

  • :trust_ca (Array)

    an array of hashed dir paths or a file

  • :user_agent (String)

    the http user agent to use in all requests



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ews/connection.rb', line 35

def initialize(endpoint, opts = {})
  @log = Logging.logger[self.class.name.to_s.to_sym]
  if opts[:user_agent]
    @httpcli = HTTPClient.new(agent_name: opts[:user_agent])
  else
    @httpcli = HTTPClient.new
  end

  if opts[:trust_ca]
    @httpcli.ssl_config.clear_cert_store
    opts[:trust_ca].each do |ca|
      @httpcli.ssl_config.add_trust_ca ca
    end
  end

  @httpcli.ssl_config.verify_mode = opts[:ssl_verify_mode] if opts[:ssl_verify_mode]
  @httpcli.ssl_config.ssl_version = opts[:ssl_version] if opts[:ssl_version]
  # Up the keep-alive so we don't have to do the NTLM dance as often.
  @httpcli.keep_alive_timeout = 60
  @httpcli.receive_timeout = opts[:receive_timeout] if opts[:receive_timeout]
  @httpcli.connect_timeout = opts[:connect_timeout] if opts[:connect_timeout]
  @endpoint = endpoint
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



24
25
26
# File 'lib/ews/connection.rb', line 24

def endpoint
  @endpoint
end

Instance Method Details

#authenticateBoolean

Authenticate to the web service. You don’t have to do this because authentication will happen on the first request if you don’t do it here.

Returns:

  • (Boolean)

    true if authentication is successful, false otherwise



66
67
68
# File 'lib/ews/connection.rb', line 66

def authenticate
  self.get && true
end

#dispatch(ews, soapmsg, opts) ⇒ Object

Every Connection class must have the dispatch method. It is what sends the SOAP request to the server and calls the parser method on the EWS instance.

This was originally in the ExchangeWebService class but it was added here to make the processing chain easier to modify. For example, it allows the reactor pattern to handle the request with a callback.

Parameters:



80
81
82
83
84
85
86
87
88
89
# File 'lib/ews/connection.rb', line 80

def dispatch(ews, soapmsg, opts)
  respmsg = post(soapmsg)
  @log.debug "    Received SOAP Response:\n    ----------------\n    \#{Nokogiri::XML(respmsg).to_xml}\n    ----------------\n  EOF\n  opts[:raw_response] ? respmsg : ews.parse_soap_response(respmsg, opts)\nend\n".gsub(/^ {6}/, '')

#getString

Send a GET to the web service

Returns:

  • (String)

    If the request is successful (200) it returns the body of the response.



94
95
96
# File 'lib/ews/connection.rb', line 94

def get
  check_response( @httpcli.get(@endpoint) )
end

#post(xmldoc) ⇒ String

Send a POST to the web service

Returns:

  • (String)

    If the request is successful (200) it returns the body of the response.



101
102
103
104
# File 'lib/ews/connection.rb', line 101

def post(xmldoc)
  headers = {'Content-Type' => 'text/xml'}
  check_response( @httpcli.post(@endpoint, xmldoc, headers) )
end

#set_auth(user, pass) ⇒ Object



59
60
61
# File 'lib/ews/connection.rb', line 59

def set_auth(user,pass)
  @httpcli.set_auth(@endpoint.to_s, user, pass)
end