Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: better DX #107

Merged
merged 4 commits into from
Oct 16, 2024
Merged
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ feature flagging and experimentation for Eppo customers. An API key is required

```groovy
dependencies {
implementation 'cloud.eppo:android-sdk:4.0.0'
implementation 'cloud.eppo:android-sdk:4.1.0'
}

dependencyResolutionManagement {
Expand Down
2 changes: 1 addition & 1 deletion eppo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "cloud.eppo"
version = "4.0.1-SNAPSHOT"
version = "4.1.0-SNAPSHOT"

android {
buildFeatures.buildConfig true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,7 @@ private void initClient(
setBaseClientHttpClientOverrideField(httpClientOverride);

CompletableFuture<Void> futureClient =
new EppoClient.Builder()
.application(ApplicationProvider.getApplicationContext())
.apiKey(apiKey)
new EppoClient.Builder(apiKey, ApplicationProvider.getApplicationContext())
.isGracefulMode(isGracefulMode)
.host(host)
.assignmentLogger(mockAssignmentLogger)
Expand Down
33 changes: 14 additions & 19 deletions eppo/src/main/java/cloud/eppo/android/EppoClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ public static EppoClient init(
@NonNull String host,
@Nullable AssignmentLogger assignmentLogger,
boolean isGracefulMode) {
return new Builder()
.application(application)
.apiKey(apiKey)
return new Builder(apiKey, application)
.host(host)
.assignmentLogger(assignmentLogger)
.isGracefulMode(isGracefulMode)
Expand All @@ -81,9 +79,7 @@ public static CompletableFuture<EppoClient> initAsync(
@NonNull String host,
@Nullable AssignmentLogger assignmentLogger,
boolean isGracefulMode) {
return new Builder()
.application(application)
.apiKey(apiKey)
return new Builder(apiKey, application)
.host(host)
.assignmentLogger(assignmentLogger)
.isGracefulMode(isGracefulMode)
Expand Down Expand Up @@ -111,8 +107,8 @@ protected EppoValue getTypedAssignment(

public static class Builder {
@NonNull private String host = DEFAULT_HOST;
@Nullable private Application application;
@Nullable private String apiKey;
private final Application application;
private final String apiKey;
@Nullable private AssignmentLogger assignmentLogger;
@Nullable private ConfigurationStore configStore;
private boolean isGracefulMode = DEFAULT_IS_GRACEFUL_MODE;
Expand All @@ -121,14 +117,9 @@ public static class Builder {
private boolean offlineMode = false;
private CompletableFuture<Configuration> initialConfiguration;

public Builder apiKey(String apiKey) {
this.apiKey = apiKey;
return this;
}

public Builder application(Application application) {
public Builder(@NonNull String apiKey, @NonNull Application application) {
this.application = application;
return this;
this.apiKey = apiKey;
}

public Builder host(String host) {
Expand Down Expand Up @@ -161,12 +152,16 @@ public Builder offlineMode(boolean offlineMode) {
return this;
}

public Builder withInitialFlagConfigResponse(
String initialFlagConfigResponse, boolean isConfigObfuscated) {
public Builder initialConfiguration(byte[] initialFlagConfigResponse) {
this.initialConfiguration =
CompletableFuture.completedFuture(
Configuration.builder(initialFlagConfigResponse.getBytes(), isConfigObfuscated)
.build());
Configuration.builder(initialFlagConfigResponse, true).build());
return this;
}

public Builder initialConfiguration(CompletableFuture<byte[]> initialFlagConfigResponse) {
this.initialConfiguration =
initialFlagConfigResponse.thenApply(ic -> Configuration.builder(ic, true).build());
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ protected void onCreate(Bundle savedInstanceState) {
Bundle extras = getIntent().getExtras();
boolean offlineMode = extras != null && extras.getBoolean(this.getPackageName() + ".offlineMode", false);

new EppoClient.Builder()
.application(getApplication())
.apiKey(API_KEY)
new EppoClient.Builder(API_KEY, getApplication())
.isGracefulMode(true)
.offlineMode(offlineMode)
.forceReinitialize(true)
Expand Down
Loading