Skip to content

Commit f7623cd

Browse files
evantk91Ayyanchiradevcsomnicgharrymash2006“Akshay
authored
[MOB-6576] merge EUDC changes into encryption branch (#600)
* [MOB 5730] Add callbacks to reading/removing in-app messages (#557) (#583) * [MOB 5730] Add callbacks to reading/removing in-app messages (#557) * add callback for setRead/removeMessage * modify test for setRead and added test for removeMessage * fixes * Update build.gradle * removed resultcallbackhandler * Update IterableInAppManager.java * fixes --------- Co-authored-by: Akshay Ayyanchira <ayyanchira.akshay@gmail.com> Co-authored-by: Hardik Mashru <harrymash2006@gmail.com> * Fixing and adding test method --------- Co-authored-by: devcsomnicg <129495456+devcsomnicg@users.noreply.github.com> Co-authored-by: Hardik Mashru <harrymash2006@gmail.com> Co-authored-by: “Akshay <“ayyanchira.akshay@gmail.com”> * [MOB - 6493] - Message read and remove bug fix (#592) Co-authored-by: “Akshay <“ayyanchira.akshay@gmail.com”> * MOB-5132: Fix deep link issue after app is opened from notification (#546) (#593) Co-authored-by: devcsomnicg <129495456+devcsomnicg@users.noreply.github.com> * [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> --------- Co-authored-by: Akshay Ayyanchira <ayyanchira.akshay@gmail.com> Co-authored-by: devcsomnicg <129495456+devcsomnicg@users.noreply.github.com> Co-authored-by: Hardik Mashru <harrymash2006@gmail.com> Co-authored-by: “Akshay <“ayyanchira.akshay@gmail.com”> Co-authored-by: evan.greer@iterable.com <evan.greer@evan.greer>
1 parent e094722 commit f7623cd

File tree

6 files changed

+75
-6
lines changed

6 files changed

+75
-6
lines changed

iterableapi/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ dependencies {
5555
testImplementation 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
5656
testImplementation 'com.squareup.okhttp3:mockwebserver:4.2.2'
5757
testImplementation 'org.skyscreamer:jsonassert:1.5.0'
58+
testImplementation project(path: ':iterableapi')
5859
androidTestImplementation 'androidx.test:runner:1.3.0'
5960
androidTestImplementation 'androidx.test:rules:1.3.0'
6061
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
@@ -96,6 +97,8 @@ task javadoc(type: Javadoc) {
9697
source = android.sourceSets.main.java.srcDirs
9798
excludes = ['**/*.kt']
9899
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
100+
101+
exclude '**/*.kt'
99102
}
100103

101104
tasks.withType(Test) {

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.
@@ -91,6 +96,7 @@ private IterableConfig(Builder builder) {
9196
authHandler = builder.authHandler;
9297
expiringAuthTokenRefreshPeriod = builder.expiringAuthTokenRefreshPeriod;
9398
allowedProtocols = builder.allowedProtocols;
99+
dataRegion = builder.dataRegion;
94100
useInMemoryStorageForInApps = builder.useInMemoryStorageForInApps;
95101
encryptionEnforced = builder.encryptionEnforced;
96102
}
@@ -107,6 +113,7 @@ public static class Builder {
107113
private IterableAuthHandler authHandler;
108114
private long expiringAuthTokenRefreshPeriod = 60000L;
109115
private String[] allowedProtocols = new String[0];
116+
private IterableDataRegion dataRegion = IterableDataRegion.US;
110117
private boolean useInMemoryStorageForInApps = false;
111118
private boolean encryptionEnforced = false;
112119

@@ -235,6 +242,16 @@ public Builder setEncryptionEnforced(boolean encryptionEnforced) {
235242
return this;
236243
}
237244

245+
/**
246+
* Set the data region used by the SDK
247+
* @param dataRegion enum value that determines which endpoint to use, defaults to IterableDataRegion.US
248+
*/
249+
@NonNull
250+
public Builder setDataRegion(@NonNull IterableDataRegion dataRegion) {
251+
this.dataRegion = dataRegion;
252+
return this;
253+
}
254+
238255
/**
239256
* Set whether the SDK should store in-apps only in memory, or in file storage
240257
* @param useInMemoryStorageForInApps `true` will have in-apps be only in memory
@@ -251,5 +268,4 @@ public IterableConfig build() {
251268
return new IterableConfig(this);
252269
}
253270
}
254-
255-
}
271+
}

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

Lines changed: 1 addition & 1 deletion
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+
}
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)