Skip to content

Commit 952e208

Browse files
author
“Akshay
committed
Merge branch 'feature/embedded/manager' into Encryption-With-Embedded-Manager
# Conflicts: # iterableapi/src/main/java/com/iterable/iterableapi/IterableConfig.java
2 parents be29cfd + 061a063 commit 952e208

14 files changed

+1006
-1
lines changed

iterableapi/build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,13 @@ dependencies {
5050
testImplementation 'androidx.test.ext:junit:1.1.2'
5151
testImplementation 'androidx.test:rules:1.3.0'
5252
testImplementation 'org.mockito:mockito-core:3.3.3'
53+
testImplementation 'org.mockito:mockito-inline:2.8.47'
5354
testImplementation 'org.robolectric:robolectric:4.4'
5455
testImplementation 'org.robolectric:shadows-playservices:4.4'
5556
testImplementation 'org.khronos:opengl-api:gl1.1-android-2.1_r1'
5657
testImplementation 'com.squareup.okhttp3:mockwebserver:4.2.2'
5758
testImplementation 'org.skyscreamer:jsonassert:1.5.0'
59+
testImplementation project(path: ':iterableapi')
5860
androidTestImplementation 'androidx.test:runner:1.3.0'
5961
androidTestImplementation 'androidx.test:rules:1.3.0'
6062
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
@@ -96,6 +98,8 @@ task javadoc(type: Javadoc) {
9698
source = android.sourceSets.main.java.srcDirs
9799
excludes = ['**/*.kt']
98100
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
101+
102+
exclude '**/*.kt'
99103
}
100104

101105
tasks.withType(Test) {

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

+31
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class IterableApi {
4242

4343
IterableApiClient apiClient = new IterableApiClient(new IterableApiAuthProvider());
4444
private @Nullable IterableInAppManager inAppManager;
45+
private @Nullable IterableEmbeddedManager embeddedManager;
4546
private String inboxSessionId;
4647
private IterableAuthManager authManager;
4748
private HashMap<String, String> deviceAttributes = new HashMap<>();
@@ -517,6 +518,10 @@ public static void initialize(@NonNull Context context, @NonNull String apiKey,
517518
sharedInstance.config.useInMemoryStorageForInApps);
518519
}
519520

521+
if (sharedInstance.embeddedManager == null) {
522+
sharedInstance.embeddedManager = new IterableEmbeddedManager(sharedInstance.config.embeddedMessagingAutoFetchInterval, null, null);
523+
}
524+
520525
loadLastSavedConfiguration(context);
521526
IterablePushNotificationUtil.processPendingAction(context);
522527
}
@@ -535,12 +540,20 @@ public static void setContext(Context context) {
535540
this.inAppManager = inAppManager;
536541
}
537542

543+
@VisibleForTesting
544+
IterableApi(IterableInAppManager inAppManager, IterableEmbeddedManager embeddedManager) {
545+
config = new IterableConfig.Builder().build();
546+
this.inAppManager = inAppManager;
547+
this.embeddedManager = embeddedManager;
548+
}
549+
538550
@VisibleForTesting
539551
IterableApi(IterableApiClient apiClient, IterableInAppManager inAppManager) {
540552
config = new IterableConfig.Builder().build();
541553
this.apiClient = apiClient;
542554
this.inAppManager = inAppManager;
543555
}
556+
544557
//endregion
545558

546559
//region SDK public functions
@@ -558,6 +571,24 @@ public IterableInAppManager getInAppManager() {
558571
return inAppManager;
559572
}
560573

574+
@NonNull
575+
public IterableEmbeddedManager getEmbeddedManager() {
576+
if (embeddedManager == null) {
577+
throw new RuntimeException("IterableApi must be initialized before calling getFlexManager(). " +
578+
"Make sure you call IterableApi#initialize() in Application#onCreate");
579+
}
580+
return embeddedManager;
581+
}
582+
583+
@NonNull
584+
public IterableEmbeddedManager embeddedManager() {
585+
if (embeddedManager == null) {
586+
throw new RuntimeException("IterableApi must be initialized before calling getFlexManager(). " +
587+
"Make sure you call IterableApi#initialize() in Application#onCreate");
588+
}
589+
return embeddedManager;
590+
}
591+
561592
/**
562593
* Returns the attribution information ({@link IterableAttributionInfo}) for last push open
563594
* or app link click from an email.

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

+19
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,25 @@ public void getInAppMessages(int count, @NonNull IterableHelper.IterableActionHa
215215
}
216216
}
217217

218+
void getEmbeddedMessages(@NonNull IterableHelper.IterableActionHandler onCallback) {
219+
JSONObject requestJSON = new JSONObject();
220+
addEmailOrUserIdToJson(requestJSON);
221+
try {
222+
addEmailOrUserIdToJson(requestJSON);
223+
requestJSON.put(IterableConstants.KEY_PLATFORM, IterableConstants.ITBL_PLATFORM_ANDROID);
224+
requestJSON.put(IterableConstants.ITBL_KEY_SDK_VERSION, IterableConstants.ITBL_KEY_SDK_VERSION_NUMBER);
225+
requestJSON.put(IterableConstants.ITBL_SYSTEM_VERSION, Build.VERSION.RELEASE);
226+
requestJSON.put(IterableConstants.KEY_PACKAGE_NAME, authProvider.getContext().getPackageName());
227+
//TODO: This will have to be replaced by either userID or email based on what the user is using
228+
requestJSON.put("userKey", IterableApi.getInstance().getEmail());
229+
requestJSON.put("placementId", "0");
230+
231+
sendGetRequest(IterableConstants.ENDPOINT_GET_EMBEDDED_MESSAGES, requestJSON, onCallback);
232+
} catch (JSONException e) {
233+
e.printStackTrace();
234+
}
235+
}
236+
218237
public void trackInAppOpen(@NonNull String messageId) {
219238
JSONObject requestJSON = new JSONObject();
220239

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

+18
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ public class IterableConfig {
7979

8080
final boolean encryptionEnforced;
8181

82+
/**
83+
* The number of seconds to wait before fetching the next embedded message
84+
*/
85+
final double embeddedMessagingAutoFetchInterval;
86+
8287
private IterableConfig(Builder builder) {
8388
pushIntegrationName = builder.pushIntegrationName;
8489
urlHandler = builder.urlHandler;
@@ -93,6 +98,7 @@ private IterableConfig(Builder builder) {
9398
allowedProtocols = builder.allowedProtocols;
9499
useInMemoryStorageForInApps = builder.useInMemoryStorageForInApps;
95100
encryptionEnforced = builder.encryptionEnforced;
101+
embeddedMessagingAutoFetchInterval = builder.embeddedMessagingAutoFetchInterval;
96102
}
97103

98104
public static class Builder {
@@ -110,6 +116,7 @@ public static class Builder {
110116
private boolean useInMemoryStorageForInApps = false;
111117
private boolean encryptionEnforced = false;
112118

119+
private double embeddedMessagingAutoFetchInterval = 30.0;
113120
public Builder() {}
114121

115122
/**
@@ -246,6 +253,17 @@ public Builder setUseInMemoryStorageForInApps(boolean useInMemoryStorageForInApp
246253
return this;
247254
}
248255

256+
/**
257+
* Set the embedded message auto fetch interval: the number of seconds to wait before fetching
258+
* the next embedded message
259+
* @param embeddedMessagingAutoFetchInterval display interval in seconds
260+
*/
261+
@NonNull
262+
public Builder setEmbeddedMessagingAutoFetchInterval(double embeddedMessagingAutoFetchInterval) {
263+
this.embeddedMessagingAutoFetchInterval = embeddedMessagingAutoFetchInterval;
264+
return this;
265+
}
266+
249267
@NonNull
250268
public IterableConfig build() {
251269
return new IterableConfig(this);

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

+25
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public final class IterableConstants {
7474
public static final String ENDPOINT_UPDATE_USER_SUBS = "users/updateSubscriptions";
7575
public static final String ENDPOINT_TRACK_INAPP_CLOSE = "events/trackInAppClose";
7676
public static final String ENDPOINT_GET_REMOTE_CONFIGURATION = "mobile/getRemoteConfiguration";
77+
public static final String ENDPOINT_GET_EMBEDDED_MESSAGES = "flex/messages";
7778

7879
public static final String PUSH_APP_ID = "IterableAppId";
7980
public static final String PUSH_GCM_PROJECT_NUMBER = "GCMProjectNumber";
@@ -165,6 +166,30 @@ public final class IterableConstants {
165166
public static final String PICASSO_CLASS = "com.squareup.picasso.Picasso";
166167
public static final String LOCATION_HEADER_FIELD = "Location";
167168

169+
//Embedded Message Constants
170+
public static final String ITERABLE_EMBEDDED_MESSAGE = "embeddedMessages";
171+
public static final String ITERABLE_EMBEDDED_MESSAGE_METADATA = "metadata";
172+
public static final String ITERABLE_EMBEDDED_MESSAGE_ELEMENTS = "elements";
173+
public static final String ITERABLE_EMBEDDED_MESSAGE_PAYLOAD = "payload";
174+
public static final String ITERABLE_EMBEDDED_MESSAGE_ID = "id";
175+
public static final String ITERABLE_EMBEDDED_MESSAGE_PLACEMENT_ID = "placementId";
176+
public static final String ITERABLE_EMBEDDED_MESSAGE_CAMPAIGN_ID = "campaignId";
177+
public static final String ITERABLE_EMBEDDED_MESSAGE_IS_PROOF = "isProof";
178+
public static final String ITERABLE_EMBEDDED_MESSAGE_TITLE = "title";
179+
public static final String ITERABLE_EMBEDDED_MESSAGE_BODY = "body";
180+
public static final String ITERABLE_EMBEDDED_MESSAGE_MEDIA_URL = "mediaUrl";
181+
public static final String ITERABLE_EMBEDDED_MESSAGE_DEFAULT_ACTION = "defaultAction";
182+
public static final String ITERABLE_EMBEDDED_MESSAGE_BUTTONS = "buttons";
183+
public static final String ITERABLE_EMBEDDED_MESSAGE_TEXT = "text";
184+
public static final String ITERABLE_EMBEDDED_MESSAGE_DEFAULT_ACTION_TYPE = "type";
185+
public static final String ITERABLE_EMBEDDED_MESSAGE_DEFAULT_ACTION_DATA = "data";
186+
public static final String ITERABLE_EMBEDDED_MESSAGE_BUTTON_ID = "id";
187+
public static final String ITERABLE_EMBEDDED_MESSAGE_BUTTON_TITLE = "title";
188+
public static final String ITERABLE_EMBEDDED_MESSAGE_BUTTON_ACTION = "action";
189+
public static final String ITERABLE_EMBEDDED_MESSAGE_TEXT_ID = "id";
190+
public static final String ITERABLE_EMBEDDED_MESSAGE_TEXT_TEXT = "text";
191+
public static final String ITERABLE_EMBEDDED_MESSAGE_TEXT_LABEL = "label";
192+
168193
//In-App Constants
169194
public static final String ITERABLE_IN_APP_BGCOLOR_ALPHA = "alpha";
170195
public static final String ITERABLE_IN_APP_BGCOLOR_HEX = "hex";

0 commit comments

Comments
 (0)