Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MOB-6576] merge EUDC changes into encryption branch #600

Merged
merged 5 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions iterableapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ dependencies {
testImplementation 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.2.2'
testImplementation 'org.skyscreamer:jsonassert:1.5.0'
testImplementation project(path: ':iterableapi')
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test:rules:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down Expand Up @@ -96,6 +97,8 @@ task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
excludes = ['**/*.kt']
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))

exclude '**/*.kt'
}

tasks.withType(Test) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public class IterableConfig {
*/
final String[] allowedProtocols;

/**
* Data region determining which data center and endpoints are used by the SDK.
*/
final IterableDataRegion dataRegion;

/**
* This controls whether the in-app content should be saved to disk, or only kept in memory.
* By default, the SDK will save in-apps to disk.
Expand All @@ -91,6 +96,7 @@ private IterableConfig(Builder builder) {
authHandler = builder.authHandler;
expiringAuthTokenRefreshPeriod = builder.expiringAuthTokenRefreshPeriod;
allowedProtocols = builder.allowedProtocols;
dataRegion = builder.dataRegion;
useInMemoryStorageForInApps = builder.useInMemoryStorageForInApps;
encryptionEnforced = builder.encryptionEnforced;
}
Expand All @@ -107,6 +113,7 @@ public static class Builder {
private IterableAuthHandler authHandler;
private long expiringAuthTokenRefreshPeriod = 60000L;
private String[] allowedProtocols = new String[0];
private IterableDataRegion dataRegion = IterableDataRegion.US;
private boolean useInMemoryStorageForInApps = false;
private boolean encryptionEnforced = false;

Expand Down Expand Up @@ -235,6 +242,16 @@ public Builder setEncryptionEnforced(boolean encryptionEnforced) {
return this;
}

/**
* Set the data region used by the SDK
* @param dataRegion enum value that determines which endpoint to use, defaults to IterableDataRegion.US
*/
@NonNull
public Builder setDataRegion(@NonNull IterableDataRegion dataRegion) {
this.dataRegion = dataRegion;
return this;
}

/**
* Set whether the SDK should store in-apps only in memory, or in file storage
* @param useInMemoryStorageForInApps `true` will have in-apps be only in memory
Expand All @@ -251,5 +268,4 @@ public IterableConfig build() {
return new IterableConfig(this);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,4 @@ public final class IterableConstants {

public static final String NO_MESSAGES_TITLE = "noMessagesTitle";
public static final String NO_MESSAGES_BODY = "noMessagesBody";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.iterable.iterableapi;

public enum IterableDataRegion {
US("https://api.iterable.com/api/"),
EU("https://api.eu.iterable.com/api/");

private final String endpoint;

IterableDataRegion(String endpoint) {
this.endpoint = endpoint;
}

public String getEndpoint() {
return this.endpoint;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
*/
class IterableRequestTask extends AsyncTask<IterableApiRequest, Void, IterableApiResponse> {
static final String TAG = "IterableRequest";
static final String ITERABLE_BASE_URL = "https://api.iterable.com/api/";

static String overrideUrl;

Expand Down Expand Up @@ -65,8 +64,8 @@ static IterableApiResponse executeApiRequest(IterableApiRequest iterableApiReque
HttpURLConnection urlConnection = null;

IterableLogger.v(TAG, ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n");
String baseUrl = (iterableApiRequest.baseUrl != null && !iterableApiRequest.baseUrl.isEmpty()) ? iterableApiRequest.baseUrl :
ITERABLE_BASE_URL;
String baseUrl = getBaseUrl();

try {
if (overrideUrl != null && !overrideUrl.isEmpty()) {
baseUrl = overrideUrl;
Expand Down Expand Up @@ -225,6 +224,18 @@ static IterableApiResponse executeApiRequest(IterableApiRequest iterableApiReque
return apiResponse;
}

private static String getBaseUrl() {
IterableConfig config = IterableApi.getInstance().config;
IterableDataRegion dataRegion = config.dataRegion;
String baseUrl = dataRegion.getEndpoint();

if (overrideUrl != null && !overrideUrl.isEmpty()) {
baseUrl = overrideUrl;
}

return baseUrl;
}

private static boolean matchesErrorCode(JSONObject jsonResponse, String errorCode) {
try {
return jsonResponse != null && jsonResponse.has("code") && jsonResponse.getString("code").equals(errorCode);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.iterable.iterableapi

import org.hamcrest.Matchers.`is`
import org.junit.Assert.*
import org.junit.Test

class IterableConfigTest {

@Test
fun defaultDataRegion() {
val configBuilder: IterableConfig.Builder = IterableConfig.Builder()
val config: IterableConfig = configBuilder.build()
assertThat(config.dataRegion, `is`(IterableDataRegion.US))
}

@Test
fun setDataRegionToEU() {
val configBuilder: IterableConfig.Builder = IterableConfig.Builder()
.setDataRegion(IterableDataRegion.EU)
val config: IterableConfig = configBuilder.build()
assertThat(config.dataRegion, `is`(IterableDataRegion.EU))
}
}
Loading