diff --git a/README.md b/README.md index 8bc249d..da82376 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,9 @@ Create an initializer and add the following line: ```ruby Mollie::Client.configure do |config| config.api_key = '' + # Timeouts (default - 60) + # config.open_timeout = 60 + # config.read_timeout = 60 end ``` diff --git a/lib/mollie/client.rb b/lib/mollie/client.rb index c189383..b6614cb 100644 --- a/lib/mollie/client.rb +++ b/lib/mollie/client.rb @@ -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 @@ -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'