Skip to content

Commit 1cd4f3b

Browse files
committed
update ruby samples
1 parent 51ecfcd commit 1cd4f3b

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

samples/client/petstore/ruby-faraday/lib/petstore/api_client.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def call_api(http_method, path, opts = {})
5656
}
5757

5858
connection = Faraday.new(:url => config.base_url, :ssl => ssl_options) do |conn|
59+
conn.proxy = config.proxy if config.proxy
5960
conn.request(:basic_auth, config.username, config.password)
6061
@config.configure_middleware(conn)
6162
if opts[:header_params]["Content-Type"] == "multipart/form-data"
@@ -106,7 +107,7 @@ def call_api(http_method, path, opts = {})
106107
# @option opts [Hash] :query_params Query parameters
107108
# @option opts [Hash] :form_params Query parameters
108109
# @option opts [Object] :body HTTP body (JSON/XML)
109-
# @return [Typhoeus::Request] A Typhoeus Request
110+
# @return [Faraday::Request] A Faraday Request
110111
def build_request(http_method, path, request, opts = {})
111112
url = build_request_url(path, opts)
112113
http_method = http_method.to_sym.downcase
@@ -117,12 +118,6 @@ def build_request(http_method, path, request, opts = {})
117118

118119
update_params_for_auth! header_params, query_params, opts[:auth_names]
119120

120-
req_opts = {
121-
:params_encoding => @config.params_encoding,
122-
:timeout => @config.timeout,
123-
:verbose => @config.debugging
124-
}
125-
126121
if [:post, :patch, :put, :delete].include?(http_method)
127122
req_body = build_request_body(header_params, form_params, opts[:body])
128123
if @config.debugging
@@ -131,7 +126,12 @@ def build_request(http_method, path, request, opts = {})
131126
end
132127
request.headers = header_params
133128
request.body = req_body
134-
request.options = OpenStruct.new(req_opts)
129+
130+
# Overload default options only if provided
131+
request.options.params_encoding = @config.params_encoding if @config.params_encoding
132+
request.options.timeout = @config.timeout if @config.timeout
133+
request.options.verbose = @config.debugging if @config.debugging
134+
135135
request.url url
136136
request.params = query_params
137137
download_file(request) if opts[:return_type] == 'File'

samples/client/petstore/ruby-faraday/lib/petstore/configuration.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ class Configuration
121121
# Client private key file (for client certificate)
122122
attr_accessor :ssl_client_key
123123

124+
### Proxy setting
125+
# HTTP Proxy settings
126+
attr_accessor :proxy
127+
124128
# Set this to customize parameters encoding of array parameter with multi collectionFormat.
125129
# Default to nil.
126130
#

0 commit comments

Comments
 (0)