=begin {{> api_info}} =end require 'cgi' module Dropbox end module {{moduleName}} {{#operations}} class {{classname}} attr_accessor :api_client def initialize(api_client = ApiClient.default) @api_client = api_client end {{#operation}} {{#summary}} # {{{.}}} {{/summary}} {{#notes}} # {{{.}}} {{/notes}} {{#allParams}}{{#required}} # @param {{paramName}} [{{{dataType}}}] {{description}} {{/required}}{{/allParams}} # @param [Hash] opts the optional parameters {{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}} {{/required}}{{/allParams}} # @return [{{{returnType}}}{{^returnType}}nil{{/returnType}}] def {{operationId}}({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {}) {{#returnType}}data, _status_code, _headers = {{/returnType}}{{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts) {{#returnType}}data{{/returnType}}{{^returnType}}nil{{/returnType}} end {{#summary}} # {{.}} {{/summary}} {{#notes}} # {{.}} {{/notes}} {{#allParams}}{{#required}} # @param {{paramName}} [{{{dataType}}}] {{description}} {{/required}}{{/allParams}} # @param [Hash] opts the optional parameters {{#allParams}}{{^required}} # @option opts [{{{dataType}}}] :{{paramName}} {{description}} {{/required}}{{/allParams}} # @return [Array<({{{returnType}}}{{^returnType}}nil{{/returnType}}, Integer, Hash)>] {{#returnType}}{{{.}}} data{{/returnType}}{{^returnType}}nil{{/returnType}}, response status code and response headers def {{operationId}}_with_http_info({{#allParams}}{{#required}}{{paramName}}, {{/required}}{{/allParams}}opts = {}) if @api_client.config.debugging @api_client.config.logger.debug 'Calling API: {{classname}}.{{operationId}} ...' end {{#allParams}} {{^isNullable}} {{#required}} # verify the required parameter '{{paramName}}' is set if @api_client.config.client_side_validation && {{{paramName}}}.nil? fail ArgumentError, "Missing the required parameter '{{paramName}}' when calling {{classname}}.{{operationId}}" end {{#isEnum}} {{^isContainer}} # verify enum value allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}] if @api_client.config.client_side_validation && !allowable_values.include?({{{paramName}}}) fail ArgumentError, "invalid value for \"{{{paramName}}}\", must be one of #{allowable_values}" end {{/isContainer}} {{/isEnum}} {{/required}} {{/isNullable}} {{^required}} {{#isEnum}} {{#collectionFormat}} allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}] if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && !opts[:'{{{paramName}}}'].all? { |item| allowable_values.include?(item) } fail ArgumentError, "invalid value for \"{{{paramName}}}\", must include one of #{allowable_values}" end {{/collectionFormat}} {{^collectionFormat}} allowable_values = [{{#allowableValues}}{{#enumVars}}{{{value}}}{{^-last}}, {{/-last}}{{/enumVars}}{{/allowableValues}}] if @api_client.config.client_side_validation && opts[:'{{{paramName}}}'] && !allowable_values.include?(opts[:'{{{paramName}}}']) fail ArgumentError, "invalid value for \"{{{paramName}}}\", must be one of #{allowable_values}" end {{/collectionFormat}} {{/isEnum}} {{/required}} {{#hasValidation}} {{#maxLength}} if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.to_s.length > {{{maxLength}}} 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}}}.' end {{/maxLength}} {{#minLength}} if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.to_s.length < {{{minLength}}} 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}}}.' end {{/minLength}} {{#maximum}} if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} >{{#exclusiveMaximum}}={{/exclusiveMaximum}} {{{maximum}}} 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}}}.' end {{/maximum}} {{#minimum}} if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} <{{#exclusiveMinimum}}={{/exclusiveMinimum}} {{{minimum}}} 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}}}.' end {{/minimum}} {{#pattern}} pattern = Regexp.new({{{pattern}}}) if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}} !~ pattern fail ArgumentError, "invalid value for '{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:\"{{{paramName}}}\"]{{/required}}' when calling {{classname}}.{{operationId}}, must conform to the pattern #{pattern}." end {{/pattern}} {{#maxItems}} if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.length > {{{maxItems}}} 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}}}.' end {{/maxItems}} {{#minItems}} if @api_client.config.client_side_validation && {{^required}}!opts[:'{{{paramName}}}'].nil? && {{/required}}{{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}.length < {{{minItems}}} 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}}}.' end {{/minItems}} {{/hasValidation}} {{/allParams}} # resource path local_var_path = '{{{path}}}'{{#pathParams}}.sub('{' + '{{baseName}}' + '}', CGI.escape({{paramName}}.to_s){{^strictSpecBehavior}}.gsub('%2F', '/'){{/strictSpecBehavior}}){{/pathParams}} # query parameters query_params = opts[:query_params] || {} {{#queryParams}} {{#required}} query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}} {{/required}} {{/queryParams}} {{#queryParams}} {{^required}} query_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{{paramName}}}'].nil? {{/required}} {{/queryParams}} # header parameters header_params = opts[:header_params] || {} {{#hasProduces}} # HTTP header 'Accept' (if needed) header_params['Accept'] = @api_client.select_header_accept([{{#produces}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/produces}}]) {{/hasProduces}} {{#hasConsumes}} # HTTP header 'Content-Type' content_type = @api_client.select_header_content_type([{{#consumes}}'{{{mediaType}}}'{{^-last}}, {{/-last}}{{/consumes}}]) if !content_type.nil? header_params['Content-Type'] = content_type end {{/hasConsumes}} {{#headerParams}} {{#required}} header_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param({{{paramName}}}, :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}{{{paramName}}}{{/collectionFormat}} {{/required}} {{/headerParams}} {{#headerParams}} {{^required}} header_params[:'{{{baseName}}}'] = {{#collectionFormat}}@api_client.build_collection_param(opts[:'{{{paramName}}}'], :{{{collectionFormat}}}){{/collectionFormat}}{{^collectionFormat}}opts[:'{{{paramName}}}']{{/collectionFormat}} if !opts[:'{{{paramName}}}'].nil? {{/required}} {{/headerParams}} post_body = {} form_params = opts[:form_params] || {} {{#bodyParam}} result = @api_client.generate_form_data( {{paramName}}, {{moduleName}}::{{{dataType}}}.openapi_types ) # form parameters if result[:has_file] form_params = opts[:form_params] || result[:params] header_params['Content-Type'] = 'multipart/form-data' else # http body (model) post_body = opts[:debug_body] || result[:params] end {{/bodyParam}} {{^bodyParam}} # http body (model) post_body = opts[:debug_body]{{#bodyParam}} || @api_client.object_to_http_body({{#required}}{{{paramName}}}{{/required}}{{^required}}opts[:'{{{paramName}}}']{{/required}}){{/bodyParam}} {{/bodyParam}} # return_type return_type = opts[:debug_return_type]{{#returnType}} || '{{{.}}}'{{/returnType}} # auth_names auth_names = opts[:debug_auth_names] || [{{#authMethods}}'{{name}}'{{^-last}}, {{/-last}}{{/authMethods}}] new_options = opts.merge( :operation => :"{{classname}}.{{operationId}}", :header_params => header_params, :query_params => query_params, :form_params => form_params, :body => post_body, :auth_names => auth_names, :return_type => return_type ) begin data, status_code, headers = @api_client.call_api(:{{httpMethod}}, local_var_path, new_options) rescue Dropbox::Sign::ApiError => e {{#returnType}} {{#responses}} {{#dataType}} {{^isWildcard}} {{^isRange}} if e.code === {{code}} body = @api_client.convert_to_type( JSON.parse("[#{e.response_body}]", :symbolize_names => true)[0], "{{moduleName}}::{{{dataType}}}" ) fail ApiError.new(:code => e.code, :response_headers => e.response_headers, :response_body => body), e.message end {{/isRange}} {{/isWildcard}} {{/dataType}} {{/responses}} {{#responses}} {{#dataType}} {{#isRange}} range_code = "{{code}}".split('').first {{=<% %>=}} range_code_left = "#{range_code}00".to_i range_code_right = "#{range_code}99".to_i <%={{ }}=%> if e.code >= range_code_left && e.code <= range_code_right body = @api_client.convert_to_type( JSON.parse("[#{e.response_body}]", :symbolize_names => true)[0], "{{moduleName}}::{{{dataType}}}" ) fail ApiError.new(:code => e.code, :response_headers => e.response_headers, :response_body => body), e.message end {{/isRange}} {{/dataType}} {{/responses}} {{#responses}} {{#dataType}} {{#isWildcard}} body = @api_client.convert_to_type( JSON.parse("[#{e.response_body}]", :symbolize_names => true)[0], "{{moduleName}}::{{{dataType}}}" ) fail ApiError.new(:code => e.code, :response_headers => e.response_headers, :response_body => body), e.message {{/isWildcard}} {{/dataType}} {{/responses}} {{/returnType}} end if @api_client.config.debugging @api_client.config.logger.debug "API called: {{classname}}#{{operationId}}\nData: #{data.inspect}\nStatus code: #{status_code}\nHeaders: #{headers}" end return data, status_code, headers end {{^-last}} {{/-last}} {{/operation}} end {{/operations}} end