diff --git a/CHANGELOG.md b/CHANGELOG.md index e2ecb9b2..04f38d8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,16 @@ **Enhancements:** -- [#31](github.com/castle/castle-ruby/pull/31/) remove auto-integration with Rails, Padrino, Sinatra (see BREAKING CHANGES, README) - [#35](github.com/castle/castle-ruby/pull/35) dropped unused cookie store class, more informative Castle:Client constructor params +- [#30](github.com/castle/castle-ruby/pull/30) change request timeout to 500ms +- [#31](github.com/castle/castle-ruby/pull/31) remove auto-integration with Rails, Padrino, Sinatra (see BREAKING CHANGES, README) **BREAKING CHANGES:** - add `require 'castle/support/rails'` to have Castle client instance available as `castle` in your Rails controllers - add `require 'castle/support/padrino'` to have Castle client instance available as `castle` in your Padrino helpers - add `require 'castle/support/sinatra'` to have Castle client instance available as `castle` in your Sinatra helpers +- request timeout uses milliseconds unit from now on **Features:** diff --git a/README.md b/README.md index 71d30387..d57faee1 100644 --- a/README.md +++ b/README.md @@ -55,8 +55,8 @@ Castle.configure do |config| # Same as setting it through Castle.api_secret config.api_secret = 'secret' - # Castle::RequestError is raised when timing out (default: 30.0) - config.request_timeout = 2.0 + # Castle::RequestError is raised when timing out in seconds (default: 500 milliseconds) + config.request_timeout = 2000 # For tracking in non-web environments: https://castle.io/docs/sources (default: 'web') config.source_header = 'backend' diff --git a/lib/castle/api.rb b/lib/castle/api.rb index 9ef6c7a4..39d6f2bd 100644 --- a/lib/castle/api.rb +++ b/lib/castle/api.rb @@ -27,7 +27,7 @@ def prepare_http @config_api_endpoint.host, @config_api_endpoint.port ) - http.read_timeout = @config.request_timeout + http.read_timeout = @config.request_timeout / 1000.0 prepare_http_for_ssl(http) if @config_api_endpoint.scheme == 'https' http end diff --git a/lib/castle/configuration.rb b/lib/castle/configuration.rb index f1dc2dc5..d34a5269 100644 --- a/lib/castle/configuration.rb +++ b/lib/castle/configuration.rb @@ -3,7 +3,8 @@ module Castle # manages configuration variables class Configuration - REQUEST_TIMEOUT = 30.0 + SUPPORTED = %i[source_header request_timeout api_secret api_endpoint].freeze + REQUEST_TIMEOUT = 500 # in milliseconds API_ENDPOINT = 'https://api.castle.io/v1' WHITELISTED = [ 'User-Agent', diff --git a/spec/lib/castle/configuration_spec.rb b/spec/lib/castle/configuration_spec.rb index 9835eae7..39be032a 100644 --- a/spec/lib/castle/configuration_spec.rb +++ b/spec/lib/castle/configuration_spec.rb @@ -64,7 +64,7 @@ describe 'request_timeout' do it do - expect(config.request_timeout).to be_eql(30.0) + expect(config.request_timeout).to be_eql(500) end context 'setter' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 5f4404d6..f45e3391 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,7 +20,6 @@ RSpec.configure do |config| config.before(:each) do Castle.config.api_endpoint = 'https://api.castle.io/v1' - Castle.config.request_timeout = 30.0 stub_request(:any, /api.castle.io/) .to_return(status: 200, body: '{}', headers: {}) end