Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/sdk-spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
44 changes: 43 additions & 1 deletion sdk-spec/Steps.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -59,4 +73,32 @@ static List<SpecFlag> getIdentityFlags(
throws FlagsmithClientError {
return asSpecFlags(flagsmith.getIdentityFlags(identifier, traits));
}

// When the application gets the experiment flag "{feature}" for identity "{identifier}" with traits:
static List<SpecFlag> getExperimentFlag(
FlagsmithClient flagsmith, String feature, String identifier, Map<String, Object> 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<String, Object> 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<String, Object> metadata) {
flagsmith.trackExposureEvent(feature, identifier, value, null, metadata);
}
}
Loading