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

csharp.api.mustache Maven / Gradle / Ivy

  using System;
  using System.Collections.Generic;
  using {{invokerPackage}};
  using {{invokerPackage}}.Model;
  {{#imports}}
  {{/imports}}

  namespace {{package}} {
    {{#operations}}
    public class {{classname}} {
      string basePath = "{{basePath}}";
      private readonly ApiInvoker apiInvoker = ApiInvoker.GetInstance();

      public ApiInvoker getInvoker() {
        return apiInvoker;
      }
      
      // Sets the endpoint base url for the services being accessed
      public void setBasePath(string basePath) {
        this.basePath = basePath;
      }
      
      // Gets the endpoint base url for the services being accessed
      public String getBasePath() {
        return basePath;
      }

      {{#operation}}

      /// 
      /// {{summary}} {{notes}}
      /// 
      {{#allParams}}/// {{description}}
      {{#hasMore}} {{/hasMore}}{{/allParams}}
      /// 
      public {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}} {{nickname}} ({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
        // create path and map variables
        var path = "{{path}}".Replace("{format}","json"){{#pathParams}}.Replace("{" + "{{paramName}}" + "}", apiInvoker.escapeString({{{paramName}}}.ToString())){{/pathParams}};

        // query params
        var queryParams = new Dictionary();
        var headerParams = new Dictionary();

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

		string paramStr = null;
        {{#queryParams}}if ({{paramName}} != null){
          paramStr = ({{paramName}} != null && {{paramName}} is DateTime) ? ((DateTime)(object){{paramName}}).ToString("u") : Convert.ToString({{paramName}});
          queryParams.Add("{{paramName}}", paramStr);
		}
        {{/queryParams}}

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

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy