Skip to content

Commit c956b3d

Browse files
authored
chore: rename apiKey to sdkKey for consistency (#105)
* feat: PR template * breaking: move builder entry point to static method
1 parent af4eea5 commit c956b3d

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

.github/pull_request_template.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
labels: mergeable
3+
---
4+
_Eppo Internal_
5+
[//]: # (Link to the issue or doc corresponding to this chunk of work)
6+
🎟️ Fixes: #__issue__
7+
📜 Design Doc (if applicable)
8+
9+
## Motivation and Context
10+
[//]: # (Why is this change required? What problem does it solve?)
11+
12+
## Description
13+
[//]: # (Describe your changes in detail)
14+
15+
## How has this been documented?
16+
[//]: # (Please describe how you documented the developer impact of your changes; link to PRs or issues)
17+
18+
## How has this been tested?
19+
[//]: # (Please describe in detail how you tested your changes)
20+
21+
22+
[//]: # (OPTIONAL)
23+
[//]: # (Add one or multiple labels: enhancement, refactoring, bugfix)

src/main/java/cloud/eppo/EppoClient.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import cloud.eppo.logging.AssignmentLogger;
77
import cloud.eppo.logging.BanditLogger;
88
import java.util.concurrent.TimeUnit;
9+
import org.jetbrains.annotations.NotNull;
910
import org.jetbrains.annotations.Nullable;
1011
import org.slf4j.Logger;
1112
import org.slf4j.LoggerFactory;
@@ -34,7 +35,7 @@ public static EppoClient getInstance() {
3435
}
3536

3637
private EppoClient(
37-
String apiKey,
38+
String sdkKey,
3839
String sdkName,
3940
String sdkVersion,
4041
@Nullable String baseUrl,
@@ -44,7 +45,7 @@ private EppoClient(
4445
@Nullable IAssignmentCache assignmentCache,
4546
@Nullable IAssignmentCache banditAssignmentCache) {
4647
super(
47-
apiKey,
48+
sdkKey,
4849
sdkName,
4950
sdkVersion,
5051
null,
@@ -60,9 +61,18 @@ private EppoClient(
6061
banditAssignmentCache);
6162
}
6263

64+
/**
65+
* Creates a new EppoClient Builder object with the specified SDK Key.
66+
*
67+
* @param sdkKey (see <a href="https://docs.geteppo.com/sdks/sdk-keys/">SDK Keys</a>)
68+
*/
69+
public static Builder builder(@NotNull String sdkKey) {
70+
return new Builder(sdkKey);
71+
}
72+
6373
/** Builder pattern to initialize the EppoClient singleton */
6474
public static class Builder {
65-
private String apiKey;
75+
private final String sdkKey;
6676
private AssignmentLogger assignmentLogger;
6777
private BanditLogger banditLogger;
6878
private boolean isGracefulMode = DEFAULT_IS_GRACEFUL_MODE;
@@ -76,10 +86,8 @@ public static class Builder {
7686
private IAssignmentCache banditAssignmentCache =
7787
new ExpiringInMemoryAssignmentCache(10, TimeUnit.MINUTES);
7888

79-
/** Sets the API Key--created within the eppo application--to use. This is required. */
80-
public Builder apiKey(String apiKey) {
81-
this.apiKey = apiKey;
82-
return this;
89+
private Builder(@NotNull String sdkKey) {
90+
this.sdkKey = sdkKey;
8391
}
8492

8593
/**
@@ -168,7 +176,7 @@ public EppoClient buildAndInit() {
168176

169177
instance =
170178
new EppoClient(
171-
apiKey,
179+
sdkKey,
172180
sdkName,
173181
sdkVersion,
174182
apiBaseUrl,

src/test/java/cloud/eppo/EppoClientTest.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ public void testErrorGracefulModeOff() {
203203
@Test
204204
public void testReinitializeWithoutForcing() {
205205
EppoClient firstInstance = initClient(DUMMY_FLAG_API_KEY);
206-
EppoClient secondInstance = new EppoClient.Builder().apiKey(DUMMY_FLAG_API_KEY).buildAndInit();
206+
EppoClient secondInstance = EppoClient.builder(DUMMY_FLAG_API_KEY).buildAndInit();
207207

208208
assertSame(firstInstance, secondInstance);
209209
}
@@ -212,7 +212,7 @@ public void testReinitializeWithoutForcing() {
212212
public void testReinitializeWitForcing() {
213213
EppoClient firstInstance = initClient(DUMMY_FLAG_API_KEY);
214214
EppoClient secondInstance =
215-
new EppoClient.Builder().apiKey(DUMMY_FLAG_API_KEY).forceReinitialize(true).buildAndInit();
215+
EppoClient.builder(DUMMY_FLAG_API_KEY).forceReinitialize(true).buildAndInit();
216216

217217
assertNotSame(firstInstance, secondInstance);
218218
}
@@ -223,8 +223,7 @@ public void testPolling() {
223223
EppoHttpClient httpClientSpy = spy(httpClient);
224224
TestUtils.setBaseClientHttpClientOverrideField(httpClientSpy);
225225

226-
new EppoClient.Builder()
227-
.apiKey(DUMMY_FLAG_API_KEY)
226+
EppoClient.builder(DUMMY_FLAG_API_KEY)
228227
.pollingIntervalMs(20)
229228
.forceReinitialize(true)
230229
.buildAndInit();
@@ -300,8 +299,7 @@ private EppoClient initClient(String apiKey) {
300299
mockAssignmentLogger = mock(AssignmentLogger.class);
301300
mockBanditLogger = mock(BanditLogger.class);
302301

303-
return new EppoClient.Builder()
304-
.apiKey(apiKey)
302+
return EppoClient.builder(apiKey)
305303
.apiBaseUrl(Constants.appendApiPathToHost(TEST_HOST))
306304
.assignmentLogger(mockAssignmentLogger)
307305
.banditLogger(mockBanditLogger)
@@ -314,8 +312,7 @@ private EppoClient initFailingGracefulClient(boolean isGracefulMode) {
314312
mockAssignmentLogger = mock(AssignmentLogger.class);
315313
mockBanditLogger = mock(BanditLogger.class);
316314

317-
return new EppoClient.Builder()
318-
.apiKey(DUMMY_FLAG_API_KEY)
315+
return EppoClient.builder(DUMMY_FLAG_API_KEY)
319316
.apiBaseUrl("blag")
320317
.assignmentLogger(mockAssignmentLogger)
321318
.banditLogger(mockBanditLogger)

0 commit comments

Comments
 (0)