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

templates.Poly.hbs Maven / Gradle / Ivy

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

import io.polyapi.client.internal.proxy.PolyProxyFactory;
import io.polyapi.client.internal.model.PolyContext;
import io.polyapi.client.api.AuthTokenEventConsumer;
import io.polyapi.client.api.model.PolyEntity;
import io.polyapi.client.api.AuthTokenOptions;
import io.polyapi.commons.api.websocket.Handle;
import java.util.function.Consumer;
import io.polyapi.commons.api.model.PolyErrorEvent;
import io.polyapi.commons.api.model.PolyGeneratedClass;

{{~#each this.imports}}
import {{{this}}};
{{~/each}}

@PolyGeneratedClass
public class {{className}} extends PolyContext {
{{~#each specifications}}
    private static {{this.className}} {{this.name}};
{{~/each}}
{{#each subcontexts}}
    public static {{this.className}} {{this.name}};
{{~/each}}
    private static final Poly poly;


    static {
        poly = new Poly();
{{~#each serverFunctionSpecifications}}
        poly.{{this.name}} = poly.createServerFunctionProxy({{this.className}}.class);
{{~/each}}
{{~#each customFunctionSpecifications}}
        poly.{{this.name}} = poly.createCustomFunctionProxy({{this.className}}.class);
{{~/each}}
{{~#each apiFunctionSpecifications}}
        poly.{{this.name}} = poly.createApiFunctionProxy({{this.className}}.class);
{{~/each}}
{{~#each subResourceAuthFunctionSpecifications}}
        poly.{{this.name}} = poly.createSubresourceAuthFunction({{this.className}}.class);
{{~/each}}
{{~#each standardAuthFunctionSpecifications}}
        poly.{{this.name}} = poly.create{{#if audienceRequired}}Audience{{/if}}TokenAuthFunction({{this.className}}.class);
{{~/each}}
{{~#each webhookHandleSpecifications}}
        poly.{{this.name}} = poly.createPolyTrigger({{this.className}}.class);
{{~/each}}
{{#each subcontexts}}
        poly.{{this.name}} = poly.createSubContext({{this.className}}.class);
{{~/each}}
    }

{{~#each functionSpecifications}}
    public static {{{this.returnType}}} {{{this.methodSignature}}} {
    {{~#if this.returnsValue}}
        return
    {{~else}}
    {{~/if}} {{this.name}}.{{this.name}}({{this.paramVariableNames}});
    }

    public {{{this.className}}} get{{{this.className}}}Function() {
        return {{{this.name}}};
    }
{{~/each}}
{{~#each webhookHandlerSpecifications}}
    public Handle {{this.name}}(Consumer<{{{this.valueType}}}> callback) {
        return {{this.name}}.{{this.name}}(callback);
    }
{{~/each}}

{{~#each specifications}}
    {{~#ifIsType this "AuthFunctionSpecification"}}
        {{~#if subResource}}
            public void {{name}}(String token) {
            this.{{name}}.{{name}}(token);
            }
        {{~else}}
            public void getToken(String clientId, String clientSecret{{#if
                    audienceRequired}}, String audience{{/if}}, String[] scopes, AuthTokenEventConsumer callback) {
            this.{{name}}.getToken(clientId, clientSecret{{#if audienceRequired}}, audience{{/if}}, scopes, callback);
            }

            public void getToken(String clientId, String clientSecret{{#if
                    audienceRequired}}, String audience{{/if}}, String[] scopes, AuthTokenEventConsumer callback, AuthTokenOptions options) {
            this.{{name}}.getToken(clientId, clientSecret{{#if
                    audienceRequired}}, audience{{/if}}, scopes, callback, options);
            }
        {{~/if}}

        public {{{this.className}}} get{{{this.className}}}AuthFunction() {
        return this.{{{this.name}}};
        }
    {{~/ifIsType}}
{{~/each}}

    public static Handle onError(String path, Consumer errorListener) {
        return poly.addErrorListener(path, errorListener);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy