Merge pull request #1761 from xhh/ruby-timeout

Ruby client: add "timeout" to configuration
This commit is contained in:
wing328 2015-12-27 23:42:53 +08:00
commit 858d44a27f
5 changed files with 33 additions and 2 deletions

View File

@ -71,6 +71,7 @@ module {{moduleName}}
:method => http_method,
:headers => header_params,
:params => query_params,
:timeout => @config.timeout,
:ssl_verifypeer => @config.verify_ssl,
:sslcert => @config.cert_file,
:sslkey => @config.key_file,

View File

@ -60,6 +60,10 @@ module {{moduleName}}
# @return [String]
attr_accessor :temp_folder_path
# The time limit for HTTP request in seconds.
# Default to 0 (never times out).
attr_accessor :timeout
### TLS/SSL
# Set this to false to skip verifying SSL certificate when calling API from https server.
# Default to true.
@ -93,6 +97,7 @@ module {{moduleName}}
@base_path = '{{contextPath}}'
@api_key = {}
@api_key_prefix = {}
@timeout = 0
@verify_ssl = true
@cert_file = nil
@key_file = nil

View File

@ -71,6 +71,7 @@ module Petstore
:method => http_method,
:headers => header_params,
:params => query_params,
:timeout => @config.timeout,
:ssl_verifypeer => @config.verify_ssl,
:sslcert => @config.cert_file,
:sslkey => @config.key_file,

View File

@ -60,6 +60,10 @@ module Petstore
# @return [String]
attr_accessor :temp_folder_path
# The time limit for HTTP request in seconds.
# Default to 0 (never times out).
attr_accessor :timeout
### TLS/SSL
# Set this to false to skip verifying SSL certificate when calling API from https server.
# Default to true.
@ -93,6 +97,7 @@ module Petstore
@base_path = '/v2'
@api_key = {}
@api_key_prefix = {}
@timeout = 0
@verify_ssl = true
@cert_file = nil
@key_file = nil

View File

@ -92,6 +92,25 @@ describe Petstore::ApiClient do
end
end
describe "timeout in #build_request" do
let(:config) { Petstore::Configuration.new }
let(:api_client) { Petstore::ApiClient.new(config) }
it "defaults to 0" do
Petstore::Configuration.default.timeout.should == 0
config.timeout.should == 0
request = api_client.build_request(:get, '/test')
request.options[:timeout].should == 0
end
it "can be customized" do
config.timeout = 100
request = api_client.build_request(:get, '/test')
request.options[:timeout].should == 100
end
end
describe "#deserialize" do
it "handles Hash<String, String>" do
api_client = Petstore::ApiClient.new