vibes-react-native 5.0.1-rc1 → 5.0.1-rc2
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/ios/Vibes.swift +2 -3
- package/ios/VibesClient.swift +3 -4
- package/ios/VibesPluginLogger.swift +0 -1
- package/package.json +3 -2
- package/vendor/VibesPush/LICENSE +13 -0
- package/vendor/VibesPush/Sources/APIDefinition.swift +502 -0
- package/vendor/VibesPush/Sources/Actions.swift +24 -0
- package/vendor/VibesPush/Sources/AppObserver.swift +137 -0
- package/vendor/VibesPush/Sources/AuthTokenBehavior.swift +17 -0
- package/vendor/VibesPush/Sources/CombinedLogger.swift +53 -0
- package/vendor/VibesPush/Sources/ConsoleLogger.swift +97 -0
- package/vendor/VibesPush/Sources/Credential.swift +41 -0
- package/vendor/VibesPush/Sources/CredentialManager.swift +24 -0
- package/vendor/VibesPush/Sources/Date+iso8601.swift +34 -0
- package/vendor/VibesPush/Sources/Date+logPrefix.swift +20 -0
- package/vendor/VibesPush/Sources/DeviceToken.swift +15 -0
- package/vendor/VibesPush/Sources/DeviceType.swift +143 -0
- package/vendor/VibesPush/Sources/Dictionary+merged.swift +11 -0
- package/vendor/VibesPush/Sources/Event.swift +83 -0
- package/vendor/VibesPush/Sources/EventCollection.swift +36 -0
- package/vendor/VibesPush/Sources/EventTracker.swift +39 -0
- package/vendor/VibesPush/Sources/FoundationExtensions.swift +16 -0
- package/vendor/VibesPush/Sources/GitTag.swift +27 -0
- package/vendor/VibesPush/Sources/HTTP/HTTPBehavior.swift +19 -0
- package/vendor/VibesPush/Sources/HTTP/HTTPMethod.swift +20 -0
- package/vendor/VibesPush/Sources/HTTP/HTTPResource.swift +69 -0
- package/vendor/VibesPush/Sources/HTTP/HTTPResourceClient.swift +190 -0
- package/vendor/VibesPush/Sources/HTTP/JSONParser.swift +91 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/AssociatePersonOperation.swift +56 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/BaseOperation.swift +153 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/EventOperation.swift +73 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/GetGitTagsOperation.swift +61 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/GetInboxMessageOperation.swift +59 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/GetInboxMessagesOperation.swift +57 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/GetPersonOperation.swift +53 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/GetVibesAppInfoOperation.swift +45 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/MigrationCallbackOperation.swift +45 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/RegisterDeviceOperation.swift +66 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/RegisterPushOperation.swift +73 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/TrackProductActionOperation.swift +75 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/TrackPurchaseActionOperation.swift +81 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/UnregisterDeviceOperation.swift +64 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/UnregisterPushOperation.swift +72 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/UpdateDeviceOperationPatch.swift +57 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/UpdateDeviceOperationPut.swift +59 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/UpdateMessageOperation.swift +50 -0
- package/vendor/VibesPush/Sources/HTTP/Operations/VibesQueueOperation.swift +76 -0
- package/vendor/VibesPush/Sources/HTTP/ResourceResult.swift +38 -0
- package/vendor/VibesPush/Sources/HTTPURLResponse+cURL.swift +16 -0
- package/vendor/VibesPush/Sources/InboxMessage.swift +219 -0
- package/vendor/VibesPush/Sources/Info.plist +26 -0
- package/vendor/VibesPush/Sources/InputStream+readToString.swift +19 -0
- package/vendor/VibesPush/Sources/KeychainStorage.swift +64 -0
- package/vendor/VibesPush/Sources/LocalObject.swift +25 -0
- package/vendor/VibesPush/Sources/LocalStorageKeys.swift +19 -0
- package/vendor/VibesPush/Sources/LocalStorageType.swift +47 -0
- package/vendor/VibesPush/Sources/LocalValue.swift +67 -0
- package/vendor/VibesPush/Sources/PersistentEventStorage.swift +81 -0
- package/vendor/VibesPush/Sources/Person.swift +98 -0
- package/vendor/VibesPush/Sources/Product.swift +103 -0
- package/vendor/VibesPush/Sources/Purchase.swift +108 -0
- package/vendor/VibesPush/Sources/TrackedEventType.swift +48 -0
- package/vendor/VibesPush/Sources/URLRequest+cURL.swift +36 -0
- package/vendor/VibesPush/Sources/UserDefaultsStorage.swift +32 -0
- package/vendor/VibesPush/Sources/Vibes.swift +1069 -0
- package/vendor/VibesPush/Sources/VibesAPI.swift +81 -0
- package/vendor/VibesPush/Sources/VibesAPIDelegate.swift +41 -0
- package/vendor/VibesPush/Sources/VibesAppInfo.swift +77 -0
- package/vendor/VibesPush/Sources/VibesConfiguration.swift +108 -0
- package/vendor/VibesPush/Sources/VibesLogger.swift +65 -0
- package/vendor/VibesPush/Sources/VibesResult.swift +78 -0
- package/vibes-react-native.podspec +6 -2
package/ios/Vibes.swift
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import Foundation
|
|
2
2
|
import UserNotifications
|
|
3
|
-
import VibesPush
|
|
4
3
|
|
|
5
4
|
@objc(Vibes)
|
|
6
|
-
class
|
|
5
|
+
class VibesModule: NSObject, RCTBridgeModule, VibesAPIDelegate {
|
|
7
6
|
static func moduleName() -> String! {
|
|
8
7
|
return "Vibes"
|
|
9
8
|
}
|
|
@@ -12,7 +11,7 @@ class Vibes: NSObject, RCTBridgeModule, VibesPush.VibesAPIDelegate {
|
|
|
12
11
|
|
|
13
12
|
let userDefaults = UserDefaults.standard
|
|
14
13
|
|
|
15
|
-
var vibes:
|
|
14
|
+
var vibes: Vibes
|
|
16
15
|
var registerDeviceResolver: RCTPromiseResolveBlock?
|
|
17
16
|
var registerDeviceRejecter: RCTPromiseRejectBlock?
|
|
18
17
|
var unregisterDeviceResolver: RCTPromiseResolveBlock?
|
package/ios/VibesClient.swift
CHANGED
|
@@ -6,13 +6,12 @@
|
|
|
6
6
|
// Copyright © 2022 Facebook. All rights reserved.
|
|
7
7
|
//
|
|
8
8
|
|
|
9
|
-
import VibesPush
|
|
10
9
|
|
|
11
10
|
@objcMembers
|
|
12
11
|
class VibesClient: NSObject {
|
|
13
12
|
static let standard = VibesClient()
|
|
14
13
|
|
|
15
|
-
public let vibes:
|
|
14
|
+
public let vibes: Vibes
|
|
16
15
|
public var logger: VibesLogger? = VibesPluginLogger.shared
|
|
17
16
|
|
|
18
17
|
override private init() {
|
|
@@ -29,7 +28,7 @@ class VibesClient: NSObject {
|
|
|
29
28
|
logger: logger,
|
|
30
29
|
storageType: .USERDEFAULTS)
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
vibes =
|
|
31
|
+
Vibes.configure(appId: appId, configuration: config)
|
|
32
|
+
vibes = Vibes.shared
|
|
34
33
|
}
|
|
35
34
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vibes-react-native",
|
|
3
|
-
"version": "5.0.1-
|
|
3
|
+
"version": "5.0.1-rc2",
|
|
4
4
|
"description": "The React Native plugin for the Vibes Mobile SDKs",
|
|
5
5
|
"author": "Vibes",
|
|
6
6
|
"main": "lib/commonjs/index",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"!ios/build",
|
|
21
21
|
"!**/__tests__",
|
|
22
22
|
"!**/__fixtures__",
|
|
23
|
-
"!**/__mocks__"
|
|
23
|
+
"!**/__mocks__",
|
|
24
|
+
"vendor"
|
|
24
25
|
],
|
|
25
26
|
"scripts": {
|
|
26
27
|
"test": "jest",
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
Copyright 2018 Vibes Media, LLC
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
/// A data structure to hold the `HTTPResource` defintions for the Vibes API.
|
|
3
|
+
///
|
|
4
|
+
/// A caseless enum is used in order to provide a namespace without allowing the
|
|
5
|
+
/// possibility of accidentally instantiating an instance of this Type.
|
|
6
|
+
enum APIDefinition {
|
|
7
|
+
/// A resource for registering a device with Vibes.
|
|
8
|
+
///
|
|
9
|
+
/// - parameters:
|
|
10
|
+
/// - appId: a unique ID, provided by Vibes, that identifies the account
|
|
11
|
+
/// - device: a `DeviceType` object with relevant device information to
|
|
12
|
+
/// record with Vibes
|
|
13
|
+
/// - Returns: The HttpResource
|
|
14
|
+
static func registerDevice(appId: String, device: DeviceType) -> HTTPResource<VibesCredential> {
|
|
15
|
+
return jsonResource(
|
|
16
|
+
path: "/\(appId)/devices",
|
|
17
|
+
method: .POST,
|
|
18
|
+
requestParameters: device.encodeJSON(),
|
|
19
|
+
parse: VibesCredential.init
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/// A resource for obtaining person information at Vibes. This is used to
|
|
24
|
+
/// retrieve person information.
|
|
25
|
+
///
|
|
26
|
+
/// - parameters:
|
|
27
|
+
/// - appId: a unique ID, provided by Vibes, that identifies the account
|
|
28
|
+
/// - deviceId: the vibes device id that uniquely identifies the device to
|
|
29
|
+
/// unregister
|
|
30
|
+
/// - Returns: The HttpResource
|
|
31
|
+
static func getPerson(appId: String, deviceId: String) -> HTTPResource<Person> {
|
|
32
|
+
return jsonResource(
|
|
33
|
+
path: "/\(appId)/devices/\(deviceId)/person",
|
|
34
|
+
method: .GET,
|
|
35
|
+
requestParameters: VibesJSONArray(),
|
|
36
|
+
parse: Person.init
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// A resource for updating a device with Vibes. This is used to save
|
|
41
|
+
/// the device location.
|
|
42
|
+
///
|
|
43
|
+
/// - parameters:
|
|
44
|
+
/// - appId: a unique ID, provided by Vibes, that identifies the account
|
|
45
|
+
/// - deviceId: the vibes device id that uniquely identifies the device to
|
|
46
|
+
/// unregister
|
|
47
|
+
/// - device: a `DeviceType` object with relevant device information to
|
|
48
|
+
/// record with Vibes
|
|
49
|
+
/// - Returns: The HttpResource
|
|
50
|
+
static func updateDeviceInfoPut(appId: String, deviceId: String, device: DeviceType) -> HTTPResource<VibesCredential> {
|
|
51
|
+
return jsonResource(
|
|
52
|
+
path: "/\(appId)/devices/\(deviceId)",
|
|
53
|
+
method: .PUT,
|
|
54
|
+
requestParameters: device.encodeJSON(),
|
|
55
|
+
parse: VibesCredential.init
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/// A resource for updating a device with Vibes. This is used to save
|
|
60
|
+
/// the device location.
|
|
61
|
+
///
|
|
62
|
+
/// - parameters:
|
|
63
|
+
/// - appId: a unique ID, provided by Vibes, that identifies the account
|
|
64
|
+
/// - deviceId: the vibes device id that uniquely identifies the device to
|
|
65
|
+
/// unregister
|
|
66
|
+
/// - device: a `DeviceType` object with relevant device information to
|
|
67
|
+
/// record with Vibes
|
|
68
|
+
/// - Returns: The HttpResource
|
|
69
|
+
static func updateDeviceInfoPatch(appId: String, deviceId: String, device: DeviceType) -> HTTPResource<Void> {
|
|
70
|
+
return jsonResource(
|
|
71
|
+
path: "/\(appId)/devices/\(deviceId)",
|
|
72
|
+
method: .PATCH,
|
|
73
|
+
requestParameters: device.encodeJSON(),
|
|
74
|
+
parse: noResult
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/// A resource for associating a device with an external person
|
|
79
|
+
///
|
|
80
|
+
/// - parameters:
|
|
81
|
+
/// - appId: a unique ID, provided by Vibes, that identifies the account
|
|
82
|
+
/// - deviceId: the vibes device id that uniquely identifies the device to associate
|
|
83
|
+
/// - externalPersonId: a string representation of the person identifier used by third parties,
|
|
84
|
+
/// stored by Vibes as `external_person_id`
|
|
85
|
+
/// - Returns: The HttpResource
|
|
86
|
+
static func associatePerson(appId: String, deviceId: String, externalPersonId: String) -> HTTPResource<Void> {
|
|
87
|
+
let personData = ["external_person_id": externalPersonId as AnyObject]
|
|
88
|
+
return jsonResource(
|
|
89
|
+
path: "/\(appId)/devices/\(deviceId)/assign",
|
|
90
|
+
method: .POST,
|
|
91
|
+
requestParameters: personData as VibesJSONDictionary,
|
|
92
|
+
parse: noResult
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/// A resource for unregistering a device with Vibes.
|
|
97
|
+
///
|
|
98
|
+
/// - parameters:
|
|
99
|
+
/// - appId: a unique ID, provided by Vibes, that identifies the account
|
|
100
|
+
/// - deviceId: the vibes device id that uniquely identifies the device to
|
|
101
|
+
/// unregister
|
|
102
|
+
/// - Returns: The HttpResource
|
|
103
|
+
static func unregisterDevice(appId: String, deviceId: String) -> HTTPResource<Void> {
|
|
104
|
+
return HTTPResource(
|
|
105
|
+
path: "/\(appId)/devices/\(deviceId)",
|
|
106
|
+
method: .DELETE,
|
|
107
|
+
parse: noResult
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/// A resource for registering this device for push notifications from Vibes.
|
|
112
|
+
///
|
|
113
|
+
/// - parameters:
|
|
114
|
+
/// - appId: a unique ID, provided by Vibes, that identifies the account
|
|
115
|
+
/// - deviceId: the vibes device id that uniquely identifies the device to
|
|
116
|
+
/// unregister
|
|
117
|
+
/// - pushToken: a unique token, provided by Apple, that identifies the
|
|
118
|
+
/// device
|
|
119
|
+
/// - Returns: The HttpResource
|
|
120
|
+
static func registerPush(appId: String, deviceId: String, pushToken: String) -> HTTPResource<Void> {
|
|
121
|
+
let deviceToken = DeviceToken(token: pushToken)
|
|
122
|
+
return jsonResource(
|
|
123
|
+
path: "/\(appId)/devices/\(deviceId)/push_registration",
|
|
124
|
+
method: .POST,
|
|
125
|
+
requestParameters: deviceToken.encodeJSON(),
|
|
126
|
+
parse: noResult
|
|
127
|
+
)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/// A resource for unregistering this device for push notifications from Vibes.
|
|
131
|
+
///
|
|
132
|
+
/// - parameters:
|
|
133
|
+
/// - appId: a unique ID, provided by Vibes, that identifies the account
|
|
134
|
+
/// - deviceId: the vibes device id that uniquely identifies the device to
|
|
135
|
+
/// unregister
|
|
136
|
+
/// - Returns: The HttpResource
|
|
137
|
+
static func unregisterPush(appId: String, deviceId: String) -> HTTPResource<Void> {
|
|
138
|
+
return HTTPResource(
|
|
139
|
+
path: "/\(appId)/devices/\(deviceId)/push_registration",
|
|
140
|
+
method: .DELETE,
|
|
141
|
+
parse: noResult
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/// A resource for tracking events with Vibes.
|
|
146
|
+
///
|
|
147
|
+
/// - parameters:
|
|
148
|
+
/// - appId: a unique ID, provided by Vibes, that identifies the account
|
|
149
|
+
/// - deviceId: the vibes device id that uniquely identifies this device
|
|
150
|
+
/// - events: the events to track
|
|
151
|
+
/// - Returns: The HttpResource
|
|
152
|
+
static func trackEvents(appId: String, deviceId: String, events: [Event]) -> HTTPResource<Void> {
|
|
153
|
+
let params: VibesJSONDictionary = [
|
|
154
|
+
"events": events.map { $0.encodeJSON() } as AnyObject,
|
|
155
|
+
]
|
|
156
|
+
|
|
157
|
+
return jsonResource(
|
|
158
|
+
path: "/\(appId)/devices/\(deviceId)/events",
|
|
159
|
+
method: .POST,
|
|
160
|
+
requestParameters: params,
|
|
161
|
+
headers: ["X-Event-Type": events.first?.type ?? "event"],
|
|
162
|
+
parse: noResult
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/// Tracks an action linked to ecommerce activity on a product
|
|
167
|
+
///
|
|
168
|
+
/// - Parameters:
|
|
169
|
+
/// - action: the type of `ProductAction`
|
|
170
|
+
/// - product: the product being tracked.
|
|
171
|
+
/// - data: Tracking data for making tracking call.
|
|
172
|
+
/// - activityUid: Optional activityUid in case user wants to override the one stored in local storage.
|
|
173
|
+
/// - Returns: HTTPResource
|
|
174
|
+
static func trackProductAction(action: ProductAction, product: Product, data: VibesTrackingData, activityUid: String?) -> HTTPResource<Void> {
|
|
175
|
+
var theActivityUID = activityUid
|
|
176
|
+
if let activityUid = activityUid,
|
|
177
|
+
!activityUid.isEmpty {
|
|
178
|
+
theActivityUID = activityUid
|
|
179
|
+
} else {
|
|
180
|
+
theActivityUID = data["activity_uid"] as? String
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
var resource = jsonResource(
|
|
184
|
+
path: "",
|
|
185
|
+
method: .GET,
|
|
186
|
+
requestParameters: [:],
|
|
187
|
+
parse: noResult
|
|
188
|
+
)
|
|
189
|
+
resource.baseURL = APIDefinition.createTrackingURL(theActivityUID: theActivityUID,
|
|
190
|
+
data: data,
|
|
191
|
+
action: action,
|
|
192
|
+
product: product)
|
|
193
|
+
return resource
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/// Tracks an action linked to ecommerce activity on a Purchase
|
|
197
|
+
///
|
|
198
|
+
/// - Parameters:
|
|
199
|
+
/// - action: the type of `PurchaseAction`
|
|
200
|
+
/// - data: Tracking data for making tracking call.
|
|
201
|
+
/// - activityUid: Optional activityUid in case user wants to override the one stored in local storage.
|
|
202
|
+
/// - Returns: HTTPResource
|
|
203
|
+
static func trackPurchaseAction(action: PurchaseAction, purchase: Purchase, data: VibesTrackingData, activityUid: String?) -> HTTPResource<Void> {
|
|
204
|
+
var theActivityUID = activityUid
|
|
205
|
+
if let activityUid = activityUid,
|
|
206
|
+
!activityUid.isEmpty {
|
|
207
|
+
theActivityUID = activityUid
|
|
208
|
+
} else {
|
|
209
|
+
theActivityUID = data["activity_uid"] as? String
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
var resource = jsonResource(
|
|
213
|
+
path: "",
|
|
214
|
+
method: .GET,
|
|
215
|
+
requestParameters: [:],
|
|
216
|
+
parse: noResult
|
|
217
|
+
)
|
|
218
|
+
resource.baseURL = APIDefinition.createTrackingURL(theActivityUID: theActivityUID,
|
|
219
|
+
data: data,
|
|
220
|
+
action: action,
|
|
221
|
+
purchase: purchase)
|
|
222
|
+
return resource
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
static func createTrackingURL(theActivityUID: String?, data: VibesTrackingData, action: PurchaseAction, purchase: Purchase) -> URL {
|
|
226
|
+
let payload: VibesJSONDictionary = [
|
|
227
|
+
"activityId": theActivityUID as AnyObject,
|
|
228
|
+
"personId": data["person_key"] as AnyObject,
|
|
229
|
+
"action": action.rawValue as AnyObject,
|
|
230
|
+
"companyId": data["company_key"] as AnyObject,
|
|
231
|
+
"data": purchase.attributes as AnyObject,
|
|
232
|
+
]
|
|
233
|
+
|
|
234
|
+
let qStr = "[\(payload.jsonStringRepresentation!)]".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
|
|
235
|
+
return URL(string: Vibes.shared.configuration.trackingApiUrl + "?d=\(qStr!)")!
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
static func createTrackingURL(theActivityUID: String?, data: VibesTrackingData, action: ProductAction, product: Product) -> URL {
|
|
239
|
+
let payload: VibesJSONDictionary = [
|
|
240
|
+
"activityId": theActivityUID as AnyObject,
|
|
241
|
+
"personId": data["person_key"] as AnyObject,
|
|
242
|
+
"action": action.rawValue as AnyObject,
|
|
243
|
+
"companyId": data["company_key"] as AnyObject,
|
|
244
|
+
"data": product.attributes as AnyObject,
|
|
245
|
+
]
|
|
246
|
+
|
|
247
|
+
let qStr = "[\(payload.jsonStringRepresentation!)]".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
|
|
248
|
+
return URL(string: Vibes.shared.configuration.trackingApiUrl + "?d=\(qStr!)")!
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/// A resource for retrieving Git Tags
|
|
252
|
+
///
|
|
253
|
+
/// - Returns: The HttpResource
|
|
254
|
+
static func getGitTags() -> HTTPResource<[GitTag]> {
|
|
255
|
+
var resource: HTTPResource<[GitTag]> = jsonResources(
|
|
256
|
+
path: "/tags",
|
|
257
|
+
method: .GET,
|
|
258
|
+
requestParameters: VibesJSONDictionary(),
|
|
259
|
+
headers: ["Accept": "application/vnd.github.v3+json"],
|
|
260
|
+
parse: fromJSONArray
|
|
261
|
+
)
|
|
262
|
+
resource.baseURL = URL(string: "https://api.github.com/repos/vibes/push-sdk-ios")
|
|
263
|
+
return resource
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/// A resource for retrieving a single inbox message
|
|
267
|
+
///
|
|
268
|
+
/// - Parameters:
|
|
269
|
+
/// - appId: a unique ID, provided by Vibes, that identifies the account
|
|
270
|
+
/// - personKey: The Alphanumeric person key
|
|
271
|
+
/// - messageUID: The Alphanumeric message UID
|
|
272
|
+
/// - Returns: The HttpResource
|
|
273
|
+
static func getInboxMessage(appId: String, personKey: String, messageUID: String) -> HTTPResource<InboxMessage> {
|
|
274
|
+
return jsonResource(
|
|
275
|
+
path: "/\(appId)/persons/\(personKey)/messages/\(messageUID)",
|
|
276
|
+
method: .GET,
|
|
277
|
+
requestParameters: VibesJSONDictionary(),
|
|
278
|
+
parse: InboxMessage.init
|
|
279
|
+
)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/// A resource for retrieving inbox messages
|
|
283
|
+
///
|
|
284
|
+
/// - Parameters:
|
|
285
|
+
/// - appId: a unique ID, provided by Vibes, that identifies the account
|
|
286
|
+
/// - personKey: The Alphanumeric person key
|
|
287
|
+
/// - Returns: The HttpResource
|
|
288
|
+
static func getInboxMessages(appId: String, personKey: String) -> HTTPResource<[InboxMessage]> {
|
|
289
|
+
return jsonResources(
|
|
290
|
+
path: "/\(appId)/persons/\(personKey)/messages",
|
|
291
|
+
method: .GET,
|
|
292
|
+
requestParameters: VibesJSONDictionary(),
|
|
293
|
+
parse: fromJSONArray
|
|
294
|
+
)
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/// A resource for updating inbox messages
|
|
298
|
+
///
|
|
299
|
+
/// - Parameters:
|
|
300
|
+
/// - appId: a unique ID, provided by Vibes, that identifies the account
|
|
301
|
+
/// - personKey: The Alphanumeric person key
|
|
302
|
+
/// - messageUID: The Alphanumeric messge UID
|
|
303
|
+
/// - Returns: The HttpResource
|
|
304
|
+
static func updateMessage(appId: String, personKey: String, messageUID: String, payload: VibesJSONDictionary) -> HTTPResource<InboxMessage> {
|
|
305
|
+
return jsonResource(
|
|
306
|
+
path: "/\(appId)/persons/\(personKey)/messages/\(messageUID)",
|
|
307
|
+
method: .PUT,
|
|
308
|
+
requestParameters: payload,
|
|
309
|
+
parse: InboxMessage.init
|
|
310
|
+
)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
static func fetchVibesAppInfo(appId: String) -> HTTPResource<VibesAppInfo> {
|
|
314
|
+
return jsonResource(
|
|
315
|
+
path: "/\(appId)",
|
|
316
|
+
method: .GET,
|
|
317
|
+
requestParameters: VibesJSONDictionary(),
|
|
318
|
+
parse: VibesAppInfo.init
|
|
319
|
+
)
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/// A resource to triggers silent push migration callback
|
|
323
|
+
///
|
|
324
|
+
/// - Parameters:
|
|
325
|
+
/// - appId: a unique ID, provided by Vibes, that identifies the account
|
|
326
|
+
/// - migrationItemId: The migration item Id
|
|
327
|
+
/// - vibesDeviceId: Vibes Device Id
|
|
328
|
+
///
|
|
329
|
+
/// - Returns: The HttpResource
|
|
330
|
+
static func migrationCallback(appId: String, migrationItemId: String, vibesDeviceId: String) -> HTTPResource<Void> {
|
|
331
|
+
let payload: VibesJSONDictionary = [
|
|
332
|
+
"migration_item_id": migrationItemId as AnyObject,
|
|
333
|
+
"vibes_device_id": vibesDeviceId as AnyObject,
|
|
334
|
+
]
|
|
335
|
+
return jsonResource(
|
|
336
|
+
path: "/\(appId)/migrations/callbacks",
|
|
337
|
+
method: .PUT,
|
|
338
|
+
requestParameters: payload,
|
|
339
|
+
parse: noResult
|
|
340
|
+
)
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/// A generic utility function for creating an `HTTPResource` that expects to
|
|
344
|
+
/// send and receive JSON.
|
|
345
|
+
///
|
|
346
|
+
/// - parameters:
|
|
347
|
+
/// - path: the path for this resource, e.g. "/devices"
|
|
348
|
+
/// - method: the HTTP method for this resource, e.g. .DELETE
|
|
349
|
+
/// - requestParameters: the JSON object to send with this request
|
|
350
|
+
/// - headers: an optional list of headers for the resource. `Content-Type`
|
|
351
|
+
/// and `Accept` headers will automatically be added in.
|
|
352
|
+
/// - parse: a closure that dictates how to map the received JSON (not Data)
|
|
353
|
+
/// into an instance of `A`.
|
|
354
|
+
private static func jsonResource<A>(path: String,
|
|
355
|
+
method: HTTPMethod,
|
|
356
|
+
requestParameters: VibesJSONDictionary = [:],
|
|
357
|
+
headers: [String: String] = [:],
|
|
358
|
+
parse: @escaping (VibesJSONDictionary) -> A?) -> HTTPResource<A> {
|
|
359
|
+
let parser = JSONParser()
|
|
360
|
+
let jsonBody = parser.encode(requestParameters)
|
|
361
|
+
|
|
362
|
+
return commonJsonResource(path: path, method: method, jsonBody: jsonBody, headers: headers, parse: parse)
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/// A generic utility function for creating an `HTTPResource` that expects to
|
|
366
|
+
/// send and receive JSON.
|
|
367
|
+
///
|
|
368
|
+
/// - parameters:
|
|
369
|
+
/// - path: the path for this resource, e.g. "/devices"
|
|
370
|
+
/// - method: the HTTP method for this resource, e.g. .DELETE
|
|
371
|
+
/// - requestParameters: the JSON object to send with this request
|
|
372
|
+
/// - headers: an optional list of headers for the resource. `Content-Type`
|
|
373
|
+
/// and `Accept` headers will automatically be added in.
|
|
374
|
+
/// - parse: a closure that dictates how to map the received JSON (not Data)
|
|
375
|
+
/// into an instance of `[A]`.
|
|
376
|
+
private static func jsonResources<A>(path: String,
|
|
377
|
+
method: HTTPMethod,
|
|
378
|
+
requestParameters: VibesJSONDictionary = [:],
|
|
379
|
+
headers: [String: String] = [:],
|
|
380
|
+
parse: @escaping (VibesJSONArray) -> [A]) -> HTTPResource<[A]> {
|
|
381
|
+
let parser = JSONParser()
|
|
382
|
+
let jsonBody = parser.encode(requestParameters)
|
|
383
|
+
|
|
384
|
+
return commonJsonResources(path: path, method: method, jsonBody: jsonBody, headers: headers, parse: parse)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/// A generic utility function for creating an `HTTPResource` that expects to
|
|
388
|
+
/// send and receive JSON.
|
|
389
|
+
///
|
|
390
|
+
/// - parameters:
|
|
391
|
+
/// - path: the path for this resource, e.g. "/devices"
|
|
392
|
+
/// - method: the HTTP method for this resource, e.g. .DELETE
|
|
393
|
+
/// - requestParameters: the JSON array to send with this request
|
|
394
|
+
/// - headers: an optional list of headers for the resource. `Content-Type`
|
|
395
|
+
/// and `Accept` headers will automatically be added in.
|
|
396
|
+
/// - parse: a closure that dictates how to map the received JSON (not Data)
|
|
397
|
+
/// into an instance of `A`.
|
|
398
|
+
private static func jsonResource<A>(path: String,
|
|
399
|
+
method: HTTPMethod,
|
|
400
|
+
requestParameters: VibesJSONArray = [],
|
|
401
|
+
headers: [String: String] = [:],
|
|
402
|
+
parse: @escaping (VibesJSONDictionary) -> A?) -> HTTPResource<A> {
|
|
403
|
+
let parser = JSONParser()
|
|
404
|
+
let jsonBody = parser.encode(requestParameters)
|
|
405
|
+
return commonJsonResource(path: path, method: method, jsonBody: jsonBody, headers: headers, parse: parse)
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/// A generic helper for creating an `HTTPResource` that expects to send and
|
|
409
|
+
/// receive JSON.
|
|
410
|
+
///
|
|
411
|
+
/// - parameters:
|
|
412
|
+
/// - path: the path for this resource, e.g. "/devices"
|
|
413
|
+
/// - method: the HTTP method for this resource, e.g. .DELETE
|
|
414
|
+
/// - jsonBody: JSON, encoded as Data
|
|
415
|
+
/// - headers: an optional list of headers for the resource. `Content-Type`
|
|
416
|
+
/// and `Accept` headers will automatically be added in.
|
|
417
|
+
/// - parse: a closure that dictates how to map the received JSON (not Data)
|
|
418
|
+
/// into an instance of `A`.
|
|
419
|
+
private static func commonJsonResource<A>(path: String,
|
|
420
|
+
method: HTTPMethod,
|
|
421
|
+
jsonBody: Data?,
|
|
422
|
+
headers: [String: String] = [:],
|
|
423
|
+
parse: @escaping (VibesJSONDictionary) -> A?) -> HTTPResource<A> {
|
|
424
|
+
let parser = JSONParser()
|
|
425
|
+
|
|
426
|
+
// Creates a function that parses `Data` into a `JSONDictionary`, and then
|
|
427
|
+
// passes that dictionary on to the custom `parse` function to create an
|
|
428
|
+
// instance of our `A` type
|
|
429
|
+
let parseWrapper: (Data) -> A? = { data in
|
|
430
|
+
guard let dict = parser.decode(data: data) else { return nil }
|
|
431
|
+
return parse(dict)
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
let headers = headers.merged(with: ["Content-Type": "application/json", "Accept": "application/json"])
|
|
435
|
+
|
|
436
|
+
return HTTPResource(path: path, method: method, requestBody: jsonBody, headers: headers, parse: parseWrapper)
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/// A generic helper for creating an `HTTPResource` that expects to send and
|
|
440
|
+
/// receive JSON.
|
|
441
|
+
///
|
|
442
|
+
/// - parameters:
|
|
443
|
+
/// - path: the path for this resource, e.g. "/devices"
|
|
444
|
+
/// - method: the HTTP method for this resource, e.g. .DELETE
|
|
445
|
+
/// - jsonBody: JSON, encoded as Data
|
|
446
|
+
/// - headers: an optional list of headers for the resource. `Content-Type`
|
|
447
|
+
/// and `Accept` headers will automatically be added in.
|
|
448
|
+
/// - parse: a closure that dictates how to map the received JSON (not Data)
|
|
449
|
+
/// into an instance of `[A]`.
|
|
450
|
+
private static func commonJsonResources<A>(path: String,
|
|
451
|
+
method: HTTPMethod,
|
|
452
|
+
jsonBody: Data?,
|
|
453
|
+
headers: [String: String] = [:],
|
|
454
|
+
parse: @escaping (VibesJSONArray) -> [A]) -> HTTPResource<[A]> {
|
|
455
|
+
let parser = JSONParser()
|
|
456
|
+
|
|
457
|
+
// Creates a function that parses `Data` into a `JSONArray`, and then
|
|
458
|
+
// passes that dictionary on to the custom `parse` function to create an
|
|
459
|
+
// instance of our `[A]` type
|
|
460
|
+
let parseWrapper: (Data) -> [A]? = { data in
|
|
461
|
+
guard let array = parser.decodeJSONArray(data: data) else { return nil }
|
|
462
|
+
return parse(array)
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
let headers = headers.merged(with: ["Content-Type": "application/json", "Accept": "application/json"])
|
|
466
|
+
|
|
467
|
+
return HTTPResource(path: path, method: method, requestBody: jsonBody, headers: headers, parse: parseWrapper)
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/// A helper function for when there is no expected response data.
|
|
471
|
+
private static func noResult(data: Data) {
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
/// A helper function for when there is no expected response JSON.
|
|
475
|
+
private static func noResult(json: VibesJSONDictionary) {
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/// A convenience initializer for decoding a JSONArray into their Array Types.
|
|
479
|
+
///
|
|
480
|
+
/// - parameters:
|
|
481
|
+
/// - jsonArray: the JSON Array to encode into data
|
|
482
|
+
private static func fromJSONArray<T: JSONDecodable>(jsonArray: VibesJSONArray) -> [T] {
|
|
483
|
+
var result: [T] = [T]()
|
|
484
|
+
for json in jsonArray {
|
|
485
|
+
if let object = T(json: json) {
|
|
486
|
+
result.append(object)
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
return result
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
extension Dictionary {
|
|
494
|
+
var jsonStringRepresentation: String? {
|
|
495
|
+
guard let theJSONData = try? JSONSerialization.data(withJSONObject: self,
|
|
496
|
+
options: [.prettyPrinted]) else {
|
|
497
|
+
return nil
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
return String(data: theJSONData, encoding: .utf8)
|
|
501
|
+
}
|
|
502
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//
|
|
2
|
+
// ProductActions.swift
|
|
3
|
+
// VibesPush
|
|
4
|
+
//
|
|
5
|
+
// Created by Moin' Victor on 11/08/2022.
|
|
6
|
+
// Copyright © 2022 Vibes. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
|
|
11
|
+
public enum ProductAction: String {
|
|
12
|
+
case click
|
|
13
|
+
case detail
|
|
14
|
+
case add
|
|
15
|
+
case remove
|
|
16
|
+
case checkout
|
|
17
|
+
case checkoutOption = "checkout_option"
|
|
18
|
+
case promoClick = "promo_click"
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public enum PurchaseAction: String {
|
|
22
|
+
case purchase
|
|
23
|
+
case refund
|
|
24
|
+
}
|