class Autodiscover::PoxRequest

Attributes

client[R]
options[R]

Public Class Methods

new(client, **options) click to toggle source

@param client [Autodiscover::Client] @param [Hash] **options @option **options [Boolean] :ignore_ssl_errors Whether to keep trying if

there are SSL errors
# File lib/autodiscover/pox_request.rb, line 11
def initialize(client, **options)
  @client = client
  @options = options
end

Public Instance Methods

autodiscover() click to toggle source

@return [Autodiscover::PoxResponse, nil]

# File lib/autodiscover/pox_request.rb, line 17
def autodiscover
  available_urls.each do |url|
    begin
      response = client.http.post(url, request_body, {'Content-Type' => 'text/xml; charset=utf-8'})
      return PoxResponse.new(response.body) if good_response?(response)
    rescue Errno::ENETUNREACH, Errno::ECONNREFUSED, HTTPClient::ConnectTimeoutError
      next
    rescue OpenSSL::SSL::SSLError
      options[:ignore_ssl_errors] ? next : raise
    end
  end
end

Private Instance Methods

available_urls() { |url| ... } click to toggle source
# File lib/autodiscover/pox_request.rb, line 38
def available_urls(&block)
  return to_enum(__method__) unless block_given?
  formatted_https_urls.each {|url|
    logger.debug "Yielding HTTPS Url #{url}"
    yield url
  }
  logger.debug "Yielding HTTP Redirected Url #{redirected_http_url}"
  yield redirected_http_url
end
formatted_https_urls() click to toggle source
# File lib/autodiscover/pox_request.rb, line 48
def formatted_https_urls
  @formatted_urls ||= %W{
    https://#{client.domain}/autodiscover/autodiscover.xml
    https://autodiscover.#{client.domain}/autodiscover/autodiscover.xml
  }
end
good_response?(response) click to toggle source
# File lib/autodiscover/pox_request.rb, line 34
def good_response?(response)
  response.status == 200
end
redirected_http_url() click to toggle source
# File lib/autodiscover/pox_request.rb, line 55
def redirected_http_url
  @redirected_http_url ||=
    begin
      response = client.http.get("http://autodiscover.#{client.domain}/autodiscover/autodiscover.xml")
      (response.status == 302) ? response.headers["Location"] : nil
    end
end
request_body() click to toggle source
# File lib/autodiscover/pox_request.rb, line 63
def request_body
  Nokogiri::XML::Builder.new do |xml| 
    xml.Autodiscover('xmlns' => 'http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006') {
      xml.Request {
        xml.EMailAddress client.email
        xml.AcceptableResponseSchema 'http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a'
      }
    }
  end.to_xml
end