forked from loafle/openapi-generator-original
Ruby fix typhoeus api client multiple call with file return type (#20615)
* [Ruby] fix Typhoeus api client multiple call with file return type * update samples
This commit is contained in:
parent
c5fb60b5f2
commit
515c8827b2
@ -4,7 +4,8 @@
|
||||
# the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
|
||||
def call_api(http_method, path, opts = {})
|
||||
request = build_request(http_method, path, opts)
|
||||
tempfile = download_file(request) if opts[:return_type] == 'File'
|
||||
tempfile = nil
|
||||
(download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File'
|
||||
response = request.run
|
||||
|
||||
if @config.debugging
|
||||
@ -145,17 +146,15 @@
|
||||
chunk.force_encoding(encoding)
|
||||
tempfile.write(chunk)
|
||||
end
|
||||
# run the request to ensure the tempfile is created successfully before returning it
|
||||
request.run
|
||||
if tempfile
|
||||
request.on_complete do
|
||||
if !tempfile
|
||||
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
||||
end
|
||||
tempfile.close
|
||||
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
||||
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
||||
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
||||
"explicitly with `tempfile.delete`"
|
||||
else
|
||||
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
||||
yield tempfile if block_given?
|
||||
end
|
||||
|
||||
tempfile
|
||||
end
|
||||
|
@ -49,7 +49,8 @@ module OpenapiClient
|
||||
# the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
|
||||
def call_api(http_method, path, opts = {})
|
||||
request = build_request(http_method, path, opts)
|
||||
tempfile = download_file(request) if opts[:return_type] == 'File'
|
||||
tempfile = nil
|
||||
(download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File'
|
||||
response = request.run
|
||||
|
||||
if @config.debugging
|
||||
@ -188,19 +189,17 @@ module OpenapiClient
|
||||
chunk.force_encoding(encoding)
|
||||
tempfile.write(chunk)
|
||||
end
|
||||
# run the request to ensure the tempfile is created successfully before returning it
|
||||
request.run
|
||||
if tempfile
|
||||
request.on_complete do
|
||||
if !tempfile
|
||||
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
||||
end
|
||||
tempfile.close
|
||||
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
||||
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
||||
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
||||
"explicitly with `tempfile.delete`"
|
||||
else
|
||||
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
||||
yield tempfile if block_given?
|
||||
end
|
||||
|
||||
tempfile
|
||||
end
|
||||
|
||||
# Check if the given MIME is a JSON MIME.
|
||||
|
@ -49,7 +49,8 @@ module Petstore
|
||||
# the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
|
||||
def call_api(http_method, path, opts = {})
|
||||
request = build_request(http_method, path, opts)
|
||||
tempfile = download_file(request) if opts[:return_type] == 'File'
|
||||
tempfile = nil
|
||||
(download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File'
|
||||
response = request.run
|
||||
|
||||
if @config.debugging
|
||||
@ -188,19 +189,17 @@ module Petstore
|
||||
chunk.force_encoding(encoding)
|
||||
tempfile.write(chunk)
|
||||
end
|
||||
# run the request to ensure the tempfile is created successfully before returning it
|
||||
request.run
|
||||
if tempfile
|
||||
request.on_complete do
|
||||
if !tempfile
|
||||
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
||||
end
|
||||
tempfile.close
|
||||
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
||||
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
||||
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
||||
"explicitly with `tempfile.delete`"
|
||||
else
|
||||
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
||||
yield tempfile if block_given?
|
||||
end
|
||||
|
||||
tempfile
|
||||
end
|
||||
|
||||
# Check if the given MIME is a JSON MIME.
|
||||
|
@ -49,7 +49,8 @@ module Petstore
|
||||
# the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
|
||||
def call_api(http_method, path, opts = {})
|
||||
request = build_request(http_method, path, opts)
|
||||
tempfile = download_file(request) if opts[:return_type] == 'File'
|
||||
tempfile = nil
|
||||
(download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File'
|
||||
response = request.run
|
||||
|
||||
if @config.debugging
|
||||
@ -188,19 +189,17 @@ module Petstore
|
||||
chunk.force_encoding(encoding)
|
||||
tempfile.write(chunk)
|
||||
end
|
||||
# run the request to ensure the tempfile is created successfully before returning it
|
||||
request.run
|
||||
if tempfile
|
||||
request.on_complete do
|
||||
if !tempfile
|
||||
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
||||
end
|
||||
tempfile.close
|
||||
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
||||
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
||||
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
||||
"explicitly with `tempfile.delete`"
|
||||
else
|
||||
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
||||
yield tempfile if block_given?
|
||||
end
|
||||
|
||||
tempfile
|
||||
end
|
||||
|
||||
# Check if the given MIME is a JSON MIME.
|
||||
|
@ -49,7 +49,8 @@ module XAuthIDAlias
|
||||
# the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
|
||||
def call_api(http_method, path, opts = {})
|
||||
request = build_request(http_method, path, opts)
|
||||
tempfile = download_file(request) if opts[:return_type] == 'File'
|
||||
tempfile = nil
|
||||
(download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File'
|
||||
response = request.run
|
||||
|
||||
if @config.debugging
|
||||
@ -188,19 +189,17 @@ module XAuthIDAlias
|
||||
chunk.force_encoding(encoding)
|
||||
tempfile.write(chunk)
|
||||
end
|
||||
# run the request to ensure the tempfile is created successfully before returning it
|
||||
request.run
|
||||
if tempfile
|
||||
request.on_complete do
|
||||
if !tempfile
|
||||
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
||||
end
|
||||
tempfile.close
|
||||
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
||||
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
||||
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
||||
"explicitly with `tempfile.delete`"
|
||||
else
|
||||
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
||||
yield tempfile if block_given?
|
||||
end
|
||||
|
||||
tempfile
|
||||
end
|
||||
|
||||
# Check if the given MIME is a JSON MIME.
|
||||
|
@ -49,7 +49,8 @@ module DynamicServers
|
||||
# the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
|
||||
def call_api(http_method, path, opts = {})
|
||||
request = build_request(http_method, path, opts)
|
||||
tempfile = download_file(request) if opts[:return_type] == 'File'
|
||||
tempfile = nil
|
||||
(download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File'
|
||||
response = request.run
|
||||
|
||||
if @config.debugging
|
||||
@ -187,19 +188,17 @@ module DynamicServers
|
||||
chunk.force_encoding(encoding)
|
||||
tempfile.write(chunk)
|
||||
end
|
||||
# run the request to ensure the tempfile is created successfully before returning it
|
||||
request.run
|
||||
if tempfile
|
||||
request.on_complete do
|
||||
if !tempfile
|
||||
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
||||
end
|
||||
tempfile.close
|
||||
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
||||
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
||||
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
||||
"explicitly with `tempfile.delete`"
|
||||
else
|
||||
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
||||
yield tempfile if block_given?
|
||||
end
|
||||
|
||||
tempfile
|
||||
end
|
||||
|
||||
# Check if the given MIME is a JSON MIME.
|
||||
|
@ -49,7 +49,8 @@ module Petstore
|
||||
# the data deserialized from response body (may be a Tempfile or nil), response status code and response headers.
|
||||
def call_api(http_method, path, opts = {})
|
||||
request = build_request(http_method, path, opts)
|
||||
tempfile = download_file(request) if opts[:return_type] == 'File'
|
||||
tempfile = nil
|
||||
(download_file(request) { tempfile = _1 }) if opts[:return_type] == 'File'
|
||||
response = request.run
|
||||
|
||||
if @config.debugging
|
||||
@ -187,19 +188,17 @@ module Petstore
|
||||
chunk.force_encoding(encoding)
|
||||
tempfile.write(chunk)
|
||||
end
|
||||
# run the request to ensure the tempfile is created successfully before returning it
|
||||
request.run
|
||||
if tempfile
|
||||
request.on_complete do
|
||||
if !tempfile
|
||||
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
||||
end
|
||||
tempfile.close
|
||||
@config.logger.info "Temp file written to #{tempfile.path}, please copy the file to a proper folder "\
|
||||
"with e.g. `FileUtils.cp(tempfile.path, '/new/file/path')` otherwise the temp file "\
|
||||
"will be deleted automatically with GC. It's also recommended to delete the temp file "\
|
||||
"explicitly with `tempfile.delete`"
|
||||
else
|
||||
fail ApiError.new("Failed to create the tempfile based on the HTTP response from the server: #{request.inspect}")
|
||||
yield tempfile if block_given?
|
||||
end
|
||||
|
||||
tempfile
|
||||
end
|
||||
|
||||
# Check if the given MIME is a JSON MIME.
|
||||
|
Loading…
x
Reference in New Issue
Block a user