diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..bf4d819 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,23 @@ +--- +labels: mergeable +--- +_Eppo Internal_ +[//]: # (Link to the issue or doc corresponding to this chunk of work) +🎟️ Fixes: #__issue__ +📜 Design Doc (if applicable) + +## Motivation and Context +[//]: # (Why is this change required? What problem does it solve?) + +## Description +[//]: # (Describe your changes in detail) + +## How has this been documented? +[//]: # (Please describe how you documented the developer impact of your changes; link to PRs or issues) + +## How has this been tested? +[//]: # (Please describe in detail how you tested your changes) + + +[//]: # (OPTIONAL) +[//]: # (Add one or multiple labels: enhancement, refactoring, bugfix) \ No newline at end of file diff --git a/src/main/java/cloud/eppo/EppoClient.java b/src/main/java/cloud/eppo/EppoClient.java index 2640925..0dea696 100644 --- a/src/main/java/cloud/eppo/EppoClient.java +++ b/src/main/java/cloud/eppo/EppoClient.java @@ -6,6 +6,7 @@ import cloud.eppo.logging.AssignmentLogger; import cloud.eppo.logging.BanditLogger; import java.util.concurrent.TimeUnit; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,7 +35,7 @@ public static EppoClient getInstance() { } private EppoClient( - String apiKey, + String sdkKey, String sdkName, String sdkVersion, @Nullable String baseUrl, @@ -44,7 +45,7 @@ private EppoClient( @Nullable IAssignmentCache assignmentCache, @Nullable IAssignmentCache banditAssignmentCache) { super( - apiKey, + sdkKey, sdkName, sdkVersion, null, @@ -60,9 +61,18 @@ private EppoClient( banditAssignmentCache); } + /** + * Creates a new EppoClient Builder object with the specified SDK Key. + * + * @param sdkKey (see SDK Keys) + */ + public static Builder builder(@NotNull String sdkKey) { + return new Builder(sdkKey); + } + /** Builder pattern to initialize the EppoClient singleton */ public static class Builder { - private String apiKey; + private final String sdkKey; private AssignmentLogger assignmentLogger; private BanditLogger banditLogger; private boolean isGracefulMode = DEFAULT_IS_GRACEFUL_MODE; @@ -76,10 +86,8 @@ public static class Builder { private IAssignmentCache banditAssignmentCache = new ExpiringInMemoryAssignmentCache(10, TimeUnit.MINUTES); - /** Sets the API Key--created within the eppo application--to use. This is required. */ - public Builder apiKey(String apiKey) { - this.apiKey = apiKey; - return this; + private Builder(@NotNull String sdkKey) { + this.sdkKey = sdkKey; } /** @@ -168,7 +176,7 @@ public EppoClient buildAndInit() { instance = new EppoClient( - apiKey, + sdkKey, sdkName, sdkVersion, apiBaseUrl, diff --git a/src/test/java/cloud/eppo/EppoClientTest.java b/src/test/java/cloud/eppo/EppoClientTest.java index cb971fb..e744d66 100644 --- a/src/test/java/cloud/eppo/EppoClientTest.java +++ b/src/test/java/cloud/eppo/EppoClientTest.java @@ -203,7 +203,7 @@ public void testErrorGracefulModeOff() { @Test public void testReinitializeWithoutForcing() { EppoClient firstInstance = initClient(DUMMY_FLAG_API_KEY); - EppoClient secondInstance = new EppoClient.Builder().apiKey(DUMMY_FLAG_API_KEY).buildAndInit(); + EppoClient secondInstance = EppoClient.builder(DUMMY_FLAG_API_KEY).buildAndInit(); assertSame(firstInstance, secondInstance); } @@ -212,7 +212,7 @@ public void testReinitializeWithoutForcing() { public void testReinitializeWitForcing() { EppoClient firstInstance = initClient(DUMMY_FLAG_API_KEY); EppoClient secondInstance = - new EppoClient.Builder().apiKey(DUMMY_FLAG_API_KEY).forceReinitialize(true).buildAndInit(); + EppoClient.builder(DUMMY_FLAG_API_KEY).forceReinitialize(true).buildAndInit(); assertNotSame(firstInstance, secondInstance); } @@ -223,8 +223,7 @@ public void testPolling() { EppoHttpClient httpClientSpy = spy(httpClient); TestUtils.setBaseClientHttpClientOverrideField(httpClientSpy); - new EppoClient.Builder() - .apiKey(DUMMY_FLAG_API_KEY) + EppoClient.builder(DUMMY_FLAG_API_KEY) .pollingIntervalMs(20) .forceReinitialize(true) .buildAndInit(); @@ -300,8 +299,7 @@ private EppoClient initClient(String apiKey) { mockAssignmentLogger = mock(AssignmentLogger.class); mockBanditLogger = mock(BanditLogger.class); - return new EppoClient.Builder() - .apiKey(apiKey) + return EppoClient.builder(apiKey) .apiBaseUrl(Constants.appendApiPathToHost(TEST_HOST)) .assignmentLogger(mockAssignmentLogger) .banditLogger(mockBanditLogger) @@ -314,8 +312,7 @@ private EppoClient initFailingGracefulClient(boolean isGracefulMode) { mockAssignmentLogger = mock(AssignmentLogger.class); mockBanditLogger = mock(BanditLogger.class); - return new EppoClient.Builder() - .apiKey(DUMMY_FLAG_API_KEY) + return EppoClient.builder(DUMMY_FLAG_API_KEY) .apiBaseUrl("blag") .assignmentLogger(mockAssignmentLogger) .banditLogger(mockBanditLogger)