|
| 1 | +=begin |
| 2 | +{{> api_info}} |
| 3 | +=end |
| 4 | + |
| 5 | +require 'uri' |
| 6 | + |
| 7 | +module {{moduleName}} |
| 8 | +{{#operations}} |
| 9 | + class {{classname}} |
| 10 | + attr_accessor :api_client |
| 11 | + |
| 12 | + def initialize(api_client = ApiClient.default) |
| 13 | + @api_client = api_client |
| 14 | + end |
| 15 | +{{#operation}} |
| 16 | + {{#summary}} |
| 17 | + # {{{summary}}} |
| 18 | + {{/summary}} |
| 19 | + {{#notes}} |
| 20 | + # {{{notes}}} |
| 21 | + {{/notes}} |
| 22 | +{{#allParams}}{{#required}} # @param {{paramName}} {{description}} |
| 23 | +{{/required}}{{/allParams}} # @param [Hash] opts the optional parameters |
| 24 | +{{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}} |
| 25 | +{{/required}}{{/allParams}} # @return [{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}nil{{/returnType}}] |
| 26 | + def {{operationId}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {}) |
| 27 | + {{#returnType}}data, _status_code, _headers = {{/returnType}}{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts) |
| 28 | + {{#returnType}}data{{/returnType}}{{^returnType}}nil{{/returnType}} |
| 29 | + end |
| 30 | + |
| 31 | + {{#summary}} |
| 32 | + # {{summary}} |
| 33 | + {{/summary}} |
| 34 | + {{#notes}} |
| 35 | + # {{notes}} |
| 36 | + {{/notes}} |
| 37 | +{{#allParams}}{{#required}} # @param {{paramName}} {{description}} |
| 38 | +{{/required}}{{/allParams}} # @param [Hash] opts the optional parameters |
| 39 | +{{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}} |
| 40 | +{{/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 |
| 41 | + def {{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {}) |
| 42 | + if @api_client.config.debugging |
| 43 | + @api_client.config.logger.debug 'Calling API: {{classname}}.{{operationId}} ...' |
| 44 | + end |
| 45 | + {{#allParams}} |
| 46 | + {{#required}} |
| 47 | + # verify the required parameter '{{paramName}}' is set |
| 48 | + if @api_client.config.client_side_validation && {{{paramName}}}.nil? |
| 49 | + fail ArgumentError, "Missing the required parameter '{{paramName}}' when calling {{classname}}.{{operationId}}" |
| 50 | + end |
| 51 | + {{#isEnum}} |
| 52 | + {{^isContainer}} |
| 53 | + # verify enum value |
| 54 | + if @api_client.config.client_side_validation && ![{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?({{{paramName}}}) |
| 55 | + fail ArgumentError, "invalid value for '{{{paramName}}}', must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}" |
| 56 | + end |
| 57 | + {{/isContainer}} |
| 58 | + {{/isEnum}} |
| 59 | + {{/required}} |
| 60 | + {{^required}} |
| 61 | + {{#isEnum}} |
| 62 | + {{#collectionFormat}} |
| 63 | + if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && !opts[:'{{{paramName}}}'].all? { |item| [{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?(item) } |
| 64 | + fail ArgumentError, 'invalid value for "{{{paramName}}}", must include one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}' |
| 65 | + end |
| 66 | + {{/collectionFormat}} |
| 67 | + {{^collectionFormat}} |
| 68 | + if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && ![{{#allowableValues}}{{#values}}'{{{this}}}'{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}].include?(opts[:'{{{paramName}}}']) |
| 69 | + fail ArgumentError, 'invalid value for "{{{paramName}}}", must be one of {{#allowableValues}}{{#values}}{{{this}}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}' |
| 70 | + end |
| 71 | + {{/collectionFormat}} |
| 72 | + {{/isEnum}} |
| 73 | + {{/required}} |
| 74 | + {{#hasValidation}} |
| 75 | + {{#maxLength}} |
| 76 | + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.to_s.length > {{{maxLength}}} |
| 77 | + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, the character length must be smaller than or equal to {{{maxLength}}}.' |
| 78 | + end |
| 79 | + |
| 80 | + {{/maxLength}} |
| 81 | + {{#minLength}} |
| 82 | + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.to_s.length < {{{minLength}}} |
| 83 | + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, the character length must be great than or equal to {{{minLength}}}.' |
| 84 | + end |
| 85 | + |
| 86 | + {{/minLength}} |
| 87 | + {{#maximum}} |
| 88 | + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{{maximum}}} |
| 89 | + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, must be smaller than {{^exclusiveMaximum}}or equal to {{/exclusiveMaximum}}{{{maximum}}}.' |
| 90 | + end |
| 91 | + |
| 92 | + {{/maximum}} |
| 93 | + {{#minimum}} |
| 94 | + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{{minimum}}} |
| 95 | + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, must be greater than {{^exclusiveMinimum}}or equal to {{/exclusiveMinimum}}{{{minimum}}}.' |
| 96 | + end |
| 97 | + |
| 98 | + {{/minimum}} |
| 99 | + {{#pattern}} |
| 100 | + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} !~ Regexp.new({{{pattern}}}) |
| 101 | + fail ArgumentError, "invalid value for '{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:\"{{{paramName}}}\"]{{/required}}' when calling {{classname}}.{{operationId}}, must conform to the pattern {{{pattern}}}." |
| 102 | + end |
| 103 | + |
| 104 | + {{/pattern}} |
| 105 | + {{#maxItems}} |
| 106 | + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.length > {{{maxItems}}} |
| 107 | + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, number of items must be less than or equal to {{{maxItems}}}.' |
| 108 | + end |
| 109 | + |
| 110 | + {{/maxItems}} |
| 111 | + {{#minItems}} |
| 112 | + if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.length < {{{minItems}}} |
| 113 | + fail ArgumentError, 'invalid value for "{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:"{{{paramName}}}"]{{/required}}" when calling {{classname}}.{{operationId}}, number of items must be greater than or equal to {{{minItems}}}.' |
| 114 | + end |
| 115 | + |
| 116 | + {{/minItems}} |
| 117 | + {{/hasValidation}} |
| 118 | + {{/allParams}} |
| 119 | + # resource path |
| 120 | + local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', {{paramName}}.to_s){{/pathParams}} |
| 121 | + |
| 122 | + # query parameters |
| 123 | + query_params = {} |
| 124 | + {{#queryParams}} |
| 125 | + {{#required}} |
| 126 | + query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}} |
| 127 | + {{/required}} |
| 128 | + {{/queryParams}} |
| 129 | + {{#queryParams}} |
| 130 | + {{^required}} |
| 131 | + query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{{paramName}}}'].nil? |
| 132 | + {{/required}} |
| 133 | + {{/queryParams}} |
| 134 | + |
| 135 | + # header parameters |
| 136 | + header_params = {} |
| 137 | + {{#hasProduces}} |
| 138 | + # HTTP header 'Accept' (if needed) |
| 139 | + header_params['Accept'] = @api_client.select_header_accept([{{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}}]) |
| 140 | + {{/hasProduces}} |
| 141 | + {{#hasConsumes}} |
| 142 | + # HTTP header 'Content-Type' |
| 143 | + header_params['Content-Type'] = @api_client.select_header_content_type([{{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}}]) |
| 144 | + {{/hasConsumes}} |
| 145 | + {{#headerParams}} |
| 146 | + {{#required}} |
| 147 | + header_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}} |
| 148 | + {{/required}} |
| 149 | + {{/headerParams}} |
| 150 | + {{#headerParams}} |
| 151 | + {{^required}} |
| 152 | + header_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{{paramName}}}'].nil? |
| 153 | + {{/required}} |
| 154 | + {{/headerParams}} |
| 155 | + |
| 156 | + # form parameters |
| 157 | + form_params = {} |
| 158 | + {{#formParams}} |
| 159 | + {{#required}} |
| 160 | + form_params['{{baseName}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}} |
| 161 | + {{/required}} |
| 162 | + {{/formParams}} |
| 163 | + {{#formParams}} |
| 164 | + {{^required}} |
| 165 | + form_params['{{baseName}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{paramName}}'].nil? |
| 166 | + {{/required}} |
| 167 | + {{/formParams}} |
| 168 | + |
| 169 | + # http body (model) |
| 170 | + {{^bodyParam}} |
| 171 | + post_body = nil |
| 172 | + {{/bodyParam}} |
| 173 | + {{#bodyParam}} |
| 174 | + post_body = @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}) |
| 175 | + {{/bodyParam}} |
| 176 | + auth_names = [{{#authMethods}}'{{name}}'{{#hasMore}}, {{/hasMore}}{{/authMethods}}] |
| 177 | + data, status_code, headers = @api_client.call_api(:{{httpMethod}}, local_var_path, |
| 178 | + :header_params => header_params, |
| 179 | + :query_params => query_params, |
| 180 | + :form_params => form_params, |
| 181 | + :body => post_body, |
| 182 | + :auth_names => auth_names{{#returnType}}, |
| 183 | + :return_type => '{{{returnType}}}'{{/returnType}}) |
| 184 | + if @api_client.config.debugging |
| 185 | + @api_client.config.logger.debug "API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" |
| 186 | + end |
| 187 | + return data, status_code, headers |
| 188 | + end |
| 189 | +{{/operation}} |
| 190 | + end |
| 191 | +{{/operations}} |
| 192 | +end |
0 commit comments