Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public void onInboxUpdated() {

@Override
public void onListItemTapped(@NonNull IterableInAppMessage message) {
IterableApi.getInstance().getInAppManager().setRead(message, true);
IterableApi.getInstance().getInAppManager().setRead(message, true, null, null);

if (inboxMode == InboxMode.ACTIVITY) {
startActivity(new Intent(getContext(), IterableInboxMessageActivity.class).putExtra(IterableInboxMessageActivity.ARG_MESSAGE_ID, message.getMessageId()));
Expand Down
3 changes: 3 additions & 0 deletions iterableapi/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,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 @@ -90,6 +91,8 @@ if(hasProperty("mavenPublishEnabled")) {
task javadoc(type: Javadoc) {
source = android.sourceSets.main.java.srcDirs
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 @@ -725,7 +725,26 @@ public void inAppConsume(@NonNull String messageId) {
IterableLogger.e(TAG, "inAppConsume: message is null");
return;
}
inAppConsume(message, null, null);
inAppConsume(message, null, null, null, null);
IterableLogger.printInfo();
}

/**
* Consumes an InApp message.
* @param messageId
* @param successHandler The callback which returns `success`.
* @param failureHandler The callback which returns `failure`.
*/
public void inAppConsume(@NonNull String messageId, @Nullable IterableHelper.SuccessHandler successHandler, @Nullable IterableHelper.FailureHandler failureHandler) {
IterableInAppMessage message = getInAppManager().getMessageById(messageId);
if (message == null) {
IterableLogger.e(TAG, "inAppConsume: message is null");
if (failureHandler != null) {
failureHandler.onFailure("inAppConsume: message is null", null);
}
return;
}
inAppConsume(message, null, null, successHandler, failureHandler);
IterableLogger.printInfo();
}

Expand All @@ -742,8 +761,25 @@ public void inAppConsume(@NonNull IterableInAppMessage message, @Nullable Iterab
if (!checkSDKInitialization()) {
return;
}
apiClient.inAppConsume(message, source, clickLocation, inboxSessionId, null, null);
}

apiClient.inAppConsume(message, source, clickLocation, inboxSessionId);
/**
* Tracks InApp delete.
* This method from informs Iterable about inApp messages deleted with additional paramters.
* Call this method from places where inApp deletion are invoked by user. The messages can be swiped to delete or can be deleted using the link to delete button.
*
* @param message message object
* @param source An enum describing how the in App delete was triggered
* @param clickLocation The module in which the action happened
* @param successHandler The callback which returns `success`.
* @param failureHandler The callback which returns `failure`.
*/
public void inAppConsume(@NonNull IterableInAppMessage message, @Nullable IterableInAppDeleteActionType source, @Nullable IterableInAppLocation clickLocation, @Nullable IterableHelper.SuccessHandler successHandler, @Nullable IterableHelper.FailureHandler failureHandler) {
if (!checkSDKInitialization()) {
return;
}
apiClient.inAppConsume(message, source, clickLocation, inboxSessionId, successHandler, failureHandler);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ void trackInAppDelivery(@NonNull IterableInAppMessage message) {
}
}

public void inAppConsume(@NonNull IterableInAppMessage message, @Nullable IterableInAppDeleteActionType source, @Nullable IterableInAppLocation clickLocation, @Nullable String inboxSessionId) {
public void inAppConsume(@NonNull IterableInAppMessage message, @Nullable IterableInAppDeleteActionType source, @Nullable IterableInAppLocation clickLocation, @Nullable String inboxSessionId, @Nullable final IterableHelper.SuccessHandler successHandler, @Nullable final IterableHelper.FailureHandler failureHandler) {
JSONObject requestJSON = new JSONObject();

try {
Expand All @@ -336,7 +336,7 @@ public void inAppConsume(@NonNull IterableInAppMessage message, @Nullable Iterab
addInboxSessionID(requestJSON, inboxSessionId);
}

sendPostRequest(IterableConstants.ENDPOINT_INAPP_CONSUME, requestJSON);
sendPostRequest(IterableConstants.ENDPOINT_INAPP_CONSUME, requestJSON, successHandler, failureHandler);
} catch (JSONException e) {
e.printStackTrace();
}
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 @@ -89,6 +94,7 @@ private IterableConfig(Builder builder) {
authHandler = builder.authHandler;
expiringAuthTokenRefreshPeriod = builder.expiringAuthTokenRefreshPeriod;
allowedProtocols = builder.allowedProtocols;
dataRegion = builder.dataRegion;
useInMemoryStorageForInApps = builder.useInMemoryStorageForInApps;
}

Expand All @@ -104,6 +110,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;

public Builder() {}
Expand Down Expand Up @@ -226,6 +233,16 @@ public Builder setAllowedProtocols(@NonNull String[] allowedProtocols) {
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 @@ -242,5 +259,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 @@ -417,7 +417,7 @@ private void processMessageRemoval() {
}

if (message.isMarkedForDeletion() && !message.isConsumed()) {
IterableApi.sharedInstance.getInAppManager().removeMessage(message);
IterableApi.sharedInstance.getInAppManager().removeMessage(message, null, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,20 @@ public synchronized int getUnreadInboxMessagesCount() {
return unreadInboxMessageCount;
}

public synchronized void setRead(@NonNull IterableInAppMessage message, boolean read) {
setRead(message, read, null, null);
}
/**
* Set the read flag on an inbox message
* @param message Inbox message object retrieved from {@link IterableInAppManager#getInboxMessages()}
* @param read Read state flag. true = read, false = unread
* @param successHandler The callback which returns `success`.
*/
public synchronized void setRead(@NonNull IterableInAppMessage message, boolean read) {
public synchronized void setRead(@NonNull IterableInAppMessage message, boolean read, @Nullable IterableHelper.SuccessHandler successHandler, @Nullable IterableHelper.FailureHandler failureHandler) {
message.setRead(read);
if (successHandler != null) {
successHandler.onSuccess(new JSONObject()); // passing blank json object here as onSuccess is @Nonnull
}
notifyOnChange();
}

Expand Down Expand Up @@ -239,7 +246,7 @@ public void execute(Uri url) {
scheduleProcessing();
}
})) {
setRead(message, true);
setRead(message, true, null, null);
if (consume) {
message.markForDeletion(true);
}
Expand All @@ -251,15 +258,31 @@ public void execute(Uri url) {
* @param message The message to be removed
*/
public synchronized void removeMessage(@NonNull IterableInAppMessage message) {
message.setConsumed(true);
api.inAppConsume(message.getMessageId());
notifyOnChange();
removeMessage(message, null, null, null, null);
}

/**
* Remove message from the list
* @param message The message to be removed
* @param source Source from where the message removal occured. Use IterableInAppDeleteActionType for available sources
* @param clickLocation Where was the message clicked. Use IterableInAppLocation for available Click Locations
*/
public synchronized void removeMessage(@NonNull IterableInAppMessage message, @NonNull IterableInAppDeleteActionType source, @NonNull IterableInAppLocation clickLocation) {
removeMessage(message, source, clickLocation, null, null);
}

/**
* Remove message from the list
* @param message The message to be removed
* @param source Source from where the message removal occured. Use IterableInAppDeleteActionType for available sources
* @param clickLocation Where was the message clicked. Use IterableInAppLocation for available Click Locations
* @param successHandler The callback which returns `success`.
* @param failureHandler The callback which returns `failure`.
*/
public synchronized void removeMessage(@NonNull IterableInAppMessage message, @Nullable IterableInAppDeleteActionType source, @Nullable IterableInAppLocation clickLocation, @Nullable IterableHelper.SuccessHandler successHandler, @Nullable IterableHelper.FailureHandler failureHandler) {
IterableLogger.printInfo();
message.setConsumed(true);
api.inAppConsume(message, source, clickLocation);
api.inAppConsume(message, source, clickLocation, successHandler, failureHandler);
notifyOnChange();
}

Expand Down Expand Up @@ -432,7 +455,7 @@ private boolean canShowInAppAfterPrevious() {

private void handleIterableCustomAction(String actionName, IterableInAppMessage message) {
if (IterableConstants.ITERABLE_IN_APP_ACTION_DELETE.equals(actionName)) {
removeMessage(message, IterableInAppDeleteActionType.DELETE_BUTTON, IterableInAppLocation.IN_APP);
removeMessage(message, IterableInAppDeleteActionType.DELETE_BUTTON, IterableInAppLocation.IN_APP, null, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public IterableNotificationBuilder createNotification(Context context, Bundle ex
trampolineActivityIntent.setClass(context, IterableTrampolineActivity.class);
trampolineActivityIntent.putExtras(extras);
trampolineActivityIntent.putExtra(IterableConstants.ITERABLE_DATA_ACTION_IDENTIFIER, IterableConstants.ITERABLE_ACTION_DEFAULT);
trampolineActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
trampolineActivityIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

// Action buttons
if (notificationData.getActionButtons() != null) {
Expand Down
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