diff --git a/.github/workflows/sdk-spec.yml b/.github/workflows/sdk-spec.yml index ec972bb..852f3ab 100644 --- a/.github/workflows/sdk-spec.yml +++ b/.github/workflows/sdk-spec.yml @@ -15,4 +15,4 @@ jobs: with: spec-ref: v0.7.0 language: java - tags: core or local-evaluation + tags: core or local-evaluation or events diff --git a/sdk-spec/Steps.java b/sdk-spec/Steps.java index 74f05c6..c264f7a 100644 --- a/sdk-spec/Steps.java +++ b/sdk-spec/Steps.java @@ -3,6 +3,7 @@ import com.flagsmith.exceptions.FlagsmithClientError; import com.flagsmith.models.BaseFlag; import com.flagsmith.models.Flags; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -36,7 +37,20 @@ static FlagsmithClient createClient(String environmentKey, String apiUrl) { return FlagsmithClient.newBuilder().setApiKey(environmentKey).withApiUrl(apiUrl).build(); } - // Create the SDK client with local evaluation + // Create the SDK client with events enabled + static FlagsmithClient createClientWithEvents( + String environmentKey, String apiUrl, String eventsUrl) { + return FlagsmithClient.newBuilder() + .setApiKey(environmentKey) + .withConfiguration(FlagsmithConfig.newBuilder() + .baseUri(apiUrl) + .withEnableEvents(true) + .eventsUri(eventsUrl) + .build()) + .build(); + } + + // Create the SDK client with local evaluation static FlagsmithClient createClientWithLocalEvaluation(String environmentKey, String apiUrl) { return FlagsmithClient.newBuilder() .setApiKey(environmentKey) @@ -59,4 +73,32 @@ static List getIdentityFlags( throws FlagsmithClientError { return asSpecFlags(flagsmith.getIdentityFlags(identifier, traits)); } + + // When the application gets the experiment flag "{feature}" for identity "{identifier}" with traits: + static List getExperimentFlag( + FlagsmithClient flagsmith, String feature, String identifier, Map traits) + throws FlagsmithClientError { + return Collections.singletonList( + new SpecFlag(flagsmith.getExperimentFlag(feature, identifier, traits))); + } + + // When the application tracks event "{event}" for identity "{identifier}" with value {value} and metadata: + static void trackEvent( + FlagsmithClient flagsmith, + String event, + String identifier, + Object value, + Map metadata) { + flagsmith.trackEvent(event, identifier, value, null, metadata); + } + + // When the application tracks an exposure of feature "{feature}" for identity "{identifier}" with value {value} and metadata: + static void trackExposureEvent( + FlagsmithClient flagsmith, + String feature, + String identifier, + Object value, + Map metadata) { + flagsmith.trackExposureEvent(feature, identifier, value, null, metadata); + } }