cordova-plugin-reteno 1.0.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.
Files changed (60) hide show
  1. package/.editorconfig +17 -0
  2. package/.travis.yml +108 -0
  3. package/CODE_OF_CONDUCT.md +133 -0
  4. package/CONTRIBUTING.md +114 -0
  5. package/LICENSE +20 -0
  6. package/docs/android.md +34 -0
  7. package/docs/api.md +8 -0
  8. package/docs/ios.md +62 -0
  9. package/package.json +41 -0
  10. package/plugin.xml +69 -0
  11. package/src/android/.idea/.name +1 -0
  12. package/src/android/.idea/compiler.xml +6 -0
  13. package/src/android/.idea/gradle.xml +20 -0
  14. package/src/android/.idea/misc.xml +10 -0
  15. package/src/android/.idea/vcs.xml +6 -0
  16. package/src/android/app/build.gradle +40 -0
  17. package/src/android/app/proguard-rules.pro +21 -0
  18. package/src/android/app/src/androidTest/java/com/reteno/plugin/ExampleInstrumentedTest.java +26 -0
  19. package/src/android/app/src/main/AndroidManifest.xml +20 -0
  20. package/src/android/app/src/main/java/com/reteno/plugin/CordovaRetenoApplication.java +7 -0
  21. package/src/android/app/src/main/java/com/reteno/plugin/RetenoEvent.java +74 -0
  22. package/src/android/app/src/main/java/com/reteno/plugin/RetenoPlugin.java +162 -0
  23. package/src/android/app/src/main/java/com/reteno/plugin/RetenoPushReceiver.java +14 -0
  24. package/src/android/app/src/main/java/com/reteno/plugin/RetenoUserAttributes.java +176 -0
  25. package/src/android/app/src/main/java/com/reteno/plugin/RetenoUtil.java +12 -0
  26. package/src/android/app/src/main/res/drawable/ic_launcher_background.xml +170 -0
  27. package/src/android/app/src/main/res/drawable-v24/ic_launcher_foreground.xml +30 -0
  28. package/src/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml +6 -0
  29. package/src/android/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml +6 -0
  30. package/src/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp +0 -0
  31. package/src/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp +0 -0
  32. package/src/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp +0 -0
  33. package/src/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp +0 -0
  34. package/src/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp +0 -0
  35. package/src/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp +0 -0
  36. package/src/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp +0 -0
  37. package/src/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp +0 -0
  38. package/src/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp +0 -0
  39. package/src/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp +0 -0
  40. package/src/android/app/src/main/res/values/colors.xml +10 -0
  41. package/src/android/app/src/main/res/values/strings.xml +3 -0
  42. package/src/android/app/src/main/res/values/themes.xml +16 -0
  43. package/src/android/app/src/main/res/values-night/themes.xml +16 -0
  44. package/src/android/app/src/main/res/xml/backup_rules.xml +13 -0
  45. package/src/android/app/src/main/res/xml/data_extraction_rules.xml +19 -0
  46. package/src/android/build.gradle +5 -0
  47. package/src/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  48. package/src/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  49. package/src/android/gradle.properties +22 -0
  50. package/src/android/gradlew +185 -0
  51. package/src/android/gradlew.bat +89 -0
  52. package/src/android/reteno.gradle +13 -0
  53. package/src/android/settings.gradle +16 -0
  54. package/src/ios/RetenoEvent.swift +67 -0
  55. package/src/ios/RetenoPlugin-Bridging-Header.h +1 -0
  56. package/src/ios/RetenoPlugin.swift +221 -0
  57. package/src/ios/RetenoUserAttributes.swift +150 -0
  58. package/src/ios/RetenoUtils.swift +12 -0
  59. package/types/index.d.ts +98 -0
  60. package/www/cordova-plugin-reteno.js +54 -0
@@ -0,0 +1,40 @@
1
+ apply plugin: 'com.android.application'
2
+
3
+ android {
4
+ namespace 'com.reteno.plugin'
5
+ compileSdk 33
6
+ //buildToolsVersion '30.0.3'
7
+
8
+ defaultConfig {
9
+ applicationId "com.reteno.plugin"
10
+ minSdk 26
11
+ targetSdk 33
12
+ versionCode 1
13
+ versionName "1.0"
14
+
15
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
16
+ }
17
+
18
+ buildTypes {
19
+ release {
20
+ minifyEnabled false
21
+ proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22
+ }
23
+ }
24
+ compileOptions {
25
+ sourceCompatibility JavaVersion.VERSION_1_8
26
+ targetCompatibility JavaVersion.VERSION_1_8
27
+ }
28
+ }
29
+
30
+ dependencies {
31
+ implementation 'androidx.appcompat:appcompat:1.6.1'
32
+ implementation 'com.google.android.material:material:1.5.0'
33
+ implementation "com.reteno:fcm:1.6.4"
34
+ implementation "com.google.firebase:firebase-messaging:23.1.0"
35
+ implementation "com.google.firebase:firebase-messaging-ktx:23.1.0"
36
+ implementation "org.apache.cordova:framework:10.1.2"
37
+ testImplementation 'junit:junit:4.13.2'
38
+ androidTestImplementation 'androidx.test.ext:junit:1.1.3'
39
+ androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
40
+ }
@@ -0,0 +1,21 @@
1
+ # Add project specific ProGuard rules here.
2
+ # You can control the set of applied configuration files using the
3
+ # proguardFiles setting in build.gradle.
4
+ #
5
+ # For more details, see
6
+ # http://developer.android.com/guide/developing/tools/proguard.html
7
+
8
+ # If your project uses WebView with JS, uncomment the following
9
+ # and specify the fully qualified class name to the JavaScript interface
10
+ # class:
11
+ #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12
+ # public *;
13
+ #}
14
+
15
+ # Uncomment this to preserve the line number information for
16
+ # debugging stack traces.
17
+ #-keepattributes SourceFile,LineNumberTable
18
+
19
+ # If you keep the line number information, uncomment this to
20
+ # hide the original source file name.
21
+ #-renamesourcefileattribute SourceFile
@@ -0,0 +1,26 @@
1
+ package com.reteno.plugin;
2
+
3
+ import android.content.Context;
4
+
5
+ import androidx.test.platform.app.InstrumentationRegistry;
6
+ import androidx.test.ext.junit.runners.AndroidJUnit4;
7
+
8
+ import org.junit.Test;
9
+ import org.junit.runner.RunWith;
10
+
11
+ import static org.junit.Assert.*;
12
+
13
+ /**
14
+ * Instrumented test, which will execute on an Android device.
15
+ *
16
+ * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17
+ */
18
+ @RunWith(AndroidJUnit4.class)
19
+ public class ExampleInstrumentedTest {
20
+ @Test
21
+ public void useAppContext() {
22
+ // Context of the app under test.
23
+ Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24
+ assertEquals("com.reteno.plugin", appContext.getPackageName());
25
+ }
26
+ }
@@ -0,0 +1,20 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
+ xmlns:tools="http://schemas.android.com/tools"
4
+ package="com.reteno.plugin">
5
+
6
+ <application>
7
+ <receiver
8
+ android:name="com.reteno.plugin.RetenoPushReceiver"
9
+ android:enabled="true"
10
+ android:exported="true">
11
+ <intent-filter>
12
+ <action android:name="com.reteno.custom-push" />
13
+ </intent-filter>
14
+ </receiver>
15
+ <meta-data
16
+ android:name="com.reteno.Receiver.PushReceived"
17
+ android:value="com.reteno.plugin.RetenoPushReceiver" />
18
+ </application>
19
+
20
+ </manifest>
@@ -0,0 +1,7 @@
1
+ package com.reteno.plugin;
2
+
3
+ import com.reteno.core.RetenoApplication;
4
+
5
+ public interface CordovaRetenoApplication extends RetenoApplication {
6
+ void initReteno(String key);
7
+ }
@@ -0,0 +1,74 @@
1
+ package com.reteno.plugin;
2
+
3
+ import android.os.Build;
4
+
5
+ import com.reteno.core.domain.model.event.Event;
6
+ import com.reteno.core.domain.model.event.Parameter;
7
+
8
+ import org.json.JSONArray;
9
+ import org.json.JSONException;
10
+ import org.json.JSONObject;
11
+
12
+ import java.time.ZonedDateTime;
13
+ import java.util.ArrayList;
14
+ import java.util.List;
15
+
16
+ public class RetenoEvent {
17
+
18
+ private static List<Parameter> buildEventParameters(JSONArray inputParameters) throws JSONException {
19
+ int countView = inputParameters.length();
20
+ if (countView == 0) return null;
21
+
22
+ List<Parameter> list = new ArrayList<>();
23
+ for (int i = 0; i < countView; i++) {
24
+ JSONObject field = (JSONObject) inputParameters.get(i);
25
+
26
+ String name = null;
27
+ String value = null;
28
+
29
+ if (field.getString("name") != null) {
30
+ name = field.getString("name");
31
+ }
32
+ if (field.getString("value") != null) {
33
+ value = field.getString("value");
34
+ }
35
+
36
+ if (name != null) {
37
+ list.add(new Parameter(name, value));
38
+ }
39
+ }
40
+ return list;
41
+ }
42
+
43
+ public static Event buildEventFromPayload(JSONObject payload) throws Exception {
44
+ String eventName = RetenoUtil.getStringOrNull(payload, "eventName");
45
+ String stringDate = RetenoUtil.getStringOrNull(payload, "date");
46
+ JSONArray inputParameters=null;
47
+ if (payload.has("parameters"))
48
+ inputParameters = payload.getJSONArray("parameters");
49
+
50
+ List<Parameter> parameters = null;
51
+
52
+ ZonedDateTime date = null;
53
+
54
+ if (eventName == null) {
55
+ throw new Exception("logEvent: missing 'eventName' parameter!");
56
+ }
57
+
58
+ if (stringDate != null) {
59
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
60
+ date = ZonedDateTime.parse(stringDate);
61
+ }
62
+ } else {
63
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
64
+ date = ZonedDateTime.now();
65
+ }
66
+ }
67
+
68
+ if (inputParameters != null) {
69
+ parameters = buildEventParameters(inputParameters);
70
+ }
71
+
72
+ return new Event.Custom(eventName, date, parameters);
73
+ }
74
+ }
@@ -0,0 +1,162 @@
1
+ package com.reteno.plugin;
2
+
3
+ import android.app.Activity;
4
+ import android.content.Context;
5
+ import android.content.Intent;
6
+ import android.os.Bundle;
7
+ import android.util.Log;
8
+ import android.widget.Toast;
9
+
10
+ import com.reteno.core.Reteno;
11
+ import com.reteno.core.RetenoApplication;
12
+ import com.reteno.core.domain.model.event.Event;
13
+ import com.reteno.core.domain.model.user.User;
14
+ import com.reteno.core.domain.model.user.UserAttributesAnonymous;
15
+
16
+ import org.apache.cordova.CallbackContext;
17
+ import org.apache.cordova.CordovaPlugin;
18
+ import org.apache.cordova.PluginResult;
19
+ import org.apache.cordova.firebase.FirebasePlugin;
20
+ import org.json.JSONArray;
21
+ import org.json.JSONException;
22
+ import org.json.JSONObject;
23
+
24
+ import java.util.HashMap;
25
+ import java.util.Iterator;
26
+ import java.util.Map;
27
+ import java.util.Set;
28
+
29
+ public class RetenoPlugin extends CordovaPlugin {
30
+ protected static final String TAG = "RetenoPlugin";
31
+
32
+ public void setApiKey(String key){
33
+ ((CordovaRetenoApplication)this.cordova.getActivity().getApplication()).initReteno(key);
34
+ }
35
+
36
+ public Reteno getRetenoInstance() {
37
+ return ((RetenoApplication)this.cordova.getActivity().getApplication()).getRetenoInstance();
38
+ }
39
+
40
+ @Override
41
+ public boolean execute(
42
+ String action, JSONArray args, CallbackContext callbackContext
43
+ ) throws JSONException {
44
+ if ("setApiKey".equals(action)){
45
+ setApiKey(args.getString(0));
46
+ return true;
47
+ }
48
+ if ("logEvent".equals(action)){
49
+ cordova.getThreadPool().execute(new Runnable() {
50
+ @Override
51
+ public void run() {
52
+ callbackContext.sendPluginResult(logEvent(args));
53
+ }
54
+ });
55
+ return true;
56
+ }
57
+ if ("setUserAttributes".equals(action)){
58
+ cordova.getThreadPool().execute(new Runnable() {
59
+ @Override
60
+ public void run() {
61
+ callbackContext.sendPluginResult(createUser(args));
62
+ }
63
+ });
64
+ return true;
65
+ }
66
+ if ("setAnonymousUserAttributes".equals(action)){
67
+ cordova.getThreadPool().execute(new Runnable() {
68
+ @Override
69
+ public void run() {
70
+ callbackContext.sendPluginResult(createAnonymousUser(args));
71
+ }
72
+ });
73
+ return true;
74
+ }
75
+ if ("getInitialNotification".equals(action)){
76
+ echo(action + "\n" + args.toString(), callbackContext);
77
+ return true;
78
+ }
79
+ if ("setDeviceToken".equals(action)){
80
+ setDeviceToken(args, callbackContext);
81
+ return true;
82
+ }
83
+ if ("performRemoteToken".equals(action)){
84
+ echo(action + "\n" + args.toString(), callbackContext);
85
+ return true;
86
+ }
87
+ return false;
88
+ }
89
+
90
+ private void echo(String msg, CallbackContext callbackContext) {
91
+ if (msg == null || msg.length() == 0) {
92
+ callbackContext.error("Empty message!");
93
+ } else {
94
+ Toast.makeText(webView.getContext(), msg, Toast.LENGTH_LONG)
95
+ .show();
96
+ callbackContext.success(msg);
97
+ }
98
+ }
99
+
100
+ private PluginResult logEvent(JSONArray args) {
101
+ if (args == null || args.length() == 0) {
102
+ return new PluginResult(PluginResult.Status.ERROR, "Empty event");
103
+ } else {
104
+ try {
105
+ Event event = RetenoEvent.buildEventFromPayload((JSONObject) args.get(0));
106
+ getRetenoInstance().logEvent(event);
107
+ } catch (Exception e) {
108
+ Log.e("RetenoPlugin", e.getLocalizedMessage(), e);
109
+ return new PluginResult(PluginResult.Status.ERROR, ("Reteno Android SDK Error " + e.getLocalizedMessage()));
110
+ }
111
+ return new PluginResult(PluginResult.Status.OK);
112
+ }
113
+ }
114
+
115
+ public void setDeviceToken(JSONArray args, CallbackContext callbackContext) {
116
+
117
+ }
118
+
119
+ public PluginResult createUser(JSONArray args) {
120
+ try {
121
+ JSONObject payload = (JSONObject)args.get(0);
122
+ String externalId = payload.getString("externalUserId");
123
+ User user = RetenoUserAttributes.buildUserFromPayload(payload);
124
+ getRetenoInstance().setUserAttributes(externalId, user);
125
+ } catch (Exception e) {
126
+ Log.e("RetenoPlugin", e.getLocalizedMessage(), e);
127
+ return new PluginResult(PluginResult.Status.ERROR, "Reteno Android SDK Error: " + e.getLocalizedMessage());
128
+ }
129
+ return new PluginResult(PluginResult.Status.OK);
130
+ }
131
+
132
+ public PluginResult createAnonymousUser(JSONArray args) {
133
+ try {
134
+ JSONObject payload = (JSONObject)args.get(0);
135
+ UserAttributesAnonymous userAttributes = RetenoUserAttributes.buildAnonymousUserFromPayload(payload);
136
+ getRetenoInstance().setAnonymousUserAttributes(userAttributes);
137
+ } catch (Exception e) {
138
+ Log.e("RetenoPlugin", e.getLocalizedMessage(), e);
139
+ return new PluginResult(PluginResult.Status.ERROR, "Reteno Android SDK Error: " + e.getLocalizedMessage());
140
+ }
141
+ return new PluginResult(PluginResult.Status.OK);
142
+ }
143
+ static Map<String, String> bundleToMap(Bundle extras) {
144
+ Map<String, String> map = new HashMap<String, String>();
145
+
146
+ Set<String> ks = extras.keySet();
147
+ Iterator<String> iterator = ks.iterator();
148
+ while (iterator.hasNext()) {
149
+ String key = iterator.next();
150
+ map.put(key, extras.getString(key));
151
+ }
152
+ return map;
153
+ }
154
+
155
+ public void getInitialNotification(CallbackContext callbackContext){
156
+ Activity activity = this.cordova.getActivity();
157
+ if(activity == null){
158
+ callbackContext.error("No activity");
159
+ return;
160
+ }
161
+ }
162
+ }
@@ -0,0 +1,14 @@
1
+ package com.reteno.plugin;
2
+
3
+ import android.content.BroadcastReceiver;
4
+ import android.content.Context;
5
+ import android.content.Intent;
6
+
7
+ import org.apache.cordova.firebase.FirebasePlugin;
8
+
9
+ public class RetenoPushReceiver extends BroadcastReceiver {
10
+ @Override
11
+ public void onReceive(Context context, Intent intent) {
12
+ FirebasePlugin.sendMessage(intent.getExtras(), context);
13
+ }
14
+ }
@@ -0,0 +1,176 @@
1
+ package com.reteno.plugin;
2
+
3
+ import com.reteno.core.domain.model.user.Address;
4
+ import com.reteno.core.domain.model.user.User;
5
+ import com.reteno.core.domain.model.user.UserAttributes;
6
+ import com.reteno.core.domain.model.user.UserAttributesAnonymous;
7
+ import com.reteno.core.domain.model.user.UserCustomField;
8
+
9
+ import org.json.JSONArray;
10
+ import org.json.JSONException;
11
+ import org.json.JSONObject;
12
+
13
+ import java.util.ArrayList;
14
+ import java.util.List;
15
+
16
+ public class RetenoUserAttributes {
17
+ private static List<UserCustomField> buildUserCustomData(JSONArray fields) throws JSONException {
18
+ int countView = fields.length();
19
+ if (countView == 0) return null;
20
+
21
+ List<UserCustomField> list = new ArrayList<>();
22
+ for (int i = 0; i < countView; i++) {
23
+ JSONObject field = fields.getJSONObject(i);
24
+
25
+ String key = null;
26
+ String value = null;
27
+
28
+ if (field.getString("key") != null) {
29
+ key = field.getString("key");
30
+ }
31
+ if (field.getString("value") != null) {
32
+ value = field.getString("value");
33
+ }
34
+
35
+ if (key != null) {
36
+ list.add(new UserCustomField(key, value));
37
+ }
38
+ }
39
+ return list;
40
+ }
41
+
42
+ private static List<String> buildStringArr(JSONObject user, String key) throws JSONException {
43
+ if (user == null) {
44
+ return null;
45
+ }
46
+ if (!user.has(key))
47
+ return null;
48
+ JSONArray payloadStringArr = user.getJSONArray(key);
49
+ if (payloadStringArr == null) {
50
+ return null;
51
+ }
52
+ int countView = payloadStringArr.length();
53
+ if (countView == 0) return null;
54
+
55
+ List<String> stringArr = new ArrayList<>();
56
+ for (int i = 0; i < countView; i++) {
57
+ String str = payloadStringArr.getString(i);
58
+ stringArr.add(str);
59
+ }
60
+ return stringArr;
61
+ }
62
+
63
+ public static User buildUserFromPayload(JSONObject payloadUser) throws JSONException {
64
+ JSONObject payloadUserAttributes = null;
65
+
66
+ String payloadPhone = null;
67
+ String payloadEmail = null;
68
+ String payloadFirstName = null;
69
+ String payloadLastName = null;
70
+ String payloadLanguageCode = null;
71
+ String payloadTimeZone = null;
72
+
73
+ JSONObject payloadAddress = null;
74
+ JSONArray payloadFields = null;
75
+
76
+ Address address = null;
77
+ List<UserCustomField> fields = null;
78
+
79
+ if (payloadUser != null) {
80
+ payloadUserAttributes = payloadUser.getJSONObject("userAttributes");
81
+ if (payloadUserAttributes != null) {
82
+ payloadPhone = RetenoUtil.getStringOrNull(payloadUserAttributes, "phone");
83
+ payloadEmail = RetenoUtil.getStringOrNull(payloadUserAttributes, "email");
84
+ payloadFirstName = RetenoUtil.getStringOrNull(payloadUserAttributes, "firstName");
85
+ payloadLastName = RetenoUtil.getStringOrNull(payloadUserAttributes, "lastName");
86
+ payloadLanguageCode = RetenoUtil.getStringOrNull(payloadUserAttributes, "languageCode");
87
+ payloadTimeZone = RetenoUtil.getStringOrNull(payloadUserAttributes, "timeZone");
88
+ if (payloadUserAttributes.has("address"))
89
+ payloadAddress = payloadUserAttributes.getJSONObject("address");
90
+ if (payloadUserAttributes.has("fields"))
91
+ payloadFields = payloadUserAttributes.getJSONArray("fields");
92
+ }
93
+ }
94
+
95
+ if (payloadAddress != null) {
96
+ address = new Address(
97
+ RetenoUtil.getStringOrNull(payloadAddress, "region"),
98
+ RetenoUtil.getStringOrNull(payloadAddress,"town"),
99
+ RetenoUtil.getStringOrNull(payloadAddress,"address"),
100
+ RetenoUtil.getStringOrNull(payloadAddress,"postcode")
101
+ );
102
+ }
103
+
104
+ if (payloadFields != null) {
105
+ fields = buildUserCustomData(payloadFields);
106
+ }
107
+
108
+ UserAttributes userAttributes = new UserAttributes(
109
+ payloadPhone,
110
+ payloadEmail,
111
+ payloadFirstName,
112
+ payloadLastName,
113
+ payloadLanguageCode,
114
+ payloadTimeZone,
115
+ address,
116
+ fields
117
+ );
118
+
119
+ List<String> subscriptionKeys = buildStringArr(payloadUser, "subscriptionKeys");
120
+ List<String> groupNamesInclude = buildStringArr(payloadUser, "groupNamesInclude");
121
+ List<String> groupNamesExclude = buildStringArr(payloadUser, "groupNamesExclude");
122
+
123
+ return new User(userAttributes, subscriptionKeys, groupNamesInclude, groupNamesExclude);
124
+ }
125
+
126
+ public static UserAttributesAnonymous buildAnonymousUserFromPayload(JSONObject payloadUser) throws JSONException {
127
+ JSONObject payloadUserAttributes = null;
128
+
129
+ String payloadFirstName = null;
130
+ String payloadLastName = null;
131
+ String payloadLanguageCode = null;
132
+ String payloadTimeZone = null;
133
+
134
+ JSONObject payloadAddress = null;
135
+ JSONArray payloadFields = null;
136
+
137
+ Address address = null;
138
+ List<UserCustomField> fields = null;
139
+
140
+ if (payloadUser != null) {
141
+ payloadUserAttributes = payloadUser.getJSONObject("userAttributes");
142
+ if (payloadUserAttributes != null) {
143
+ payloadFirstName = RetenoUtil.getStringOrNull(payloadUserAttributes, "firstName");
144
+ payloadLastName = RetenoUtil.getStringOrNull(payloadUserAttributes, "lastName");
145
+ payloadLanguageCode = RetenoUtil.getStringOrNull(payloadUserAttributes, "languageCode");
146
+ payloadTimeZone = RetenoUtil.getStringOrNull(payloadUserAttributes, "timeZone");
147
+ if (payloadUserAttributes.has("address"))
148
+ payloadAddress = payloadUserAttributes.getJSONObject("address");
149
+ if (payloadUserAttributes.has("fields"))
150
+ payloadFields = payloadUserAttributes.getJSONArray("fields");
151
+ }
152
+ }
153
+
154
+ if (payloadAddress != null) {
155
+ address = new Address(
156
+ RetenoUtil.getStringOrNull(payloadAddress, "region"),
157
+ RetenoUtil.getStringOrNull(payloadAddress,"town"),
158
+ RetenoUtil.getStringOrNull(payloadAddress,"address"),
159
+ RetenoUtil.getStringOrNull(payloadAddress,"postcode")
160
+ );
161
+ }
162
+ if (payloadFields != null) {
163
+ fields = buildUserCustomData(payloadFields);
164
+ }
165
+
166
+ UserAttributesAnonymous userAttributes = new UserAttributesAnonymous(
167
+ payloadFirstName,
168
+ payloadLastName,
169
+ payloadLanguageCode,
170
+ payloadTimeZone,
171
+ address,
172
+ fields
173
+ );
174
+ return userAttributes;
175
+ }
176
+ }
@@ -0,0 +1,12 @@
1
+ package com.reteno.plugin;
2
+
3
+ import org.json.JSONException;
4
+ import org.json.JSONObject;
5
+
6
+ public class RetenoUtil {
7
+ public static String getStringOrNull(JSONObject object, String fieldName) throws JSONException {
8
+ if (object.has(fieldName))
9
+ return object.getString(fieldName);
10
+ return null;
11
+ }
12
+ }