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

Java.api.mustache Maven / Gradle / Ivy

There is a newer version: 2.0.14
Show newest version
package {{package}};

import {{invokerPackage}}.ApiException;
import {{invokerPackage}}.ApiInvoker;
{{#imports}}import {{import}};
{{/imports}}

import java.util.*;

{{#operations}}
public class {{classname}} {
  String basePath = "{{basePath}}";
  ApiInvoker apiInvoker = ApiInvoker.getInstance();

  public ApiInvoker getInvoker() {
    return apiInvoker;
  }
  
  public void setBasePath(String basePath) {
    this.basePath = basePath;
  }
  
  public String getBasePath() {
    return basePath;
  }

  {{#operation}}
  public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) throws ApiException {
    // create path and map variables
    String path = "{{path}}".replaceAll("\\{format\\}","json"){{#pathParams}}.replaceAll("\\{" + "{{paramName}}" + "\\}", apiInvoker.escapeString({{{paramName}}}.toString())){{/pathParams}};

    // query params
    Map queryParams = new HashMap();
    Map headerParams = new HashMap();

    {{#requiredParamCount}}
    // verify required params are set
    if({{/requiredParamCount}}{{#requiredParams}} {{paramName}} == null {{#hasMore}}|| {{/hasMore}}{{/requiredParams}}{{#requiredParamCount}}) {
       throw new ApiException(400, "missing required params");
    }
    {{/requiredParamCount}}

    {{#queryParams}}if(!"null".equals(String.valueOf({{paramName}})))
      queryParams.put("{{paramName}}", String.valueOf({{paramName}}));
    {{/queryParams}}

    {{#headerParams}}headerParams.put("{{paramName}}", {{paramName}});
    {{/headerParams}}

    try {
      String response = apiInvoker.invokeAPI(basePath, path, "{{httpMethod}}", queryParams, {{#bodyParam}}{{bodyParam}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}, headerParams);
      if(response != null){
        return {{#returnType}}({{{returnType}}}) ApiInvoker.deserialize(response, "{{returnContainer}}", {{returnBaseType}}.class){{/returnType}};
      }
      else {
        return {{#returnType}}null{{/returnType}};
      }
    } catch (ApiException ex) {
      if(ex.getCode() == 404) {
      	return {{#returnType}} null{{/returnType}};
      }
      else {
        throw ex;
      }
    }
  }
  {{/operation}}
}
{{/operations}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy