Skip to content

Commit eee1b76

Browse files
evantk91evan.greer@iterable.com
andcommitted
[MOB-6309] prepares EUDC updates for release (#572)
* stashed changes * adds data center to config and associated unit tests * adds excluding kotlin files to javadoc check * moves IterableDataRegion to IterableConstants.java * gets rid of extra lines * removes jacoco.exe * adds endpoint override to IterableApi * removes logging statement * sets up base url at IterableRequestTask * minor edits * refactors to pull endpoint directly from config value * removes unfinished unit test * removes jacoco.exec * removes white space --------- Co-authored-by: evan.greer@iterable.com <evan.greer@evan.greer>
1 parent b8fc54a commit eee1b76

File tree

6 files changed

+73
-6
lines changed

6 files changed

+73
-6
lines changed

iterableapi/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ dependencies {
5252
testImplementation 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
5353
testImplementation 'com.squareup.okhttp3:mockwebserver:4.2.2'
5454
testImplementation 'org.skyscreamer:jsonassert:1.5.0'
55+
testImplementation project(path: ':iterableapi')
5556
androidTestImplementation 'androidx.test:runner:1.3.0'
5657
androidTestImplementation 'androidx.test:rules:1.3.0'
5758
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

iterableapi/src/main/java/com/iterable/iterableapi/IterableConfig.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ public class IterableConfig {
7171
*/
7272
final String[] allowedProtocols;
7373

74+
/**
75+
* Data region determining which data center and endpoints are used by the SDK.
76+
*/
77+
final IterableDataRegion dataRegion;
78+
7479
/**
7580
* This controls whether the in-app content should be saved to disk, or only kept in memory.
7681
* By default, the SDK will save in-apps to disk.
@@ -89,6 +94,7 @@ private IterableConfig(Builder builder) {
8994
authHandler = builder.authHandler;
9095
expiringAuthTokenRefreshPeriod = builder.expiringAuthTokenRefreshPeriod;
9196
allowedProtocols = builder.allowedProtocols;
97+
dataRegion = builder.dataRegion;
9298
useInMemoryStorageForInApps = builder.useInMemoryStorageForInApps;
9399
}
94100

@@ -104,6 +110,7 @@ public static class Builder {
104110
private IterableAuthHandler authHandler;
105111
private long expiringAuthTokenRefreshPeriod = 60000L;
106112
private String[] allowedProtocols = new String[0];
113+
private IterableDataRegion dataRegion = IterableDataRegion.US;
107114
private boolean useInMemoryStorageForInApps = false;
108115

109116
public Builder() {}
@@ -226,6 +233,16 @@ public Builder setAllowedProtocols(@NonNull String[] allowedProtocols) {
226233
return this;
227234
}
228235

236+
/**
237+
* Set the data region used by the SDK
238+
* @param dataRegion enum value that determines which endpoint to use, defaults to IterableDataRegion.US
239+
*/
240+
@NonNull
241+
public Builder setDataRegion(@NonNull IterableDataRegion dataRegion) {
242+
this.dataRegion = dataRegion;
243+
return this;
244+
}
245+
229246
/**
230247
* Set whether the SDK should store in-apps only in memory, or in file storage
231248
* @param useInMemoryStorageForInApps `true` will have in-apps be only in memory
@@ -242,5 +259,4 @@ public IterableConfig build() {
242259
return new IterableConfig(this);
243260
}
244261
}
245-
246-
}
262+
}

iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,4 +294,4 @@ public final class IterableConstants {
294294

295295
public static final String NO_MESSAGES_TITLE = "noMessagesTitle";
296296
public static final String NO_MESSAGES_BODY = "noMessagesBody";
297-
}
297+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.iterable.iterableapi;
2+
3+
public enum IterableDataRegion {
4+
US("https://api.iterable.com/api/"),
5+
EU("https://api.eu.iterable.com/api/");
6+
7+
private final String endpoint;
8+
9+
IterableDataRegion(String endpoint) {
10+
this.endpoint = endpoint;
11+
}
12+
13+
public String getEndpoint() {
14+
return this.endpoint;
15+
}
16+
}

iterableapi/src/main/java/com/iterable/iterableapi/IterableRequestTask.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
*/
2828
class IterableRequestTask extends AsyncTask<IterableApiRequest, Void, IterableApiResponse> {
2929
static final String TAG = "IterableRequest";
30-
static final String ITERABLE_BASE_URL = "https://api.iterable.com/api/";
3130

3231
static String overrideUrl;
3332

@@ -65,8 +64,8 @@ static IterableApiResponse executeApiRequest(IterableApiRequest iterableApiReque
6564
HttpURLConnection urlConnection = null;
6665

6766
IterableLogger.v(TAG, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
68-
String baseUrl = (iterableApiRequest.baseUrl != null && !iterableApiRequest.baseUrl.isEmpty()) ? iterableApiRequest.baseUrl :
69-
ITERABLE_BASE_URL;
67+
String baseUrl = getBaseUrl();
68+
7069
try {
7170
if (overrideUrl != null && !overrideUrl.isEmpty()) {
7271
baseUrl = overrideUrl;
@@ -225,6 +224,18 @@ static IterableApiResponse executeApiRequest(IterableApiRequest iterableApiReque
225224
return apiResponse;
226225
}
227226

227+
private static String getBaseUrl() {
228+
IterableConfig config = IterableApi.getInstance().config;
229+
IterableDataRegion dataRegion = config.dataRegion;
230+
String baseUrl = dataRegion.getEndpoint();
231+
232+
if (overrideUrl != null && !overrideUrl.isEmpty()) {
233+
baseUrl = overrideUrl;
234+
}
235+
236+
return baseUrl;
237+
}
238+
228239
private static boolean matchesErrorCode(JSONObject jsonResponse, String errorCode) {
229240
try {
230241
return jsonResponse != null && jsonResponse.has("code") && jsonResponse.getString("code").equals(errorCode);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.iterable.iterableapi
2+
3+
import org.hamcrest.Matchers.`is`
4+
import org.junit.Assert.*
5+
import org.junit.Test
6+
7+
class IterableConfigTest {
8+
9+
@Test
10+
fun defaultDataRegion() {
11+
val configBuilder: IterableConfig.Builder = IterableConfig.Builder()
12+
val config: IterableConfig = configBuilder.build()
13+
assertThat(config.dataRegion, `is`(IterableDataRegion.US))
14+
}
15+
16+
@Test
17+
fun setDataRegionToEU() {
18+
val configBuilder: IterableConfig.Builder = IterableConfig.Builder()
19+
.setDataRegion(IterableDataRegion.EU)
20+
val config: IterableConfig = configBuilder.build()
21+
assertThat(config.dataRegion, `is`(IterableDataRegion.EU))
22+
}
23+
}

0 commit comments

Comments
 (0)