Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add class method to set global default timeout

Closes gh-36
  • Loading branch information...
commit 8cba0ccdb2781a8d099ef79e4656911b195b3916 1 parent fd67f32
@urajat urajat authored sandro committed
Showing with 23 additions and 0 deletions.
  1. +12 −0 lib/httparty.rb
  2. +11 −0 spec/httparty_spec.rb
View
12 lib/httparty.rb
@@ -94,6 +94,18 @@ def default_params(h={})
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.
#
View
11 spec/httparty_spec.rb
@@ -203,6 +203,17 @@ def second_method
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
Please sign in to comment.
Something went wrong with that request. Please try again.