All Projects → patxibocos → poetimizely

patxibocos / poetimizely

Licence: MIT License
Generate Kotlin type safe accessors for Optimizely experiments and features

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to poetimizely

Jsonschema2pojo
Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
Stars: ✭ 5,633 (+33035.29%)
Mutual labels:  maven-plugin, gradle-plugin
Maven Git Versioning Extension
This extension will virtually set project versions, based on current git branch or tag.
Stars: ✭ 178 (+947.06%)
Mutual labels:  maven-plugin, gradle-plugin
Typescript Generator
Generates TypeScript from Java - JSON declarations, REST service client
Stars: ✭ 729 (+4188.24%)
Mutual labels:  maven-plugin, gradle-plugin
Dependencycheck
OWASP dependency-check is a software composition analysis utility that detects publicly disclosed vulnerabilities in application dependencies.
Stars: ✭ 3,571 (+20905.88%)
Mutual labels:  maven-plugin, gradle-plugin
kgql
GraphQL Document wrapper generator for Kotlin Multiplatform Project and Android
Stars: ✭ 54 (+217.65%)
Mutual labels:  gradle-plugin, kotlinpoet
Bnd
Bnd/Bndtools. Tooling to build OSGi bundles including Eclipse, Maven, and Gradle plugins.
Stars: ✭ 446 (+2523.53%)
Mutual labels:  maven-plugin, gradle-plugin
Jib
🏗 Build container images for your Java applications.
Stars: ✭ 11,370 (+66782.35%)
Mutual labels:  maven-plugin, gradle-plugin
Javapackager
📦 Gradle/Maven plugin to package Java applications as native Windows, Mac OS X, or GNU/Linux executables and create installers for them.
Stars: ✭ 285 (+1576.47%)
Mutual labels:  maven-plugin, gradle-plugin
RapidMavenPushPlugin
A Gradle plugin : Upload Artifacts to Multi Maven Repository
Stars: ✭ 21 (+23.53%)
Mutual labels:  maven-plugin, gradle-plugin
boost
Boost Maven and Gradle plugins for MicroProfile development
Stars: ✭ 27 (+58.82%)
Mutual labels:  maven-plugin, gradle-plugin
Kotlin
The Kotlin Programming Language.
Stars: ✭ 39,664 (+233217.65%)
Mutual labels:  maven-plugin, gradle-plugin
gradle-git-versioning-plugin
This extension will set project version, based on current Git branch or tag.
Stars: ✭ 44 (+158.82%)
Mutual labels:  maven-plugin, gradle-plugin
dmn-check
A tool which performs static analyses on Decision Model Notation (DMN) files to detect bugs
Stars: ✭ 34 (+100%)
Mutual labels:  maven-plugin, gradle-plugin
kobby
Kobby is a codegen plugin of Kotlin DSL Client by GraphQL schema. The generated DSL supports execution of complex GraphQL queries, mutation and subscriptions in Kotlin with syntax similar to native GraphQL syntax.
Stars: ✭ 52 (+205.88%)
Mutual labels:  maven-plugin, gradle-plugin
native-build-tools
Native-image plugins for various build tools
Stars: ✭ 168 (+888.24%)
Mutual labels:  maven-plugin, gradle-plugin
scalafix-maven-plugin
Enables automatic refactoring and linting of Maven projects written in Scala using Scalafix.
Stars: ✭ 15 (-11.76%)
Mutual labels:  maven-plugin
eclipselink-maven-plugin
Eclipselink JPA Maven plugin, supporting static weaving, canonical model generation, and DDL generation.
Stars: ✭ 24 (+41.18%)
Mutual labels:  maven-plugin
pyroclastic
Functional dataflow through composable computations
Stars: ✭ 17 (+0%)
Mutual labels:  typesafe
gradle-localization-plugin
Gradle plugin for automating the download process of localization files.
Stars: ✭ 19 (+11.76%)
Mutual labels:  gradle-plugin
scalor-maven-plugin
Build integrator for Java, Scala, Scala.macro, Scala.js, Scala.native, Eclipse and Maven.
Stars: ✭ 47 (+176.47%)
Mutual labels:  maven-plugin

codecov CI generator gradle-plugin maven-plugin

What is poetimizely

poetimizely is a library to generate type safe accessors for Optimizely experiments and features. Given a Project ID and a token it will generate classes for every experiment + variations and features + variables.

Setup

ℹ️ Before editing the build file, there are three properties required to configure explained below:

  • optimizelyProjectId (Long): id of the Optimizely project to grab experiments and features from.
  • optimizelyToken (String): Optimizely personal access token. See Personal token authentication.
  • packageName (String): package where the code will be placed. The expected format is your.destination.package.

Gradle 🐘

Kotlin DSL (build.gradle.kts)

plugins {
  id("com.patxi.poetimizely") version "1.0.0"
}

poetimizely {
    optimizelyProjectId = $OPTIMIZELY_PROJECT_ID
    optimizelyToken = $PERSONAL_ACCESS_TOKEN
    packageName = $PACKAGE_NAME
}

Groovy (build.gradle)

plugins {
  id "com.patxi.poetimizely" version "1.0.0"
}

poetimizely {
    optimizelyProjectId = $OPTIMIZELY_PROJECT_ID
    optimizelyToken = $PERSONAL_ACCESS_TOKEN
    packageName = $PACKAGE_NAME
}

Maven 🕊️

pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>com.patxi</groupId>
            <artifactId>poetimizely-maven-plugin</artifactId>
            <version>1.0.0</version>
            <configuration>
                <optimizelyProjectId>$OPTIMIZELY_PROJECT_ID</optimizelyProjectId>
                <optimizelyToken>$PERSONAL_ACCESS_TOKEN</optimizelyToken>
                <packageName>$PACKAGE_NAME</packageName>
            </configuration>
        </plugin>
    </plugins>
</build>

Usage 📋

After the plugin has been setup, a new Gradle task / Maven goal named poetimize will be available. In order to run it successfully, both Optimizely project id and token must be valid.

For Gradle projects run:

./gradlew poetimize

or with Maven:

./mvnw poetimizely:poetimize

This will generate all the code based on the experiments (and its variants) and features defined for the given Optimizely project.

Experiments 🧪

For each of the experiments, a new object will be generated. And for the set of variations for each of the experiments an enum class will be also created.

An extension function for the Optimizely class is also available that brings the type safety:

when (optimizely.getVariationForExperiment(Experiments.ExampleExperiment, userId)) {
    EXAMPLE_VARIATION -> TODO() 
    null -> TODO()
}

Features 💡

Kotlin objects will also be generated for features. For the set of variables that each of the features may have, a property is added to the object.

To check whether a feature is enabled an extension function is provided:

if (optimizely.isFeatureEnabled(Features.ExampleFeature, userId)) {
    TODO()
}

and also for getting feature variables values:

val booleanVariable: Boolean? = optimizely.getFeatureVariable(Features.ExampleFeature.exampleBooleanVariable)
val stringVariable: String? = optimizely.getFeatureVariable(Features.ExampleFeature.exampleStringVariable)
val doubleVariable: Double? = optimizely.getFeatureVariable(Features.ExampleFeature.exampleDoubleVariable)
val intVariable: Int? = optimizely.getFeatureVariable(Features.ExampleFeature.exampleIntVariable)

A look at the generated code 👀

After running the task there will be two new classes generated in the given packageName:

Experiments.kt

interface BaseVariation {
    val key: String
}

fun Optimizely.getAllExperiments(): List<Experiments<out BaseVariation>> =
    listOf(Experiments.ExampleExperiment)

fun <V : BaseVariation> Optimizely.getVariationForExperiment(
    experiment: Experiments<out V>,
    userId: String,
    attributes: Map<String, Any> = emptyMap()
): V? {
    val variation = this.activate(experiment.key, userId, attributes)
    return experiment.variations.find { it.key == variation?.key }
}

enum class ExampleExperimentVariations : BaseVariation {
    EXAMPLE_VARIATION {
        override val key: String = "example-variation"
    }
}

sealed class Experiments<V : BaseVariation>(
    val key: String,
    val variations: Array<V>
) {
    object ExampleExperiment : Experiments<ExampleExperimentVariations> (
        "example-experiment",
        ExampleExperimentVariations.values()
    )
}

Features.kt

class FeatureVariable<T>(
    val featureKey: String,
    val variableKey: String
)

sealed class Features(
    val key: String
) {
    object ExampleFeature("example-feature") {
        val exampleVariable: FeatureVariable<Boolean> = FeatureVariable("example-feature", "example-variable")
    } 
}

fun Optimizely.isFeatureEnabled(
    feature: Features,
    userId: String,
    attributes: Map<String, Any> = emptyMap()
): Boolean = this.isFeatureEnabled(feature.key, userId, attributes)

fun Optimizely.getFeatureVariable(
    variable: FeatureVariable<Boolean>,
    userId: String,
    attributes: Map<String, Any> = emptyMap()
): Boolean? =
    this.getFeatureVariableBoolean(variable.featureKey, variable.variableKey, userId, attributes)

fun Optimizely.getFeatureVariable(
    variable: FeatureVariable<String>,
    userId: String,
    attributes: Map<String, Any> = emptyMap()
): String? =
    this.getFeatureVariableString(variable.featureKey, variable.variableKey, userId, attributes)

fun Optimizely.getFeatureVariable(
    variable: FeatureVariable<Double>,
    userId: String,
    attributes: Map<String, Any> = emptyMap()
): Double? =
    this.getFeatureVariableDouble(variable.featureKey, variable.variableKey, userId, attributes)

fun Optimizely.getFeatureVariable(
    variable: FeatureVariable<Int>,
    userId: String,
    attributes: Map<String, Any> = emptyMap()
): Int? =
    this.getFeatureVariableInteger(variable.featureKey, variable.variableKey, userId, attributes)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].