diff --git a/lib/parliament/request/base_request.rb b/lib/parliament/request/base_request.rb index c4f49af..81d1e47 100644 --- a/lib/parliament/request/base_request.rb +++ b/lib/parliament/request/base_request.rb @@ -128,9 +128,10 @@ def get(params: nil) # # @param [Hash] params (optional) additional URI encoded form values to be added to the URI. # @param [String] body (optional) body of the post request. + # @param [Integer] timeout (optional) a Net::HTTP.read_timeout value passed suring the post. # # @return [Parliament::Response::BaseResponse] a Parliament::Response::BaseResponse object containing all of the data returned from the URL. - def post(params: nil, body: nil) + def post(params: nil, body: nil, timeout: 60) @query_params = @query_params.merge(params) unless params.nil? endpoint_uri = URI.parse(query_url) @@ -138,6 +139,7 @@ def post(params: nil, body: nil) http = Net::HTTP.new(endpoint_uri.host, endpoint_uri.port) http.use_ssl = true if endpoint_uri.scheme == 'https' + http.read_timeout = timeout request = Net::HTTP::Post.new( endpoint_uri.request_uri, diff --git a/lib/parliament/version.rb b/lib/parliament/version.rb index d311d98..44aae64 100644 --- a/lib/parliament/version.rb +++ b/lib/parliament/version.rb @@ -1,3 +1,3 @@ module Parliament - VERSION = '0.10.0'.freeze + VERSION = '0.10.1'.freeze end diff --git a/spec/parliament/request/base_request_spec.rb b/spec/parliament/request/base_request_spec.rb index d6082de..3495361 100644 --- a/spec/parliament/request/base_request_spec.rb +++ b/spec/parliament/request/base_request_spec.rb @@ -187,5 +187,18 @@ with(:body => '{"foo":"bar","test":true,"number":1}').once end end + + context 'it accepts a timeout' do + before :each do + stub_request(:post, 'http://localhost:3030/people').to_return(status: 200, body: '{}') + end + + it 'still processes our request' do + Parliament::Request::BaseRequest.new(base_url: 'http://localhost:3030/people').post(body: { foo: 'bar', test: true, number: 1 }.to_json, timeout: 1) + + expect(WebMock).to have_requested(:post, 'http://localhost:3030/people'). + with(:body => '{"foo":"bar","test":true,"number":1}').once + end + end end end