Skip to content

Commit 6f5a805

Browse files
evantk91evan.greer@iterable.com
and
evan.greer@iterable.com
authored
[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 b780ec4 commit 6f5a805

File tree

6 files changed

+75
-6
lines changed

6 files changed

+75
-6
lines changed

Diff for: iterableapi/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ dependencies {
5151
testImplementation 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
5252
testImplementation 'com.squareup.okhttp3:mockwebserver:4.2.2'
5353
testImplementation 'org.skyscreamer:jsonassert:1.5.0'
54+
testImplementation project(path: ':iterableapi')
5455
androidTestImplementation 'androidx.test:runner:1.3.0'
5556
androidTestImplementation 'androidx.test:rules:1.3.0'
5657
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
@@ -90,6 +91,8 @@ if(hasProperty("mavenPublishEnabled")) {
9091
task javadoc(type: Javadoc) {
9192
source = android.sourceSets.main.java.srcDirs
9293
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
94+
95+
exclude '**/*.kt'
9396
}
9497

9598
tasks.withType(Test) {

Diff for: iterableapi/src/main/java/com/iterable/iterableapi/IterableConfig.java

+18-2
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+
}

Diff for: iterableapi/src/main/java/com/iterable/iterableapi/IterableConstants.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,4 @@ public final class IterableConstants {
252252

253253
public static final String NO_MESSAGES_TITLE = "noMessagesTitle";
254254
public static final String NO_MESSAGES_BODY = "noMessagesBody";
255-
}
255+
}
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+
}

Diff for: iterableapi/src/main/java/com/iterable/iterableapi/IterableRequestTask.java

+14-3
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);
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)