mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Add class method to set global default timeout
Closes gh-36
This commit is contained in:
parent
fd67f32aeb
commit
8cba0ccdb2
2 changed files with 23 additions and 0 deletions
|
@ -94,6 +94,18 @@ module HTTParty
|
|||
default_options[:default_params].merge!(h)
|
||||
end
|
||||
|
||||
# Allows setting a default timeout for all HTTP calls
|
||||
# Timeout is specified in seconds.
|
||||
#
|
||||
# class Foo
|
||||
# include HTTParty
|
||||
# default_timeout 10
|
||||
# end
|
||||
def default_timeout(t)
|
||||
raise ArgumentError, 'Timeout must be an integer' unless t && t.is_a?(Integer)
|
||||
default_options[:timeout] = t
|
||||
end
|
||||
|
||||
# Set an output stream for debugging, defaults to $stderr.
|
||||
# The output stream is passed on to Net::HTTP#set_debug_output.
|
||||
#
|
||||
|
|
|
@ -203,6 +203,17 @@ describe HTTParty do
|
|||
end
|
||||
end
|
||||
|
||||
describe "default timeout" do
|
||||
it "should default to nil" do
|
||||
@klass.default_options[:timeout].should == nil
|
||||
end
|
||||
|
||||
it "should support updating" do
|
||||
@klass.default_timeout 10
|
||||
@klass.default_options[:timeout].should == 10
|
||||
end
|
||||
end
|
||||
|
||||
describe "debug_output" do
|
||||
it "stores the given stream as a default_option" do
|
||||
@klass.debug_output $stdout
|
||||
|
|
Loading…
Reference in a new issue