Skip to content

Commit

Permalink
Added the ability to set the connection timeout.
Browse files Browse the repository at this point in the history
  • Loading branch information
homerlex committed Oct 11, 2016
1 parent 5595fd2 commit e3bcbf6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ client = Autodiscover::Client.new(email: "[email protected]", password: "t
# Override the domain
client = Autodiscover::Client.new(email: "[email protected]", password: "tps_eq_awesome", domain: "tpsreports.local")

# Set a custom connection timeout
client = Autodiscover::Client.new(email: "[email protected]", password: "tps_eq_awesome", connect_timeout: 5)

# Ignore SSL Errors
client.autodiscover(ignore_ssl_errors: true)
```
Expand Down
3 changes: 2 additions & 1 deletion lib/autodiscover/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ class Client
# with something other than the e-mail. For instance DOMAIN\user
# @param domain [String] An optional domain to provide as an override for
# the one parsed from the e-mail.
def initialize(email:, password:, username: nil, domain: nil)
def initialize(email:, password:, username: nil, domain: nil, connect_timeout: nil)
@email = email
@domain = domain || @email.split("@").last
@http = HTTPClient.new
@http.connect_timeout = connect_timeout if connect_timeout
@username = username || email
@http.set_auth(nil, @username, password)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/autodiscover/pox_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def autodiscover
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
rescue Errno::ENETUNREACH, Errno::ECONNREFUSED, HTTPClient::ConnectTimeoutError
next
rescue OpenSSL::SSL::SSLError
options[:ignore_ssl_errors] ? next : raise
Expand Down

0 comments on commit e3bcbf6

Please sign in to comment.