mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-08-10 00:01:09 -04:00
Add configurable timeouts. [#265]
This commit is contained in:
parent
8c6dc1a838
commit
6be76b9754
@ -66,9 +66,12 @@ module Stripe
|
||||
@ssl_bundle_path = DEFAULT_CA_BUNDLE_PATH
|
||||
@verify_ssl_certs = true
|
||||
|
||||
@open_timeout = 30
|
||||
@read_timeout = 80
|
||||
|
||||
class << self
|
||||
attr_accessor :api_key, :api_base, :verify_ssl_certs, :api_version, :connect_base, :uploads_base
|
||||
attr_accessor :api_key, :api_base, :verify_ssl_certs, :api_version, :connect_base, :uploads_base,
|
||||
:open_timeout, :read_timeout
|
||||
end
|
||||
|
||||
def self.api_url(url='', api_base_url=nil)
|
||||
@ -123,8 +126,8 @@ module Stripe
|
||||
end
|
||||
|
||||
request_opts.update(:headers => request_headers(api_key).update(headers),
|
||||
:method => method, :open_timeout => 30,
|
||||
:payload => payload, :url => url, :timeout => 80)
|
||||
:method => method, :open_timeout => open_timeout,
|
||||
:payload => payload, :url => url, :timeout => read_timeout)
|
||||
|
||||
begin
|
||||
response = execute_request(request_opts)
|
||||
|
@ -112,6 +112,29 @@ module Stripe
|
||||
'sk_test_local')
|
||||
end
|
||||
|
||||
should "have default open and read timeouts" do
|
||||
assert_equal Stripe.open_timeout, 30
|
||||
assert_equal Stripe.read_timeout, 80
|
||||
end
|
||||
|
||||
should "allow configurable open and read timeouts" do
|
||||
original_timeouts = Stripe.open_timeout, Stripe.read_timeout
|
||||
|
||||
begin
|
||||
Stripe.open_timeout = 999
|
||||
Stripe.read_timeout = 998
|
||||
|
||||
Stripe.expects(:execute_request).with do |opts|
|
||||
opts[:open_timeout] == 999 && opts[:timeout] == 998
|
||||
end.returns(make_response(make_charge))
|
||||
|
||||
Stripe::Charge.create({:card => {:number => '4242424242424242'}},
|
||||
'sk_test_local')
|
||||
ensure
|
||||
Stripe.open_timeout, Stripe.read_timeout = original_timeouts
|
||||
end
|
||||
end
|
||||
|
||||
context "when specifying per-object credentials" do
|
||||
context "with no global API key set" do
|
||||
should "use the per-object credential when creating" do
|
||||
|
Loading…
x
Reference in New Issue
Block a user