All Downloads are FREE. Search and download functionalities are using the official Maven repository.

perl.api.mustache Maven / Gradle / Ivy

There is a newer version: 3.0.0-rc1
Show newest version
{{>partial_license}}
#
# NOTE: This class is auto generated by the swagger code generator program. 
# Do not edit the class manually.
# Ref: https://github.com/swagger-api/swagger-codegen
#
package {{moduleName}}::{{classname}};

require 5.6.0;
use strict;
use warnings;
use utf8; 
use Exporter;
use Carp qw( croak );
use Log::Any qw($log);

use {{moduleName}}::ApiClient;

use base "Class::Data::Inheritable";

__PACKAGE__->mk_classdata('method_documentation' => {});

sub new {
    my $class = shift;
    my $api_client;

    if ($_[0] && ref $_[0] && ref $_[0] eq '{{moduleName}}::ApiClient' ) {
        $api_client = $_[0];
    } else {
        $api_client = {{moduleName}}::ApiClient->new(@_);
    }

    bless { api_client => $api_client }, $class;

}
{{#operations}}

{{#operation}}

#
# {{{operationId}}}
#
# {{{summary}}}
# 
{{#allParams}}# @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional{{#defaultValue}}, default to {{{.}}}{{/defaultValue}}){{/required}}
{{/allParams}}
{
    my $params = {
{{#allParams}}
    '{{paramName}}' => {
        data_type => '{{dataType}}',
        description => '{{description}}',
        required => {{#required}}'1'{{/required}}{{^required}}'0'{{/required}},
    },
{{/allParams}}
    };
    __PACKAGE__->method_documentation->{ '{{operationId}}' } = { 
    	summary => '{{summary}}',
        params => $params,
        returns => {{#returnType}}'{{{returnType}}}'{{/returnType}}{{^returnType}}undef{{/returnType}},
        };
}
# @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
#
sub {{operationId}} {
    my ($self, %args) = @_;

    {{#allParams}}
    {{#required}}
    # verify the required parameter '{{paramName}}' is set
    unless (exists $args{'{{paramName}}'}) {
      croak("Missing the required parameter '{{paramName}}' when calling {{operationId}}");
    }

    {{/required}}
    {{/allParams}}
    # parse inputs
    my $_resource_path = '{{{path}}}';

    my $_method = '{{httpMethod}}';
    my $query_params = {};
    my $header_params = {};
    my $form_params = {};

    # 'Accept' and 'Content-Type' header
    my $_header_accept = $self->{api_client}->select_header_accept({{#produces}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/produces}});
    if ($_header_accept) {
        $header_params->{'Accept'} = $_header_accept;
    }
    $header_params->{'Content-Type'} = $self->{api_client}->select_header_content_type({{#consumes}}'{{{mediaType}}}'{{#hasMore}}, {{/hasMore}}{{/consumes}});

    {{#queryParams}}
    # query params
    if ( exists $args{'{{paramName}}'}) {
        $query_params->{'{{baseName}}'} = $self->{api_client}->to_query_value($args{'{{paramName}}'});
    }

    {{/queryParams}}
    {{#headerParams}}
    # header params
    if ( exists $args{'{{paramName}}'}) {
        $header_params->{'{{baseName}}'} = $self->{api_client}->to_header_value($args{'{{paramName}}'});
    }

    {{/headerParams}}
    {{#pathParams}}
    # path params
    if ( exists $args{'{{paramName}}'}) {
        my $_base_variable = "{" . "{{baseName}}" . "}";
        my $_base_value = $self->{api_client}->to_path_value($args{'{{paramName}}'});
        $_resource_path =~ s/$_base_variable/$_base_value/g;
    }

    {{/pathParams}}
    {{#formParams}}
    # form params
    if ( exists $args{'{{paramName}}'} ) {
        {{#isFile}}$form_params->{'{{baseName}}'} = [] unless defined $form_params->{'{{baseName}}'};
        push @{$form_params->{'{{baseName}}'}}, $args{'{{paramName}}'};
        {{/isFile}}
        {{^isFile}}$form_params->{'{{baseName}}'} = $self->{api_client}->to_form_value($args{'{{paramName}}'});
        {{/isFile}}
    }
    
    {{/formParams}}
    my $_body_data;
    {{#bodyParams}}
    # body params
    if ( exists $args{'{{paramName}}'}) {
        $_body_data = $args{'{{paramName}}'};
    }

    {{/bodyParams}}
    # authentication setting, if any
    my $auth_settings = [qw({{#authMethods}}{{name}} {{/authMethods}})];

    # make the API Call
    {{#returnType}}
    my $response = $self->{api_client}->call_api($_resource_path, $_method,
                                           $query_params, $form_params,
                                           $header_params, $_body_data, $auth_settings);
    if (!$response) {
        return;
    }
    my $_response_object = $self->{api_client}->deserialize('{{returnType}}', $response);
    return $_response_object;
    {{/returnType}}
    {{^returnType}}
    $self->{api_client}->call_api($_resource_path, $_method,
                                           $query_params, $form_params,
                                           $header_params, $_body_data, $auth_settings);
    return;
    {{/returnType}}
}
{{/operation}}
{{/operations}}

1;




© 2015 - 2024 Weber Informatics LLC | Privacy Policy