Skip to content

Commit

Permalink
Add timeouts configuration for Net::HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
jughead committed Oct 3, 2019
1 parent 1d041b6 commit e201368
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ Create an initializer and add the following line:
```ruby
Mollie::Client.configure do |config|
config.api_key = '<your-api-key>'
# Timeouts (default - 60)
# config.open_timeout = 60
# config.read_timeout = 60
end
```

Expand Down
16 changes: 10 additions & 6 deletions lib/mollie/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ class << self
end

class Configuration
attr_accessor :api_key
attr_accessor :api_key, :open_timeout, :read_timeout

def initialize
@api_key = ''
@open_timeout = 60
@read_timeout = 60
end
end

Expand Down Expand Up @@ -76,11 +78,13 @@ def perform_http_call(http_method, api_method, id = nil, http_body = {}, query =
path += "?#{build_nested_query(camelized_query)}"
end

uri = URI.parse(api_endpoint)
client = Net::HTTP.new(uri.host, uri.port)
client.use_ssl = true
client.verify_mode = OpenSSL::SSL::VERIFY_PEER
client.ca_file = (File.expand_path '../cacert.pem', File.dirname(__FILE__))
uri = URI.parse(api_endpoint)
client = Net::HTTP.new(uri.host, uri.port)
client.use_ssl = true
client.verify_mode = OpenSSL::SSL::VERIFY_PEER
client.ca_file = (File.expand_path '../cacert.pem', File.dirname(__FILE__))
client.read_timeout = self.class.configuration.read_timeout
client.open_timeout = self.class.configuration.open_timeout

case http_method
when 'GET'
Expand Down

0 comments on commit e201368

Please sign in to comment.