@capawesome/capacitor-singular 0.0.1

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 (79) hide show
  1. package/CapawesomeCapacitorSingular.podspec +19 -0
  2. package/LICENSE +21 -0
  3. package/Package.swift +26 -0
  4. package/README.md +1262 -0
  5. package/android/build.gradle +61 -0
  6. package/android/src/main/AndroidManifest.xml +5 -0
  7. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/Singular.java +443 -0
  8. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/SingularHelper.java +53 -0
  9. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/SingularPlugin.java +336 -0
  10. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/CustomException.java +20 -0
  11. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/CustomExceptions.java +34 -0
  12. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/events/DeviceAttributionInfoReceivedEvent.java +48 -0
  13. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/events/SdidReceivedEvent.java +23 -0
  14. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/events/SdidSetEvent.java +23 -0
  15. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/events/SingularLinkResolvedEvent.java +44 -0
  16. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/CreateReferrerShortLinkOptions.java +61 -0
  17. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/InitializeOptions.java +168 -0
  18. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/SetCustomUserIdOptions.java +24 -0
  19. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/SetDeviceTokenOptions.java +24 -0
  20. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/SetGlobalPropertyOptions.java +44 -0
  21. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/SetLimitAdvertisingIdentifiersOptions.java +22 -0
  22. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/SetLimitDataSharingOptions.java +22 -0
  23. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/TrackAdRevenueOptions.java +157 -0
  24. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/TrackEventOptions.java +35 -0
  25. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/TrackRevenueOptions.java +56 -0
  26. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/options/UnsetGlobalPropertyOptions.java +24 -0
  27. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/results/CreateReferrerShortLinkResult.java +23 -0
  28. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/results/GetGlobalPropertiesResult.java +31 -0
  29. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/results/GetLimitDataSharingResult.java +22 -0
  30. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/classes/results/IsAllTrackingStoppedResult.java +22 -0
  31. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/interfaces/Callback.java +5 -0
  32. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/interfaces/EmptyCallback.java +5 -0
  33. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/interfaces/NonEmptyResultCallback.java +7 -0
  34. package/android/src/main/java/io/capawesome/capacitorjs/plugins/singular/interfaces/Result.java +7 -0
  35. package/android/src/main/res/.gitkeep +0 -0
  36. package/dist/docs.json +2014 -0
  37. package/dist/esm/definitions.d.ts +925 -0
  38. package/dist/esm/definitions.js +39 -0
  39. package/dist/esm/definitions.js.map +1 -0
  40. package/dist/esm/index.d.ts +4 -0
  41. package/dist/esm/index.js +7 -0
  42. package/dist/esm/index.js.map +1 -0
  43. package/dist/esm/web.d.ts +27 -0
  44. package/dist/esm/web.js +73 -0
  45. package/dist/esm/web.js.map +1 -0
  46. package/dist/plugin.cjs.js +126 -0
  47. package/dist/plugin.cjs.js.map +1 -0
  48. package/dist/plugin.js +129 -0
  49. package/dist/plugin.js.map +1 -0
  50. package/ios/Plugin/Classes/Events/DeviceAttributionInfoReceivedEvent.swift +43 -0
  51. package/ios/Plugin/Classes/Events/SdidReceivedEvent.swift +16 -0
  52. package/ios/Plugin/Classes/Events/SdidSetEvent.swift +16 -0
  53. package/ios/Plugin/Classes/Events/SingularLinkResolvedEvent.swift +28 -0
  54. package/ios/Plugin/Classes/Events/SkanConversionValueUpdatedEvent.swift +30 -0
  55. package/ios/Plugin/Classes/Options/CreateReferrerShortLinkOptions.swift +25 -0
  56. package/ios/Plugin/Classes/Options/InitializeOptions.swift +44 -0
  57. package/ios/Plugin/Classes/Options/SetCustomUserIdOptions.swift +13 -0
  58. package/ios/Plugin/Classes/Options/SetDeviceTokenOptions.swift +30 -0
  59. package/ios/Plugin/Classes/Options/SetGlobalPropertyOptions.swift +20 -0
  60. package/ios/Plugin/Classes/Options/SetLimitAdvertisingIdentifiersOptions.swift +13 -0
  61. package/ios/Plugin/Classes/Options/SetLimitDataSharingOptions.swift +13 -0
  62. package/ios/Plugin/Classes/Options/SkanUpdateConversionValueOptions.swift +27 -0
  63. package/ios/Plugin/Classes/Options/TrackAdRevenueOptions.swift +47 -0
  64. package/ios/Plugin/Classes/Options/TrackEventOptions.swift +15 -0
  65. package/ios/Plugin/Classes/Options/TrackRevenueOptions.swift +22 -0
  66. package/ios/Plugin/Classes/Options/UnsetGlobalPropertyOptions.swift +13 -0
  67. package/ios/Plugin/Classes/Results/CreateReferrerShortLinkResult.swift +16 -0
  68. package/ios/Plugin/Classes/Results/GetGlobalPropertiesResult.swift +16 -0
  69. package/ios/Plugin/Classes/Results/GetLimitDataSharingResult.swift +16 -0
  70. package/ios/Plugin/Classes/Results/IsAllTrackingStoppedResult.swift +16 -0
  71. package/ios/Plugin/Classes/Results/SkanGetConversionValueResult.swift +20 -0
  72. package/ios/Plugin/Enums/CustomError.swift +88 -0
  73. package/ios/Plugin/Enums/SkanCoarseConversionValue.swift +31 -0
  74. package/ios/Plugin/Info.plist +24 -0
  75. package/ios/Plugin/Protocols/Result.swift +6 -0
  76. package/ios/Plugin/Singular.swift +341 -0
  77. package/ios/Plugin/SingularHelper.swift +40 -0
  78. package/ios/Plugin/SingularPlugin.swift +340 -0
  79. package/package.json +102 -0
@@ -0,0 +1,336 @@
1
+ package io.capawesome.capacitorjs.plugins.singular;
2
+
3
+ import android.content.Intent;
4
+ import androidx.annotation.NonNull;
5
+ import androidx.annotation.Nullable;
6
+ import com.getcapacitor.Logger;
7
+ import com.getcapacitor.Plugin;
8
+ import com.getcapacitor.PluginCall;
9
+ import com.getcapacitor.PluginMethod;
10
+ import com.getcapacitor.annotation.CapacitorPlugin;
11
+ import io.capawesome.capacitorjs.plugins.singular.classes.CustomException;
12
+ import io.capawesome.capacitorjs.plugins.singular.classes.events.DeviceAttributionInfoReceivedEvent;
13
+ import io.capawesome.capacitorjs.plugins.singular.classes.events.SdidReceivedEvent;
14
+ import io.capawesome.capacitorjs.plugins.singular.classes.events.SdidSetEvent;
15
+ import io.capawesome.capacitorjs.plugins.singular.classes.events.SingularLinkResolvedEvent;
16
+ import io.capawesome.capacitorjs.plugins.singular.classes.options.CreateReferrerShortLinkOptions;
17
+ import io.capawesome.capacitorjs.plugins.singular.classes.options.InitializeOptions;
18
+ import io.capawesome.capacitorjs.plugins.singular.classes.options.SetCustomUserIdOptions;
19
+ import io.capawesome.capacitorjs.plugins.singular.classes.options.SetDeviceTokenOptions;
20
+ import io.capawesome.capacitorjs.plugins.singular.classes.options.SetGlobalPropertyOptions;
21
+ import io.capawesome.capacitorjs.plugins.singular.classes.options.SetLimitAdvertisingIdentifiersOptions;
22
+ import io.capawesome.capacitorjs.plugins.singular.classes.options.SetLimitDataSharingOptions;
23
+ import io.capawesome.capacitorjs.plugins.singular.classes.options.TrackAdRevenueOptions;
24
+ import io.capawesome.capacitorjs.plugins.singular.classes.options.TrackEventOptions;
25
+ import io.capawesome.capacitorjs.plugins.singular.classes.options.TrackRevenueOptions;
26
+ import io.capawesome.capacitorjs.plugins.singular.classes.options.UnsetGlobalPropertyOptions;
27
+ import io.capawesome.capacitorjs.plugins.singular.interfaces.EmptyCallback;
28
+ import io.capawesome.capacitorjs.plugins.singular.interfaces.NonEmptyResultCallback;
29
+ import io.capawesome.capacitorjs.plugins.singular.interfaces.Result;
30
+
31
+ @CapacitorPlugin(name = "Singular")
32
+ public class SingularPlugin extends Plugin {
33
+
34
+ public static final String EVENT_DEVICE_ATTRIBUTION_INFO_RECEIVED = "deviceAttributionInfoReceived";
35
+ public static final String EVENT_SDID_RECEIVED = "sdidReceived";
36
+ public static final String EVENT_SDID_SET = "sdidSet";
37
+ public static final String EVENT_SINGULAR_LINK_RESOLVED = "singularLinkResolved";
38
+ public static final String TAG = "SingularPlugin";
39
+
40
+ private static final String ERROR_UNKNOWN_ERROR = "An unknown error has occurred.";
41
+
42
+ private Singular implementation;
43
+
44
+ @Override
45
+ public void load() {
46
+ super.load();
47
+ this.implementation = new Singular(this);
48
+ }
49
+
50
+ @PluginMethod
51
+ public void clearGlobalProperties(PluginCall call) {
52
+ try {
53
+ implementation.clearGlobalProperties(createEmptyCallback(call));
54
+ } catch (Exception exception) {
55
+ rejectCall(call, exception);
56
+ }
57
+ }
58
+
59
+ @PluginMethod
60
+ public void createReferrerShortLink(PluginCall call) {
61
+ try {
62
+ CreateReferrerShortLinkOptions options = new CreateReferrerShortLinkOptions(call);
63
+ implementation.createReferrerShortLink(options, createNonEmptyResultCallback(call));
64
+ } catch (Exception exception) {
65
+ rejectCall(call, exception);
66
+ }
67
+ }
68
+
69
+ @PluginMethod
70
+ public void getGlobalProperties(PluginCall call) {
71
+ try {
72
+ implementation.getGlobalProperties(createNonEmptyResultCallback(call));
73
+ } catch (Exception exception) {
74
+ rejectCall(call, exception);
75
+ }
76
+ }
77
+
78
+ @PluginMethod
79
+ public void getLimitDataSharing(PluginCall call) {
80
+ try {
81
+ implementation.getLimitDataSharing(createNonEmptyResultCallback(call));
82
+ } catch (Exception exception) {
83
+ rejectCall(call, exception);
84
+ }
85
+ }
86
+
87
+ @PluginMethod
88
+ public void initialize(PluginCall call) {
89
+ try {
90
+ InitializeOptions options = new InitializeOptions(call);
91
+ implementation.initialize(options, createEmptyCallback(call));
92
+ } catch (Exception exception) {
93
+ rejectCall(call, exception);
94
+ }
95
+ }
96
+
97
+ @PluginMethod
98
+ public void isAllTrackingStopped(PluginCall call) {
99
+ try {
100
+ implementation.isAllTrackingStopped(createNonEmptyResultCallback(call));
101
+ } catch (Exception exception) {
102
+ rejectCall(call, exception);
103
+ }
104
+ }
105
+
106
+ public void notifyDeviceAttributionInfoReceivedListeners(@NonNull DeviceAttributionInfoReceivedEvent event) {
107
+ notifyListeners(EVENT_DEVICE_ATTRIBUTION_INFO_RECEIVED, event.toJSObject());
108
+ }
109
+
110
+ public void notifySdidReceivedListeners(@NonNull SdidReceivedEvent event) {
111
+ notifyListeners(EVENT_SDID_RECEIVED, event.toJSObject());
112
+ }
113
+
114
+ public void notifySdidSetListeners(@NonNull SdidSetEvent event) {
115
+ notifyListeners(EVENT_SDID_SET, event.toJSObject());
116
+ }
117
+
118
+ public void notifySingularLinkResolvedListeners(@NonNull SingularLinkResolvedEvent event) {
119
+ notifyListeners(EVENT_SINGULAR_LINK_RESOLVED, event.toJSObject());
120
+ }
121
+
122
+ @PluginMethod
123
+ public void resumeAllTracking(PluginCall call) {
124
+ try {
125
+ implementation.resumeAllTracking(createEmptyCallback(call));
126
+ } catch (Exception exception) {
127
+ rejectCall(call, exception);
128
+ }
129
+ }
130
+
131
+ @PluginMethod
132
+ public void setCustomUserId(PluginCall call) {
133
+ try {
134
+ SetCustomUserIdOptions options = new SetCustomUserIdOptions(call);
135
+ implementation.setCustomUserId(options, createEmptyCallback(call));
136
+ } catch (Exception exception) {
137
+ rejectCall(call, exception);
138
+ }
139
+ }
140
+
141
+ @PluginMethod
142
+ public void setDeviceToken(PluginCall call) {
143
+ try {
144
+ SetDeviceTokenOptions options = new SetDeviceTokenOptions(call);
145
+ implementation.setDeviceToken(options, createEmptyCallback(call));
146
+ } catch (Exception exception) {
147
+ rejectCall(call, exception);
148
+ }
149
+ }
150
+
151
+ @PluginMethod
152
+ public void setGlobalProperty(PluginCall call) {
153
+ try {
154
+ SetGlobalPropertyOptions options = new SetGlobalPropertyOptions(call);
155
+ implementation.setGlobalProperty(options, createEmptyCallback(call));
156
+ } catch (Exception exception) {
157
+ rejectCall(call, exception);
158
+ }
159
+ }
160
+
161
+ @PluginMethod
162
+ public void setLimitAdvertisingIdentifiers(PluginCall call) {
163
+ try {
164
+ SetLimitAdvertisingIdentifiersOptions options = new SetLimitAdvertisingIdentifiersOptions(call);
165
+ implementation.setLimitAdvertisingIdentifiers(options, createEmptyCallback(call));
166
+ } catch (Exception exception) {
167
+ rejectCall(call, exception);
168
+ }
169
+ }
170
+
171
+ @PluginMethod
172
+ public void setLimitDataSharing(PluginCall call) {
173
+ try {
174
+ SetLimitDataSharingOptions options = new SetLimitDataSharingOptions(call);
175
+ implementation.setLimitDataSharing(options, createEmptyCallback(call));
176
+ } catch (Exception exception) {
177
+ rejectCall(call, exception);
178
+ }
179
+ }
180
+
181
+ @PluginMethod
182
+ public void skanGetConversionValue(PluginCall call) {
183
+ rejectCallAsUnimplemented(call);
184
+ }
185
+
186
+ @PluginMethod
187
+ public void skanRegisterAppForAdNetworkAttribution(PluginCall call) {
188
+ rejectCallAsUnimplemented(call);
189
+ }
190
+
191
+ @PluginMethod
192
+ public void skanUpdateConversionValue(PluginCall call) {
193
+ rejectCallAsUnimplemented(call);
194
+ }
195
+
196
+ @PluginMethod
197
+ public void stopAllTracking(PluginCall call) {
198
+ try {
199
+ implementation.stopAllTracking(createEmptyCallback(call));
200
+ } catch (Exception exception) {
201
+ rejectCall(call, exception);
202
+ }
203
+ }
204
+
205
+ @PluginMethod
206
+ public void trackAdRevenue(PluginCall call) {
207
+ try {
208
+ TrackAdRevenueOptions options = new TrackAdRevenueOptions(call);
209
+ implementation.trackAdRevenue(options, createEmptyCallback(call));
210
+ } catch (Exception exception) {
211
+ rejectCall(call, exception);
212
+ }
213
+ }
214
+
215
+ @PluginMethod
216
+ public void trackEvent(PluginCall call) {
217
+ try {
218
+ TrackEventOptions options = new TrackEventOptions(call);
219
+ implementation.trackEvent(options, createEmptyCallback(call));
220
+ } catch (Exception exception) {
221
+ rejectCall(call, exception);
222
+ }
223
+ }
224
+
225
+ @PluginMethod
226
+ public void trackRevenue(PluginCall call) {
227
+ try {
228
+ TrackRevenueOptions options = new TrackRevenueOptions(call);
229
+ implementation.trackRevenue(options, createEmptyCallback(call));
230
+ } catch (Exception exception) {
231
+ rejectCall(call, exception);
232
+ }
233
+ }
234
+
235
+ @PluginMethod
236
+ public void trackingOptIn(PluginCall call) {
237
+ try {
238
+ implementation.trackingOptIn(createEmptyCallback(call));
239
+ } catch (Exception exception) {
240
+ rejectCall(call, exception);
241
+ }
242
+ }
243
+
244
+ @PluginMethod
245
+ public void trackingUnder13(PluginCall call) {
246
+ try {
247
+ implementation.trackingUnder13(createEmptyCallback(call));
248
+ } catch (Exception exception) {
249
+ rejectCall(call, exception);
250
+ }
251
+ }
252
+
253
+ @PluginMethod
254
+ public void unsetCustomUserId(PluginCall call) {
255
+ try {
256
+ implementation.unsetCustomUserId(createEmptyCallback(call));
257
+ } catch (Exception exception) {
258
+ rejectCall(call, exception);
259
+ }
260
+ }
261
+
262
+ @PluginMethod
263
+ public void unsetGlobalProperty(PluginCall call) {
264
+ try {
265
+ UnsetGlobalPropertyOptions options = new UnsetGlobalPropertyOptions(call);
266
+ implementation.unsetGlobalProperty(options, createEmptyCallback(call));
267
+ } catch (Exception exception) {
268
+ rejectCall(call, exception);
269
+ }
270
+ }
271
+
272
+ @Override
273
+ protected void handleOnNewIntent(Intent intent) {
274
+ super.handleOnNewIntent(intent);
275
+ implementation.handleNewIntent(intent);
276
+ }
277
+
278
+ @NonNull
279
+ private EmptyCallback createEmptyCallback(@NonNull PluginCall call) {
280
+ return new EmptyCallback() {
281
+ @Override
282
+ public void success() {
283
+ resolveCall(call);
284
+ }
285
+
286
+ @Override
287
+ public void error(Exception exception) {
288
+ rejectCall(call, exception);
289
+ }
290
+ };
291
+ }
292
+
293
+ @NonNull
294
+ private <T extends Result> NonEmptyResultCallback<T> createNonEmptyResultCallback(@NonNull PluginCall call) {
295
+ return new NonEmptyResultCallback<T>() {
296
+ @Override
297
+ public void success(@NonNull T result) {
298
+ resolveCall(call, result);
299
+ }
300
+
301
+ @Override
302
+ public void error(Exception exception) {
303
+ rejectCall(call, exception);
304
+ }
305
+ };
306
+ }
307
+
308
+ private void rejectCall(@NonNull PluginCall call, @NonNull Exception exception) {
309
+ String message = exception.getMessage();
310
+ if (message == null) {
311
+ message = ERROR_UNKNOWN_ERROR;
312
+ }
313
+ String code = null;
314
+ if (exception instanceof CustomException) {
315
+ code = ((CustomException) exception).getCode();
316
+ }
317
+ Logger.error(TAG, message, exception);
318
+ call.reject(message, code);
319
+ }
320
+
321
+ private void rejectCallAsUnimplemented(@NonNull PluginCall call) {
322
+ call.unimplemented("This method is not available on this platform.");
323
+ }
324
+
325
+ private void resolveCall(@NonNull PluginCall call) {
326
+ call.resolve();
327
+ }
328
+
329
+ private void resolveCall(@NonNull PluginCall call, @Nullable Result result) {
330
+ if (result == null) {
331
+ call.resolve();
332
+ } else {
333
+ call.resolve(result.toJSObject());
334
+ }
335
+ }
336
+ }
@@ -0,0 +1,20 @@
1
+ package io.capawesome.capacitorjs.plugins.singular.classes;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
6
+ public class CustomException extends Exception {
7
+
8
+ @Nullable
9
+ private final String code;
10
+
11
+ public CustomException(@Nullable String code, @NonNull String message) {
12
+ super(message);
13
+ this.code = code;
14
+ }
15
+
16
+ @Nullable
17
+ public String getCode() {
18
+ return code;
19
+ }
20
+ }
@@ -0,0 +1,34 @@
1
+ package io.capawesome.capacitorjs.plugins.singular.classes;
2
+
3
+ public class CustomExceptions {
4
+
5
+ public static final CustomException AD_PLATFORM_MISSING = new CustomException(null, "adPlatform must be provided.");
6
+ public static final CustomException AMOUNT_MISSING = new CustomException(null, "amount must be provided.");
7
+ public static final CustomException API_KEY_MISSING = new CustomException(null, "apiKey must be provided.");
8
+ public static final CustomException BASE_LINK_MISSING = new CustomException(null, "baseLink must be provided.");
9
+ public static final CustomException CURRENCY_MISSING = new CustomException(null, "currency must be provided.");
10
+ public static final CustomException CUSTOM_USER_ID_MISSING = new CustomException(null, "customUserId must be provided.");
11
+ public static final CustomException EVENT_COULD_NOT_BE_TRACKED = new CustomException(null, "The event could not be tracked.");
12
+ public static final CustomException GLOBAL_PROPERTY_COULD_NOT_BE_SET = new CustomException(
13
+ null,
14
+ "The global property could not be set."
15
+ );
16
+ public static final CustomException INITIALIZATION_FAILED = new CustomException(
17
+ "INITIALIZATION_FAILED",
18
+ "The initialization of the SDK failed."
19
+ );
20
+ public static final CustomException KEY_MISSING = new CustomException(null, "key must be provided.");
21
+ public static final CustomException LIMIT_MISSING = new CustomException(null, "limit must be provided.");
22
+ public static final CustomException NAME_MISSING = new CustomException(null, "name must be provided.");
23
+ public static final CustomException NOT_INITIALIZED = new CustomException(
24
+ "NOT_INITIALIZED",
25
+ "The plugin has not been initialized yet."
26
+ );
27
+ public static final CustomException REFERRER_ID_MISSING = new CustomException(null, "referrerId must be provided.");
28
+ public static final CustomException REFERRER_NAME_MISSING = new CustomException(null, "referrerName must be provided.");
29
+ public static final CustomException REVENUE_COULD_NOT_BE_TRACKED = new CustomException(null, "The revenue could not be tracked.");
30
+ public static final CustomException REVENUE_MISSING = new CustomException(null, "revenue must be provided.");
31
+ public static final CustomException SECRET_MISSING = new CustomException(null, "secret must be provided.");
32
+ public static final CustomException TOKEN_MISSING = new CustomException(null, "token must be provided.");
33
+ public static final CustomException VALUE_MISSING = new CustomException(null, "value must be provided.");
34
+ }
@@ -0,0 +1,48 @@
1
+ package io.capawesome.capacitorjs.plugins.singular.classes.events;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.singular.interfaces.Result;
6
+ import java.util.Map;
7
+
8
+ public class DeviceAttributionInfoReceivedEvent implements Result {
9
+
10
+ @NonNull
11
+ private final Map<String, Object> attributionInfo;
12
+
13
+ public DeviceAttributionInfoReceivedEvent(@NonNull Map<String, Object> attributionInfo) {
14
+ this.attributionInfo = attributionInfo;
15
+ }
16
+
17
+ @Override
18
+ @NonNull
19
+ public JSObject toJSObject() {
20
+ JSObject event = new JSObject();
21
+ putStringIfPresent(event, "campaignId", "campaign_id");
22
+ putStringIfPresent(event, "campaignName", "campaign_name");
23
+ putClickTimestampIfPresent(event);
24
+ putStringIfPresent(event, "creativeId", "creative_id");
25
+ putStringIfPresent(event, "creativeName", "creative_name");
26
+ putStringIfPresent(event, "matchType", "match_type");
27
+ putStringIfPresent(event, "network", "network");
28
+ putStringIfPresent(event, "passthrough", "passthrough");
29
+ putStringIfPresent(event, "subcampaignId", "subcampaign_id");
30
+ putStringIfPresent(event, "subcampaignName", "subcampaign_name");
31
+ return event;
32
+ }
33
+
34
+ private void putClickTimestampIfPresent(@NonNull JSObject event) {
35
+ Object value = attributionInfo.get("click_timestamp");
36
+ if (value instanceof Number) {
37
+ long timestampInMicroseconds = ((Number) value).longValue();
38
+ event.put("clickTimestamp", timestampInMicroseconds / 1000);
39
+ }
40
+ }
41
+
42
+ private void putStringIfPresent(@NonNull JSObject event, @NonNull String key, @NonNull String attributionInfoKey) {
43
+ Object value = attributionInfo.get(attributionInfoKey);
44
+ if (value instanceof String) {
45
+ event.put(key, (String) value);
46
+ }
47
+ }
48
+ }
@@ -0,0 +1,23 @@
1
+ package io.capawesome.capacitorjs.plugins.singular.classes.events;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.singular.interfaces.Result;
6
+
7
+ public class SdidReceivedEvent implements Result {
8
+
9
+ @NonNull
10
+ private final String sdid;
11
+
12
+ public SdidReceivedEvent(@NonNull String sdid) {
13
+ this.sdid = sdid;
14
+ }
15
+
16
+ @Override
17
+ @NonNull
18
+ public JSObject toJSObject() {
19
+ JSObject event = new JSObject();
20
+ event.put("sdid", sdid);
21
+ return event;
22
+ }
23
+ }
@@ -0,0 +1,23 @@
1
+ package io.capawesome.capacitorjs.plugins.singular.classes.events;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import com.getcapacitor.JSObject;
5
+ import io.capawesome.capacitorjs.plugins.singular.interfaces.Result;
6
+
7
+ public class SdidSetEvent implements Result {
8
+
9
+ @NonNull
10
+ private final String sdid;
11
+
12
+ public SdidSetEvent(@NonNull String sdid) {
13
+ this.sdid = sdid;
14
+ }
15
+
16
+ @Override
17
+ @NonNull
18
+ public JSObject toJSObject() {
19
+ JSObject event = new JSObject();
20
+ event.put("sdid", sdid);
21
+ return event;
22
+ }
23
+ }
@@ -0,0 +1,44 @@
1
+ package io.capawesome.capacitorjs.plugins.singular.classes.events;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+ import com.getcapacitor.JSObject;
6
+ import com.singular.sdk.SingularLinkParams;
7
+ import io.capawesome.capacitorjs.plugins.singular.interfaces.Result;
8
+ import java.util.HashMap;
9
+ import java.util.Map;
10
+ import org.json.JSONObject;
11
+
12
+ public class SingularLinkResolvedEvent implements Result {
13
+
14
+ @NonNull
15
+ private final SingularLinkParams linkParams;
16
+
17
+ public SingularLinkResolvedEvent(@NonNull SingularLinkParams linkParams) {
18
+ this.linkParams = linkParams;
19
+ }
20
+
21
+ @Override
22
+ @NonNull
23
+ public JSObject toJSObject() {
24
+ String deepLink = linkParams.getDeeplink();
25
+ String passthrough = linkParams.getPassthrough();
26
+ JSObject event = new JSObject();
27
+ event.put("deepLink", deepLink == null ? JSONObject.NULL : deepLink);
28
+ event.put("isDeferred", linkParams.isDeferred());
29
+ event.put("passthrough", passthrough == null ? JSONObject.NULL : passthrough);
30
+ event.put("urlParameters", createUrlParameters(linkParams.getUrlParameters()));
31
+ return event;
32
+ }
33
+
34
+ @NonNull
35
+ private JSObject createUrlParameters(@Nullable HashMap<String, String> parameters) {
36
+ JSObject urlParameters = new JSObject();
37
+ if (parameters != null) {
38
+ for (Map.Entry<String, String> parameter : parameters.entrySet()) {
39
+ urlParameters.put(parameter.getKey(), parameter.getValue());
40
+ }
41
+ }
42
+ return urlParameters;
43
+ }
44
+ }
@@ -0,0 +1,61 @@
1
+ package io.capawesome.capacitorjs.plugins.singular.classes.options;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+ import com.getcapacitor.JSObject;
6
+ import com.getcapacitor.PluginCall;
7
+ import io.capawesome.capacitorjs.plugins.singular.classes.CustomExceptions;
8
+
9
+ public class CreateReferrerShortLinkOptions {
10
+
11
+ @NonNull
12
+ private final String baseLink;
13
+
14
+ @Nullable
15
+ private final JSObject passthroughParameters;
16
+
17
+ @NonNull
18
+ private final String referrerId;
19
+
20
+ @NonNull
21
+ private final String referrerName;
22
+
23
+ public CreateReferrerShortLinkOptions(@NonNull PluginCall call) throws Exception {
24
+ String baseLink = call.getString("baseLink");
25
+ if (baseLink == null) {
26
+ throw CustomExceptions.BASE_LINK_MISSING;
27
+ }
28
+ String referrerId = call.getString("referrerId");
29
+ if (referrerId == null) {
30
+ throw CustomExceptions.REFERRER_ID_MISSING;
31
+ }
32
+ String referrerName = call.getString("referrerName");
33
+ if (referrerName == null) {
34
+ throw CustomExceptions.REFERRER_NAME_MISSING;
35
+ }
36
+ this.baseLink = baseLink;
37
+ this.passthroughParameters = call.getObject("passthroughParameters");
38
+ this.referrerId = referrerId;
39
+ this.referrerName = referrerName;
40
+ }
41
+
42
+ @NonNull
43
+ public String getBaseLink() {
44
+ return baseLink;
45
+ }
46
+
47
+ @Nullable
48
+ public JSObject getPassthroughParameters() {
49
+ return passthroughParameters;
50
+ }
51
+
52
+ @NonNull
53
+ public String getReferrerId() {
54
+ return referrerId;
55
+ }
56
+
57
+ @NonNull
58
+ public String getReferrerName() {
59
+ return referrerName;
60
+ }
61
+ }