Skip to content

Commit 58c5247

Browse files
dquimpercbisnett
authored andcommitted
Separates read_timeout and open_timeout (#186)
* Bumps up version so the timeout param can be used. * Separates read_timeout and open_timeout. * Revert gemspec change
1 parent 945a871 commit 58c5247

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ Hubspot.configure({
3434
client_id: <CLIENT_ID>,
3535
client_secret: <CLIENT_SECRET>,
3636
redirect_uri: <REDIRECT_URI>,
37-
timeout: nil,
37+
read_timeout: nil, # or :timeout to set read_timeout and open_timeout
38+
open_timeout: nil,
3839
})
3940
```
4041

lib/hubspot/config.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Hubspot
55
class Config
66
CONFIG_KEYS = [
77
:hapikey, :base_url, :portal_id, :logger, :access_token, :client_id,
8-
:client_secret, :redirect_uri, :timeout
8+
:client_secret, :redirect_uri, :read_timeout, :open_timeout
99
]
1010
DEFAULT_LOGGER = Logger.new(nil)
1111
DEFAULT_BASE_URL = "https://api.hubapi.com".freeze
@@ -23,7 +23,8 @@ def configure(config)
2323
@client_id = config["client_id"] if config["client_id"].present?
2424
@client_secret = config["client_secret"] if config["client_secret"].present?
2525
@redirect_uri = config["redirect_uri"] if config["redirect_uri"].present?
26-
@timeout = config['timeout']
26+
@read_timeout = config['read_timeout'] || config['timeout']
27+
@open_timeout = config['open_timeout'] || config['timeout']
2728

2829
unless authentication_uncertain?
2930
raise Hubspot::ConfigurationError.new("You must provide either an access_token or an hapikey")

lib/hubspot/connection.rb

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class Connection
55
class << self
66
def get_json(path, opts)
77
url = generate_url(path, opts)
8-
response = get(url, format: :json, timeout: timeout(opts))
8+
response = get(url, format: :json, read_timeout: read_timeout(opts), open_timeout: open_timeout(opts))
99
log_request_and_response url, response
1010
handle_response(response)
1111
end
@@ -14,7 +14,7 @@ def post_json(path, opts)
1414
no_parse = opts[:params].delete(:no_parse) { false }
1515

1616
url = generate_url(path, opts[:params])
17-
response = post(url, body: opts[:body].to_json, headers: { 'Content-Type' => 'application/json' }, format: :json, timeout: timeout(opts))
17+
response = post(url, { body: opts[:body].to_json, headers: { 'Content-Type' => 'application/json' }, format: :json, read_timeout: read_timeout(opts), open_timeout: open_timeout(opts) })
1818
log_request_and_response url, response, opts[:body]
1919
raise(Hubspot::RequestError.new(response)) unless response.success?
2020

@@ -29,7 +29,8 @@ def put_json(path, options)
2929
body: options[:body].to_json,
3030
headers: { "Content-Type" => "application/json" },
3131
format: :json,
32-
timeout: timeout(options)
32+
read_timeout: read_timeout(options),
33+
open_timeout: open_timeout(options),
3334
)
3435

3536
log_request_and_response(url, response, options[:body])
@@ -38,16 +39,20 @@ def put_json(path, options)
3839

3940
def delete_json(path, opts)
4041
url = generate_url(path, opts)
41-
response = delete(url, format: :json, timeout: timeout(opts))
42+
response = delete(url, format: :json, read_timeout: read_timeout(opts), open_timeout: open_timeout(opts))
4243
log_request_and_response url, response, opts[:body]
4344
raise(Hubspot::RequestError.new(response)) unless response.success?
4445
response
4546
end
4647

4748
protected
4849

49-
def timeout(opts = {})
50-
opts.delete(:timeout) || Hubspot::Config.timeout
50+
def read_timeout(opts = {})
51+
opts.delete(:read_timeout) || Hubspot::Config.read_timeout
52+
end
53+
54+
def open_timeout(opts = {})
55+
opts.delete(:open_timeout) || Hubspot::Config.open_timeout
5156
end
5257

5358
def handle_response(response)

0 commit comments

Comments
 (0)