Return data before response status code and headers

This commit is contained in:
xhh
2015-12-07 16:10:24 +08:00
parent 66112d9eb5
commit 07de03c09b
7 changed files with 104 additions and 100 deletions

View File

@@ -17,7 +17,7 @@ module {{moduleName}}
{{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}}
{{/required}}{{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}]
def {{operationId}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {})
{{#returnType}}status_code, headers, data = {{/returnType}}{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts)
{{#returnType}}data, status_code, headers = {{/returnType}}{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts)
{{#returnType}}return data{{/returnType}}{{^returnType}}return nil{{/returnType}}
end
@@ -26,7 +26,7 @@ module {{moduleName}}
{{#allParams}}{{#required}} # @param {{paramName}} {{description}}
{{/required}}{{/allParams}} # @param [Hash] opts the optional parameters
{{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}}
{{/required}}{{/allParams}} # @return [Array<Fixnum, Hash, {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}>] response status code, response headers and {{#returnType}}{{{returnType}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}
{{/required}}{{/allParams}} # @return [Array<({{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}, Fixnum, Hash)>] {{#returnType}}{{{returnType}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers
def {{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {})
if Configuration.debugging
Configuration.logger.debug "Calling API: {{classname}}#{{operationId}} ..."
@@ -74,7 +74,7 @@ module {{moduleName}}
{{/bodyParam}}
auth_names = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}]
status_code, headers, data = @api_client.call_api(:{{httpMethod}}, path,
data, status_code, headers = @api_client.call_api(:{{httpMethod}}, path,
:header_params => header_params,
:query_params => query_params,
:form_params => form_params,
@@ -82,9 +82,9 @@ module {{moduleName}}
:auth_names => auth_names{{#returnType}},
:return_type => '{{{returnType}}}'{{/returnType}})
if Configuration.debugging
Configuration.logger.debug "API called: {{classname}}#{{operationId}}\nStatus code: #{status_code}\nHeaders: #{headers}\nData: #{data.inspect}"
Configuration.logger.debug "API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}"
end
return status_code, headers, data
return data, status_code, headers
end
{{/operation}}
end

View File

@@ -25,8 +25,10 @@ module {{moduleName}}
}
end
# Call an API with given options and an array of 3 elements:
# response status code, response headers and the data deserialized from response body (could be nil).
# Call an API with given options.
#
# @return [Array<(Object, Fixnum, Hash)>] an array of 3 elements:
# the data deserialized from response body (could be nil), response status code and response headers.
def call_api(http_method, path, opts = {})
request = build_request(http_method, path, opts)
response = request.run
@@ -47,7 +49,7 @@ module {{moduleName}}
else
data = nil
end
return response.code, response.headers, data
return data, response.code, response.headers
end
def build_request(http_method, path, opts = {})