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

flash.api.mustache Maven / Gradle / Ivy

There is a newer version: 7.7.0
Show newest version
package {{package}} {

import org.openapitools.common.ApiInvoker;
import org.openapitools.exception.ApiErrorCodes;
import org.openapitools.exception.ApiError;
import org.openapitools.common.ApiUserCredentials;
import org.openapitools.event.Response;
import org.openapitools.common.OpenApi;
{{#imports}}import {{import}};
{{/imports}}

import mx.rpc.AsyncToken;
import mx.utils.UIDUtil;
import flash.utils.Dictionary;
import flash.events.EventDispatcher;

{{#operations}}
public class {{classname}} extends OpenApi {
    /**
    * Constructor for the {{classname}} api client
    * @param apiCredentials Wrapper object for tokens and hostName required towards authentication
    * @param eventDispatcher Optional event dispatcher that when provided is used by the SDK to dispatch any Response
    */
    public function {{classname}}(apiCredentials: ApiUserCredentials, eventDispatcher: EventDispatcher = null) {
        super(apiCredentials, eventDispatcher);
    }

{{#operation}}
        public static const event_{{nickname}}: String = "{{nickname}}";
{{/operation}}

{{#operation}}

    /*
     * Returns {{#returnType}}{{{returnType}}} {{/returnType}}{{^returnType}}void {{/returnType}}
     */
    public function {{nickname}} ({{#allParams}}{{paramName}}: {{{dataType}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}): String {
        // create path and map variables
        var path: String = "{{{path}}}".replace(/{format}/g,"xml"){{#pathParams}}.replace("{" + "{{baseName}}" + "}", getApiInvoker().escapeString({{{paramName}}})){{/pathParams}};

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

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

        {{#queryParams}}if("null" != String({{paramName}}))
            queryParams["{{baseName}}"] = toPathValue({{paramName}});
        {{/queryParams}}

        {{#headerParams}}headerParams["{{baseName}}"] = toPathValue({{paramName}});
        {{/headerParams}}

        var token:AsyncToken = getApiInvoker().invokeAPI(path, "{{httpMethod}}", queryParams, {{#bodyParam}}{{paramName}}{{/bodyParam}}{{^bodyParam}}null{{/bodyParam}}, headerParams);

        var requestId: String = getUniqueId();

        token.requestId = requestId;
        token.completionEventType = "{{nickname}}";

        token.returnType = {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}null {{/returnType}};
        return requestId;

    }
    {{/operation}}
}
        {{/operations}}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy