cordova-plugin-insider 3.0.2 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugin.xml +6 -2
- package/src/android/CDVUtils.java +279 -44
- package/src/android/Constants.java +2 -0
- package/src/android/InsiderPlugin.java +150 -238
- package/src/android/build-extras.gradle +1 -1
- package/src/ios/CDVUtils.h +14 -0
- package/src/ios/CDVUtils.m +228 -0
- package/src/ios/InsiderPlugin.m +88 -20
- package/types/Product.d.ts +10 -0
- package/www/CallbackType.js +0 -11
- package/www/Constants.js +0 -114
- package/www/ContentOptimizerDataType.js +0 -6
- package/www/Event.js +0 -190
- package/www/Gender.js +0 -7
- package/www/Identifier.js +0 -96
- package/www/InsiderPlugin.js +0 -742
- package/www/Product.js +0 -507
- package/www/User.js +0 -482
- package/www/Utils.js +0 -39
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version='1.0' encoding='utf-8'?>
|
|
2
|
-
<plugin id="cordova-plugin-insider" version="3.0
|
|
2
|
+
<plugin id="cordova-plugin-insider" version="3.1.0" xmlns="http://apache.org/cordova/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android">
|
|
3
3
|
<name>Insider</name>
|
|
4
4
|
<description>Insider Cordova Plugin</description>
|
|
5
5
|
<keywords>insider,cordova,cordova-ios,cordova-android</keywords>
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
</js-module>
|
|
11
11
|
|
|
12
12
|
<js-module name="CallbackType" src="www/CallbackType.js"/>
|
|
13
|
+
<js-module name="CloseButtonPosition" src="www/CloseButtonPosition.js"/>
|
|
13
14
|
<js-module name="ContentOptimizerDataType" src="www/ContentOptimizerDataType.js" />
|
|
14
15
|
<js-module name="Gender" src="www/Gender.js" />
|
|
15
16
|
<js-module name="Identifier" src="www/Identifier.js"/>
|
|
@@ -70,7 +71,7 @@
|
|
|
70
71
|
<source url="https://cdn.cocoapods.org/" />
|
|
71
72
|
</config>
|
|
72
73
|
<pods use-frameworks="true">
|
|
73
|
-
<pod name="InsiderMobile" spec="14.2.
|
|
74
|
+
<pod name="InsiderMobile" spec="14.2.3" />
|
|
74
75
|
<pod name="InsiderGeofence" spec="1.2.4" />
|
|
75
76
|
<pod name="InsiderHybrid" spec="1.7.6" />
|
|
76
77
|
</pods>
|
|
@@ -85,6 +86,9 @@
|
|
|
85
86
|
<source-file src="src/ios/InsiderPlugin.m" />
|
|
86
87
|
<header-file src="src/ios/InsiderPlugin.h" />
|
|
87
88
|
|
|
89
|
+
<source-file src="src/ios/CDVUtils.m" />
|
|
90
|
+
<header-file src="src/ios/CDVUtils.h" />
|
|
91
|
+
|
|
88
92
|
<source-file src="src/ios/IDFAHelper.m" />
|
|
89
93
|
<header-file src="src/ios/IDFAHelper.h" />
|
|
90
94
|
</platform>
|
|
@@ -1,22 +1,18 @@
|
|
|
1
1
|
package com.useinsider.cordova;
|
|
2
2
|
|
|
3
|
-
import com.fasterxml.jackson.core.type.TypeReference;
|
|
4
3
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
5
4
|
import com.useinsider.insider.Insider;
|
|
6
5
|
import com.useinsider.insider.InsiderProduct;
|
|
6
|
+
import com.useinsider.insider.InsiderEvent;
|
|
7
|
+
import com.useinsider.insiderhybrid.InsiderHybridUtils;
|
|
7
8
|
|
|
8
9
|
import org.json.JSONArray;
|
|
9
10
|
import org.json.JSONException;
|
|
10
11
|
import org.json.JSONObject;
|
|
11
12
|
|
|
12
|
-
import java.lang.reflect.Array;
|
|
13
|
-
import java.lang.reflect.Type;
|
|
14
|
-
import java.text.DateFormat;
|
|
15
|
-
import java.text.SimpleDateFormat;
|
|
16
13
|
import java.util.ArrayList;
|
|
17
14
|
import java.util.Date;
|
|
18
15
|
import java.util.HashMap;
|
|
19
|
-
import java.util.Iterator;
|
|
20
16
|
import java.util.Map;
|
|
21
17
|
|
|
22
18
|
public class CDVUtils {
|
|
@@ -58,63 +54,302 @@ public class CDVUtils {
|
|
|
58
54
|
return listdata;
|
|
59
55
|
}
|
|
60
56
|
|
|
61
|
-
public static
|
|
62
|
-
HashMap map = new HashMap();
|
|
63
|
-
|
|
57
|
+
public static InsiderEvent parseEvent(String eventName, JSONArray parameters) {
|
|
64
58
|
try {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
59
|
+
InsiderEvent event = Insider.Instance.tagEvent(eventName);
|
|
60
|
+
|
|
61
|
+
if (parameters != null) {
|
|
62
|
+
for (int i = 0; i < parameters.length(); i++) {
|
|
63
|
+
JSONObject parameter = parameters.getJSONObject(i);
|
|
64
|
+
if (parameter == null) continue;
|
|
65
|
+
|
|
66
|
+
String type = parameter.getString("type");
|
|
67
|
+
String key = parameter.getString("key");
|
|
68
|
+
if (type == null || key == null) continue;
|
|
69
|
+
|
|
70
|
+
switch (type) {
|
|
71
|
+
case "string":
|
|
72
|
+
event.addParameterWithString(key, parameter.getString("value"));
|
|
73
|
+
break;
|
|
74
|
+
case "integer":
|
|
75
|
+
event.addParameterWithInt(key, parameter.getInt("value"));
|
|
76
|
+
break;
|
|
77
|
+
case "double":
|
|
78
|
+
event.addParameterWithDouble(key, parameter.getDouble("value"));
|
|
79
|
+
break;
|
|
80
|
+
case "boolean":
|
|
81
|
+
event.addParameterWithBoolean(key, parameter.getBoolean("value"));
|
|
82
|
+
break;
|
|
83
|
+
case "date":
|
|
84
|
+
// value is epoch milliseconds as string
|
|
85
|
+
long epochValue = Long.parseLong(parameter.getString("value"));
|
|
86
|
+
Date dateValue = new Date(epochValue);
|
|
87
|
+
event.addParameterWithDate(key, dateValue);
|
|
88
|
+
break;
|
|
89
|
+
case "strings":
|
|
90
|
+
JSONArray stringsArray = parameter.getJSONArray("value");
|
|
91
|
+
String[] stringsValue = convertJSONArrayToStringArray(stringsArray);
|
|
92
|
+
event.addParameterWithStringArray(key, stringsValue);
|
|
93
|
+
break;
|
|
94
|
+
case "numbers":
|
|
95
|
+
JSONArray numbersArray = parameter.getJSONArray("value");
|
|
96
|
+
Number[] numbersValue = convertJSONArrayToNumericArray(numbersArray);
|
|
97
|
+
event.addParameterWithNumericArray(key, numbersValue);
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
83
100
|
}
|
|
84
101
|
}
|
|
102
|
+
|
|
103
|
+
return event;
|
|
85
104
|
} catch (Exception e) {
|
|
86
105
|
Insider.Instance.putException(e);
|
|
87
106
|
}
|
|
88
107
|
|
|
89
|
-
return
|
|
108
|
+
return null;
|
|
90
109
|
}
|
|
91
110
|
|
|
92
|
-
|
|
93
|
-
|
|
111
|
+
private static String[] convertJSONArrayToStringArray(JSONArray jsonArray){
|
|
112
|
+
try {
|
|
113
|
+
String[] result = new String[jsonArray.length()];
|
|
114
|
+
|
|
115
|
+
for (int i = 0; i < jsonArray.length(); i++) {
|
|
116
|
+
result[i] = jsonArray.getString(i);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return result;
|
|
120
|
+
} catch (Exception e) {
|
|
121
|
+
Insider.Instance.putException(e);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
94
126
|
|
|
127
|
+
private static Number[] convertJSONArrayToNumericArray(JSONArray jsonArray) {
|
|
95
128
|
try {
|
|
129
|
+
Number[] result = new Number[jsonArray.length()];
|
|
130
|
+
|
|
96
131
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
97
132
|
Object value = jsonArray.get(i);
|
|
98
|
-
if (value instanceof
|
|
99
|
-
|
|
100
|
-
} else if (value instanceof JSONArray) {
|
|
101
|
-
array.add(convertJSONArrayToArray((JSONArray) value));
|
|
102
|
-
} else if (value instanceof Boolean) {
|
|
103
|
-
array.add((Boolean) value);
|
|
104
|
-
} else if (value instanceof Integer) {
|
|
105
|
-
array.add((Integer) value);
|
|
106
|
-
} else if (value instanceof Double) {
|
|
107
|
-
array.add((Double) value);
|
|
133
|
+
if (value instanceof Number) {
|
|
134
|
+
result[i] = (Number) value;
|
|
108
135
|
} else if (value instanceof String) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
136
|
+
try {
|
|
137
|
+
result[i] = Double.parseDouble((String) value);
|
|
138
|
+
} catch (NumberFormatException e) {
|
|
139
|
+
result[i] = 0;
|
|
140
|
+
}
|
|
112
141
|
}
|
|
113
142
|
}
|
|
143
|
+
|
|
144
|
+
return result;
|
|
114
145
|
} catch (Exception e) {
|
|
115
146
|
Insider.Instance.putException(e);
|
|
116
147
|
}
|
|
117
148
|
|
|
118
|
-
return
|
|
149
|
+
return null;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
public static InsiderProduct parseProduct(Map<String, Object> requiredFields, Map<String, Object> optionalFields, JSONArray customParameters) {
|
|
153
|
+
try {
|
|
154
|
+
if (!isProductValid(requiredFields)) return null;
|
|
155
|
+
|
|
156
|
+
String[] taxonomy;
|
|
157
|
+
Object taxObject = requiredFields.get(Constants.TAXONOMY);
|
|
158
|
+
|
|
159
|
+
if (taxObject.getClass().isArray()) {
|
|
160
|
+
taxonomy = (String[]) taxObject;
|
|
161
|
+
} else {
|
|
162
|
+
taxonomy = ((ArrayList<String>) taxObject).toArray(new String[0]);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
double price = 0;
|
|
166
|
+
if (requiredFields.get(Constants.UNIT_PRICE) instanceof Integer) {
|
|
167
|
+
price = Integer.valueOf((Integer) requiredFields.get(Constants.UNIT_PRICE)).doubleValue();
|
|
168
|
+
} else {
|
|
169
|
+
price = (double) requiredFields.get(Constants.UNIT_PRICE);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
InsiderProduct product = Insider.Instance.createNewProduct(
|
|
173
|
+
(String) requiredFields.get(Constants.PRODUCT_ID),
|
|
174
|
+
(String) requiredFields.get(Constants.NAME),
|
|
175
|
+
taxonomy,
|
|
176
|
+
(String) requiredFields.get(Constants.IMAGE_URL),
|
|
177
|
+
price,
|
|
178
|
+
(String) requiredFields.get(Constants.CURRENCY)
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
// Apply optional fields
|
|
182
|
+
if (optionalFields != null && optionalFields.size() > 0) {
|
|
183
|
+
Map<String, Object> validatedMap = InsiderHybridUtils.validateMap(optionalFields);
|
|
184
|
+
|
|
185
|
+
for (Map.Entry<String, Object> entry : validatedMap.entrySet()) {
|
|
186
|
+
Object value = entry.getValue();
|
|
187
|
+
switch (entry.getKey()) {
|
|
188
|
+
case Constants.SALE_PRICE:
|
|
189
|
+
product.setSalePrice((double) value);
|
|
190
|
+
break;
|
|
191
|
+
case Constants.STOCK:
|
|
192
|
+
product.setStock(((int) value));
|
|
193
|
+
break;
|
|
194
|
+
case Constants.COLOR:
|
|
195
|
+
product.setColor((String) value);
|
|
196
|
+
break;
|
|
197
|
+
case Constants.SIZE:
|
|
198
|
+
product.setSize((String) value);
|
|
199
|
+
break;
|
|
200
|
+
case Constants.QUANTITY:
|
|
201
|
+
product.setQuantity(((int) value));
|
|
202
|
+
break;
|
|
203
|
+
case Constants.SHIPPING_COST:
|
|
204
|
+
product.setShippingCost((double) value);
|
|
205
|
+
break;
|
|
206
|
+
case Constants.VOUCHER_NAME:
|
|
207
|
+
product.setVoucherName((String) value);
|
|
208
|
+
break;
|
|
209
|
+
case Constants.VOUCHER_DISCOUNT:
|
|
210
|
+
product.setVoucherDiscount((double) value);
|
|
211
|
+
break;
|
|
212
|
+
case Constants.PROMOTION_NAME:
|
|
213
|
+
product.setPromotionName((String) value);
|
|
214
|
+
break;
|
|
215
|
+
case Constants.PROMOTION_DISCOUNT:
|
|
216
|
+
product.setPromotionDiscount((double) value);
|
|
217
|
+
break;
|
|
218
|
+
case Constants.GROUP_CODE:
|
|
219
|
+
product.setGroupCode((String) value);
|
|
220
|
+
break;
|
|
221
|
+
case Constants.BRAND:
|
|
222
|
+
product.setBrand((String) value);
|
|
223
|
+
break;
|
|
224
|
+
case Constants.SKU:
|
|
225
|
+
product.setSku((String) value);
|
|
226
|
+
break;
|
|
227
|
+
case Constants.PRODUCT_GENDER:
|
|
228
|
+
product.setGender((String) value);
|
|
229
|
+
break;
|
|
230
|
+
case Constants.MULTIPACK:
|
|
231
|
+
product.setMultipack((String) value);
|
|
232
|
+
break;
|
|
233
|
+
case Constants.PRODUCT_TYPE:
|
|
234
|
+
product.setProductType((String) value);
|
|
235
|
+
break;
|
|
236
|
+
case Constants.GTIN:
|
|
237
|
+
product.setGtin((String) value);
|
|
238
|
+
break;
|
|
239
|
+
case Constants.DESCRIPTION:
|
|
240
|
+
product.setDescription((String) value);
|
|
241
|
+
break;
|
|
242
|
+
case Constants.TAGS:
|
|
243
|
+
String[] tags;
|
|
244
|
+
if (value.getClass().isArray()) {
|
|
245
|
+
tags = (String[]) value;
|
|
246
|
+
} else {
|
|
247
|
+
tags = ((ArrayList<String>) value).toArray(new String[0]);
|
|
248
|
+
}
|
|
249
|
+
product.setTags(tags);
|
|
250
|
+
break;
|
|
251
|
+
case Constants.IS_IN_STOCK:
|
|
252
|
+
product.setInStock((boolean) value);
|
|
253
|
+
break;
|
|
254
|
+
case Constants.PRODUCT_URL:
|
|
255
|
+
product.setProductURL((String) value);
|
|
256
|
+
break;
|
|
257
|
+
default:
|
|
258
|
+
setProductCustomAttribute(product, entry.getKey(), value);
|
|
259
|
+
break;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Apply custom parameters
|
|
265
|
+
if (customParameters != null && customParameters.length() > 0) {
|
|
266
|
+
for (int i = 0; i < customParameters.length(); i++) {
|
|
267
|
+
JSONObject param = customParameters.getJSONObject(i);
|
|
268
|
+
if (param == null) continue;
|
|
269
|
+
|
|
270
|
+
String type = param.getString("type");
|
|
271
|
+
String key = param.getString("key");
|
|
272
|
+
if (type == null || key == null) continue;
|
|
273
|
+
|
|
274
|
+
switch (type) {
|
|
275
|
+
case "string":
|
|
276
|
+
product.setCustomAttributeWithString(key, param.getString("value"));
|
|
277
|
+
break;
|
|
278
|
+
case "integer":
|
|
279
|
+
product.setCustomAttributeWithInt(key, param.getInt("value"));
|
|
280
|
+
break;
|
|
281
|
+
case "double":
|
|
282
|
+
product.setCustomAttributeWithDouble(key, param.getDouble("value"));
|
|
283
|
+
break;
|
|
284
|
+
case "boolean":
|
|
285
|
+
product.setCustomAttributeWithBoolean(key, param.getBoolean("value"));
|
|
286
|
+
break;
|
|
287
|
+
case "date":
|
|
288
|
+
// value is epoch milliseconds as string
|
|
289
|
+
long epochValue = Long.parseLong(param.getString("value"));
|
|
290
|
+
Date dateValue = new Date(epochValue);
|
|
291
|
+
product.setCustomAttributeWithDate(key, dateValue);
|
|
292
|
+
break;
|
|
293
|
+
case "strings":
|
|
294
|
+
JSONArray stringsArray = param.getJSONArray("value");
|
|
295
|
+
String[] stringsValue = convertJSONArrayToStringArray(stringsArray);
|
|
296
|
+
product.setCustomAttributeWithStringArray(key, stringsValue);
|
|
297
|
+
break;
|
|
298
|
+
case "numbers":
|
|
299
|
+
JSONArray numbersArray = param.getJSONArray("value");
|
|
300
|
+
Number[] numbersValue = convertJSONArrayToNumericArray(numbersArray);
|
|
301
|
+
product.setCustomAttributeWithNumericArray(key, numbersValue);
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return product;
|
|
308
|
+
} catch (Exception e) {
|
|
309
|
+
Insider.Instance.putException(e);
|
|
310
|
+
}
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
private static boolean isProductValid(Map<String, Object> requiredFields) {
|
|
315
|
+
return requiredFields.containsKey(Constants.PRODUCT_ID)
|
|
316
|
+
&& requiredFields.containsKey(Constants.NAME)
|
|
317
|
+
&& requiredFields.containsKey(Constants.TAXONOMY)
|
|
318
|
+
&& requiredFields.containsKey(Constants.IMAGE_URL)
|
|
319
|
+
&& requiredFields.containsKey(Constants.UNIT_PRICE)
|
|
320
|
+
&& requiredFields.containsKey(Constants.CURRENCY);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
private static void setProductCustomAttribute(InsiderProduct product, String key, Object value) {
|
|
324
|
+
try {
|
|
325
|
+
if (key == null || key.length() == 0 || value == null) return;
|
|
326
|
+
switch (value.getClass().getSimpleName()) {
|
|
327
|
+
case "String":
|
|
328
|
+
product.setCustomAttributeWithString(key, (String) value);
|
|
329
|
+
break;
|
|
330
|
+
case "Double":
|
|
331
|
+
product.setCustomAttributeWithDouble(key, (double) value);
|
|
332
|
+
break;
|
|
333
|
+
case "Integer":
|
|
334
|
+
product.setCustomAttributeWithInt(key, (int) value);
|
|
335
|
+
break;
|
|
336
|
+
case "Boolean":
|
|
337
|
+
product.setCustomAttributeWithBoolean(key, (boolean) value);
|
|
338
|
+
break;
|
|
339
|
+
case "Date":
|
|
340
|
+
product.setCustomAttributeWithDate(key, (Date) value);
|
|
341
|
+
break;
|
|
342
|
+
case "String[]":
|
|
343
|
+
product.setCustomAttributeWithStringArray(key, (String[]) value);
|
|
344
|
+
break;
|
|
345
|
+
case "Number[]":
|
|
346
|
+
product.setCustomAttributeWithNumericArray(key, (Number[]) value);
|
|
347
|
+
break;
|
|
348
|
+
default:
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
} catch (Exception e) {
|
|
352
|
+
Insider.Instance.putException(e);
|
|
353
|
+
}
|
|
119
354
|
}
|
|
120
355
|
}
|
|
@@ -6,6 +6,7 @@ class Constants {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
static final String HANDLE_NOTIFICATION = "handleNotification";
|
|
9
|
+
static final String SET_INTERNAL_BROWSER_CLOSE_BUTTON_POSITION = "setInternalBrowserCloseButtonPosition";
|
|
9
10
|
static final String ERROR = "error";
|
|
10
11
|
static final String DEFAULT_VALUE = "defaultValue";
|
|
11
12
|
static final String VARIABLE_NAME = "variableName";
|
|
@@ -48,4 +49,5 @@ class Constants {
|
|
|
48
49
|
static final String DESCRIPTION = "desc";
|
|
49
50
|
static final String TAGS = "tags";
|
|
50
51
|
static final String IS_IN_STOCK = "iis";
|
|
52
|
+
static final String PRODUCT_URL = "product_url";
|
|
51
53
|
}
|