CleverTap / clevertap-android-sdk

CleverTap Android SDK
MIT License
80 stars 74 forks source link

feat(MC-1457): Create custom in-app templates definitions #581

Closed vasct closed 8 months ago

vasct commented 8 months ago

Example usage would look like this:

Kotlin

CleverTapApi.register {
    templatesSet(
        function(isVisual = false) {
            name("function")
            stringArgument("string", "")
            booleanArgument("bool", true)
        },
        template {
            name("template")
            mapArgument("map", mapOf("int" to 5))
        },
    )
}

or

TemplatesManager.register {
    setOf(
        FunctionBuilder(isVisual = false)
            .name("function")
            .stringArgument("string", "")
            .booleanArgument("bool", true)
            .build(),
        TemplateBuilder()
            .name("template")
            .mapArgument("map", mapOf("int" to 5))
            .build()
    )
}

Java:

CleverTapApi.register(ctConfig -> {
    Set<CustomTemplate> templates = new HashSet<>();
    templates.add(
            new FunctionBuilder(false)
                    .name("function")
                    .stringArgument("string", "")
                    .booleanArgument("bool", true)
                    .build());

    Map<String, Object> mapArgument = new HashMap<>();
    mapArgument.put("int", 5);
    templates.add(
            new TemplateBuilder()
                    .name("template")
                    .mapArgument("map", mapArgument)
                    .build()
    );
    return templates;
});

or

CleverTapApi.register(ctConfig ->
        templatesSet(
                new TemplateBuilder()
                        .name("name")
                        .booleanArgument("bool", true)
                        .fileArgument("file")
                        .build(),
                new FunctionBuilder(true)
                        .name("asd")
                        .build()
        )
);
vasct commented 8 months ago

Added a few more test cases.