vibes-react-native 5.0.0 → 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 +2 -5
- 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
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
//
|
|
2
|
+
// BackendOperation.swift
|
|
3
|
+
// VibesPush-iOS
|
|
4
|
+
//
|
|
5
|
+
// Created by Jean-Michel Barbieri on 2/21/18.
|
|
6
|
+
// Copyright © 2018 Vibes. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
struct VibesQueueConstant {
|
|
11
|
+
static let NONE = ""
|
|
12
|
+
static let MAX_RETRY = 3
|
|
13
|
+
static let MAX_SEC: UInt32 = 15
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
internal class BaseOperation<A>: VibesQueueOperation {
|
|
17
|
+
internal var credentialManager: CredentialManager
|
|
18
|
+
fileprivate let api: VibesAPIType
|
|
19
|
+
fileprivate let advertisingId: String
|
|
20
|
+
fileprivate let appId: String
|
|
21
|
+
fileprivate let MAX_SEC = 15
|
|
22
|
+
|
|
23
|
+
/// Initialize this object
|
|
24
|
+
///
|
|
25
|
+
/// - parameters:
|
|
26
|
+
/// - credentialManager: an object to store credentials, keeping track of the current Credential..
|
|
27
|
+
/// - api: an object that allows talking to the Vibes API
|
|
28
|
+
/// - advertisingId: AdSupport.advertisingId
|
|
29
|
+
/// - appId: the application ID provided by Vibes to identify this application
|
|
30
|
+
init(credentials: CredentialManager,
|
|
31
|
+
api: VibesAPIType,
|
|
32
|
+
advertisingId: String,
|
|
33
|
+
appId: String) {
|
|
34
|
+
self.credentialManager = credentials
|
|
35
|
+
self.api = api
|
|
36
|
+
self.advertisingId = advertisingId
|
|
37
|
+
self.appId = appId
|
|
38
|
+
|
|
39
|
+
super.init()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/// If the auth token expires (error 401), this method is called before retrying to execute the failing request.
|
|
43
|
+
/// It requests a new auth token, and if the call is successful, store it locally in the keychain.
|
|
44
|
+
/// - parameters:
|
|
45
|
+
/// - completion: a handler for receiving the result of updating the auth token
|
|
46
|
+
fileprivate func updateDeviceToken(completion: @escaping VibesCompletion<VibesCredential>) {
|
|
47
|
+
guard let credential = credentialManager.currentCredential else {
|
|
48
|
+
// Should never be the case as we check credential for every request except reg_device
|
|
49
|
+
completion(VibesResult<VibesCredential>.failure(.noCredentials))
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
let device = Device(advertisingIdentifier: self.advertisingId)
|
|
53
|
+
let resource = APIDefinition.updateDeviceInfoPut(appId: self.appId, deviceId: credential.deviceId, device: device)
|
|
54
|
+
|
|
55
|
+
self.api.request(authToken: credential.authToken, resource: resource) {[weak self] apiResult in
|
|
56
|
+
if case .success(let credential) = apiResult {
|
|
57
|
+
self?.credentialManager.currentCredential = credential
|
|
58
|
+
// after updating token, we want to delay before retrying, just so we are sure the token update to storage has happened.
|
|
59
|
+
self?.delayWithSeconds(0.5, completion: {
|
|
60
|
+
completion(VibesResult<VibesCredential>(apiResult))
|
|
61
|
+
})
|
|
62
|
+
} else {
|
|
63
|
+
completion(VibesResult<VibesCredential>(apiResult))
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
func delayWithSeconds(_ seconds: Double, completion: @escaping () -> ()) {
|
|
69
|
+
DispatchQueue.main.asyncAfter(deadline: .now() + seconds) {
|
|
70
|
+
completion()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/// Validate that credentials aren't nil
|
|
75
|
+
/// - returns:
|
|
76
|
+
/// - VibesError: .noCredential if currentCredential are nil
|
|
77
|
+
func validateOperation() -> VibesError? {
|
|
78
|
+
if self.credentialManager.currentCredential == nil {
|
|
79
|
+
return .noCredentials
|
|
80
|
+
}
|
|
81
|
+
return nil
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/// Whether to inject the auth header, override and return false to disable `Authorization` header in the request
|
|
85
|
+
/// - Returns: `true` or `false`
|
|
86
|
+
func injectAuthHeader() -> Bool {
|
|
87
|
+
return true
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/// Method called to execute a new http request. The request might be first added to a queue. This persisted queue
|
|
91
|
+
/// will be reexecuted later on, if for instance a request is failing, even after several attempts.
|
|
92
|
+
/// Between each request attempt, there is a delay of several seconds (random(15s))
|
|
93
|
+
/// - parameters:
|
|
94
|
+
/// - type: the request type (ex: REG_DEVICE, REG_PUSH ...)
|
|
95
|
+
/// - retry: Number of retry if the request is failing. By default, if no value is provided, the retry == 2
|
|
96
|
+
/// - resource: The resource to request
|
|
97
|
+
/// - completion: Completion block executed after the request execution.
|
|
98
|
+
internal func execute<A>(retry: Int = VibesQueueConstant.MAX_RETRY,
|
|
99
|
+
resource: @escaping () -> HTTPResource<A>,
|
|
100
|
+
completion: @escaping VibesCompletion<A>) {
|
|
101
|
+
if let error = validateOperation() {
|
|
102
|
+
completion(VibesResult.failure(error))
|
|
103
|
+
self.finish()
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
let retry = (retry > VibesQueueConstant.MAX_RETRY) ? VibesQueueConstant.MAX_RETRY : retry
|
|
107
|
+
// if the auth_token is nil, 'Authorization' is not injected in the header (see class AuthTokenBehavior)
|
|
108
|
+
let authToken = self.injectAuthHeader() ? self.credentialManager.currentCredential?.authToken : nil
|
|
109
|
+
self.api.request(authToken: authToken, resource: resource()) {[weak self] initialResult in
|
|
110
|
+
// Check for Token expiration error. If so, this piece of code get a new auth_token and retry the request.
|
|
111
|
+
guard let _self = self else { return }
|
|
112
|
+
|
|
113
|
+
func doRetry() {
|
|
114
|
+
guard retry == 0 else {
|
|
115
|
+
// When run in a unit Test, DispatchQueue.asynAfter... throws an exception.
|
|
116
|
+
if Vibes.isRunningThroughUnitTest {
|
|
117
|
+
self?.execute(retry: retry - 1, resource: resource, completion: completion)
|
|
118
|
+
} else {
|
|
119
|
+
let randomDelay = Int(arc4random_uniform(VibesQueueConstant.MAX_SEC))
|
|
120
|
+
DispatchQueue.global(qos: .background).asyncAfter(deadline: .now() + .seconds(randomDelay)) {
|
|
121
|
+
self?.execute(retry: retry - 1, resource: resource, completion: completion)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return
|
|
125
|
+
}
|
|
126
|
+
let vibesResult = VibesResult<A>(initialResult)
|
|
127
|
+
completion(vibesResult)
|
|
128
|
+
_self.finish()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
switch initialResult {
|
|
132
|
+
case .failure(.unauthorized):
|
|
133
|
+
_self.updateDeviceToken(completion: { updateResult in
|
|
134
|
+
switch updateResult {
|
|
135
|
+
case .success:
|
|
136
|
+
_self.execute(retry: retry, resource: resource, completion: completion)
|
|
137
|
+
case .failure(let error):
|
|
138
|
+
completion(VibesResult<A>.failure(error))
|
|
139
|
+
_self.finish()
|
|
140
|
+
}
|
|
141
|
+
})
|
|
142
|
+
case .failure(.unreachable):
|
|
143
|
+
doRetry()
|
|
144
|
+
case .failure(.invalidResponse(let statusCode, _)) where statusCode.isStatusCodeForRetryableServerError():
|
|
145
|
+
doRetry()
|
|
146
|
+
default:
|
|
147
|
+
let vibesResult = VibesResult<A>(initialResult)
|
|
148
|
+
completion(vibesResult)
|
|
149
|
+
_self.finish()
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
//
|
|
2
|
+
// EventOperation.swift
|
|
3
|
+
// VibesPush-iOS
|
|
4
|
+
//
|
|
5
|
+
// Created by Jean-Michel Barbieri on 2/21/18.
|
|
6
|
+
// Copyright © 2018 Vibes. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
internal class EventOperation: BaseOperation<[Event]> {
|
|
10
|
+
fileprivate let completion: VibesCompletion<[Event]>?
|
|
11
|
+
fileprivate let resource: () -> HTTPResource<Void>
|
|
12
|
+
fileprivate let outgoingEvents: [Event]
|
|
13
|
+
fileprivate let trackCompletion: (VibesResult<Void>) -> Void?
|
|
14
|
+
|
|
15
|
+
/// Initialize this object
|
|
16
|
+
///
|
|
17
|
+
/// - parameters:
|
|
18
|
+
/// - credentialManager: an object to store credentials, keeping track of the current Credential..
|
|
19
|
+
/// - api: an object that allows talking to the Vibes API
|
|
20
|
+
/// - advertisingId: AdSupport.advertisingId
|
|
21
|
+
/// - appId: the application ID provided by Vibes to identify this application
|
|
22
|
+
/// - completion: Vibes completion block executed by BaseOperation when the request is finished.
|
|
23
|
+
/// - outgoingEvents: contains the list of event to send
|
|
24
|
+
/// - trackCompletion: Completion block for the tracking system
|
|
25
|
+
public init(credentials: CredentialManager,
|
|
26
|
+
api: VibesAPIType,
|
|
27
|
+
advertisingId: String,
|
|
28
|
+
appId: String,
|
|
29
|
+
completion: VibesCompletion<[Event]>?,
|
|
30
|
+
outgoingEvents: [Event],
|
|
31
|
+
trackCompletion: @escaping (VibesResult<Void>) -> Void?) {
|
|
32
|
+
self.completion = completion
|
|
33
|
+
self.outgoingEvents = outgoingEvents
|
|
34
|
+
self.trackCompletion = trackCompletion
|
|
35
|
+
self.resource = {
|
|
36
|
+
let deviceId = credentials.currentCredential?.deviceId ?? VibesQueueConstant.NONE
|
|
37
|
+
return APIDefinition.trackEvents(appId: appId, deviceId: deviceId, events: outgoingEvents)
|
|
38
|
+
}
|
|
39
|
+
super.init(credentials: credentials, api: api, advertisingId: advertisingId, appId: appId)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/// Validate that the event are present and that the event sending concerns only one type.
|
|
43
|
+
/// Super will validate that credential exist.
|
|
44
|
+
/// - returns:
|
|
45
|
+
/// - VibesError: nullable error
|
|
46
|
+
override func validateOperation() -> VibesError? {
|
|
47
|
+
guard outgoingEvents.first != nil else {
|
|
48
|
+
completion?(.failure(.noEvents))
|
|
49
|
+
return .noEvents
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
guard Set(outgoingEvents.map { $0.type }).count == 1 else {
|
|
53
|
+
completion?(.failure(.tooManyEventTypes))
|
|
54
|
+
return .tooManyEventTypes
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return super.validateOperation()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/// Execute the operation
|
|
61
|
+
override func start() {
|
|
62
|
+
super.start()
|
|
63
|
+
super.execute(retry: 0, resource: resource) {[weak self] result in
|
|
64
|
+
switch result {
|
|
65
|
+
case .success:
|
|
66
|
+
self?.trackCompletion(VibesResult.success(()))
|
|
67
|
+
self?.completion?(VibesResult.success((self?.outgoingEvents)!))
|
|
68
|
+
case .failure(let error):
|
|
69
|
+
self?.completion?(VibesResult.failure(error))
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
//
|
|
2
|
+
// GetGitTagsOperation.swift
|
|
3
|
+
// VibesPush
|
|
4
|
+
//
|
|
5
|
+
// Created by Moin' Victor on 15/09/2020.
|
|
6
|
+
// Copyright © 2020 Vibes. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
|
|
11
|
+
/// Get Git Tags Operation
|
|
12
|
+
internal class GetGitTagsOperation: BaseOperation<GitTag> {
|
|
13
|
+
fileprivate let storage: LocalStorageType
|
|
14
|
+
fileprivate let resource: () -> HTTPResource<[GitTag]>
|
|
15
|
+
fileprivate var callback: GetGitTagsCallback
|
|
16
|
+
|
|
17
|
+
/// Completion handler responsible for notifying the caller
|
|
18
|
+
fileprivate lazy var completionHandler: VibesCompletion<[GitTag]> = { [weak self] result in
|
|
19
|
+
switch result {
|
|
20
|
+
case let .success(tags):
|
|
21
|
+
self?.callback(tags, nil)
|
|
22
|
+
case let .failure(error):
|
|
23
|
+
self?.callback([], error)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// Initialize this object
|
|
28
|
+
///
|
|
29
|
+
/// - parameters:
|
|
30
|
+
/// - credentialManager: an object to store credentials, keeping track of the current Credential..
|
|
31
|
+
/// - storage: an object that allows storing data locally
|
|
32
|
+
/// - api: an object that allows talking to the Vibes API
|
|
33
|
+
/// - advertisingId: AdSupport.advertisingId
|
|
34
|
+
/// - appId: the application ID provided by Vibes to identify this application
|
|
35
|
+
/// - callback: GetGitTagsCallback ([GitTag]], Error?)
|
|
36
|
+
public init(credentials: CredentialManager,
|
|
37
|
+
storage: LocalStorageType,
|
|
38
|
+
api: VibesAPIType,
|
|
39
|
+
advertisingId: String,
|
|
40
|
+
appId: String,
|
|
41
|
+
callback: @escaping GetGitTagsCallback) {
|
|
42
|
+
self.callback = callback
|
|
43
|
+
self.storage = storage
|
|
44
|
+
resource = {
|
|
45
|
+
APIDefinition.getGitTags()
|
|
46
|
+
}
|
|
47
|
+
super.init(credentials: credentials, api: api, advertisingId: advertisingId, appId: appId)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// Override BaseOperation validateOperation: For this request we don't want to check
|
|
51
|
+
/// if the credentials exists.
|
|
52
|
+
override func validateOperation() -> VibesError? {
|
|
53
|
+
return nil
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/// Execute the operation
|
|
57
|
+
override func start() {
|
|
58
|
+
super.start()
|
|
59
|
+
super.execute(resource: resource, completion: completionHandler)
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//
|
|
2
|
+
// GetInboxMessageOperation.swift
|
|
3
|
+
// VibesPush-iOS
|
|
4
|
+
//
|
|
5
|
+
// Created by Moin' Victor on 22/10/2019.
|
|
6
|
+
// Copyright © 2019 Vibes. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
|
|
11
|
+
/// Get Inbox Messages Operation
|
|
12
|
+
internal class GetInboxMessageOperation: BaseOperation<InboxMessage> {
|
|
13
|
+
fileprivate let storage: LocalStorageType
|
|
14
|
+
fileprivate let resource: () -> HTTPResource<InboxMessage>
|
|
15
|
+
fileprivate var callback: GetInboxMessageCallback
|
|
16
|
+
|
|
17
|
+
/// Completion handler responsible for notifying sdk users
|
|
18
|
+
fileprivate lazy var completionHandler: VibesCompletion<InboxMessage> = { [weak self] result in
|
|
19
|
+
switch result {
|
|
20
|
+
case let .success(message):
|
|
21
|
+
self?.callback(message, nil)
|
|
22
|
+
case let .failure(error):
|
|
23
|
+
self?.callback(nil, error)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// Initialize this object
|
|
28
|
+
///
|
|
29
|
+
/// - parameters:
|
|
30
|
+
/// - credentialManager: an object to store credentials, keeping track of the current Credential..
|
|
31
|
+
/// - storage: an object that allows storing data locally
|
|
32
|
+
/// - api: an object that allows talking to the Vibes API
|
|
33
|
+
/// - advertisingId: AdSupport.advertisingId
|
|
34
|
+
/// - appId: the application ID provided by Vibes to identify this application
|
|
35
|
+
/// - personKey: The alppanumeric person key
|
|
36
|
+
/// - messageUID: The alppanumeric message UID
|
|
37
|
+
/// - callback: GetInboxMessageCallback (InboxMessage?, Error?)
|
|
38
|
+
public init(credentials: CredentialManager,
|
|
39
|
+
storage: LocalStorageType,
|
|
40
|
+
api: VibesAPIType,
|
|
41
|
+
advertisingId: String,
|
|
42
|
+
appId: String,
|
|
43
|
+
personKey: String,
|
|
44
|
+
messageUID: String,
|
|
45
|
+
callback: @escaping GetInboxMessageCallback) {
|
|
46
|
+
self.callback = callback
|
|
47
|
+
self.storage = storage
|
|
48
|
+
resource = {
|
|
49
|
+
APIDefinition.getInboxMessage(appId: appId, personKey: personKey, messageUID: messageUID)
|
|
50
|
+
}
|
|
51
|
+
super.init(credentials: credentials, api: api, advertisingId: advertisingId, appId: appId)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/// Execute the operation
|
|
55
|
+
override func start() {
|
|
56
|
+
super.start()
|
|
57
|
+
super.execute(resource: resource, completion: completionHandler)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
//
|
|
2
|
+
// GetInboxMessagesOperation.swift
|
|
3
|
+
// VibesPush-iOS
|
|
4
|
+
//
|
|
5
|
+
// Created by Moin' Victor on 16/07/2019.
|
|
6
|
+
// Copyright © 2019 Vibes. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
import Foundation
|
|
10
|
+
|
|
11
|
+
/// Get Inbox Messages Operation
|
|
12
|
+
internal class GetInboxMessagesOperation: BaseOperation<[InboxMessage]> {
|
|
13
|
+
fileprivate let storage: LocalStorageType
|
|
14
|
+
fileprivate let resource: () -> HTTPResource<[InboxMessage]>
|
|
15
|
+
fileprivate var callback: GetInboxMessagesCallback?
|
|
16
|
+
|
|
17
|
+
/// Completion handler responsible for notifying sdk users
|
|
18
|
+
fileprivate lazy var completionHandler: VibesCompletion<[InboxMessage]> = { [weak self] result in
|
|
19
|
+
switch result {
|
|
20
|
+
case let .success(messages):
|
|
21
|
+
self?.callback?(messages, nil)
|
|
22
|
+
case let .failure(error):
|
|
23
|
+
self?.callback?([], error)
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// Initialize this object
|
|
28
|
+
///
|
|
29
|
+
/// - parameters:
|
|
30
|
+
/// - credentialManager: an object to store credentials, keeping track of the current Credential..
|
|
31
|
+
/// - storage: an object that allows storing data locally
|
|
32
|
+
/// - api: an object that allows talking to the Vibes API
|
|
33
|
+
/// - advertisingId: AdSupport.advertisingId
|
|
34
|
+
/// - appId: the application ID provided by Vibes to identify this application
|
|
35
|
+
/// - personKey: The alppanumeric person key
|
|
36
|
+
/// - callback: GetInboxMessagesCallback ([InboxMessage], Error?)
|
|
37
|
+
public init(credentials: CredentialManager,
|
|
38
|
+
storage: LocalStorageType,
|
|
39
|
+
api: VibesAPIType,
|
|
40
|
+
advertisingId: String,
|
|
41
|
+
appId: String,
|
|
42
|
+
personKey: String,
|
|
43
|
+
callback: GetInboxMessagesCallback? = nil) {
|
|
44
|
+
self.callback = callback
|
|
45
|
+
self.storage = storage
|
|
46
|
+
resource = {
|
|
47
|
+
APIDefinition.getInboxMessages(appId: appId, personKey: personKey)
|
|
48
|
+
}
|
|
49
|
+
super.init(credentials: credentials, api: api, advertisingId: advertisingId, appId: appId)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// Execute the operation
|
|
53
|
+
override func start() {
|
|
54
|
+
super.start()
|
|
55
|
+
super.execute(resource: resource, completion: completionHandler)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
//
|
|
2
|
+
// GetPersonOperation.swift
|
|
3
|
+
// VibesPush-iOS
|
|
4
|
+
//
|
|
5
|
+
// Created by clemwek on 16/07/2019.
|
|
6
|
+
// Copyright © 2019 Vibes. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
/// Get Vibes Person Operation
|
|
10
|
+
internal class GetPersonOperation: BaseOperation<Person> {
|
|
11
|
+
fileprivate let storage: LocalStorageType
|
|
12
|
+
fileprivate let resource: () -> HTTPResource<Person>
|
|
13
|
+
fileprivate var callback: GetPersonCallback?
|
|
14
|
+
/// Completion handler responsible for notifying sdk users
|
|
15
|
+
fileprivate lazy var completionHandler: VibesCompletion<Person> = { [weak self] result in
|
|
16
|
+
switch result {
|
|
17
|
+
case let .success(person):
|
|
18
|
+
self?.callback?(person, nil)
|
|
19
|
+
case let .failure(error):
|
|
20
|
+
self?.callback?(nil, error)
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/// Initialize this object
|
|
25
|
+
///
|
|
26
|
+
/// - parameters:
|
|
27
|
+
/// - credentialManager: an object to store credentials, keeping track of the current Credential..
|
|
28
|
+
/// - storage: an object that allows storing data locally
|
|
29
|
+
/// - api: an object that allows talking to the Vibes API
|
|
30
|
+
/// - advertisingId: AdSupport.advertisingId
|
|
31
|
+
/// - appId: the application ID provided by Vibes to identify this application
|
|
32
|
+
/// - callback: GetPersonCallback (Person?, Error?)
|
|
33
|
+
public init(credentials: CredentialManager,
|
|
34
|
+
storage: LocalStorageType,
|
|
35
|
+
api: VibesAPIType,
|
|
36
|
+
advertisingId: String,
|
|
37
|
+
appId: String,
|
|
38
|
+
callback: GetPersonCallback? = nil) {
|
|
39
|
+
self.storage = storage
|
|
40
|
+
self.callback = callback
|
|
41
|
+
resource = {
|
|
42
|
+
let deviceId = credentials.currentCredential?.deviceId ?? VibesQueueConstant.NONE
|
|
43
|
+
return APIDefinition.getPerson(appId: appId, deviceId: deviceId)
|
|
44
|
+
}
|
|
45
|
+
super.init(credentials: credentials, api: api, advertisingId: advertisingId, appId: appId)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/// Execute the operation
|
|
49
|
+
override func start() {
|
|
50
|
+
super.start()
|
|
51
|
+
super.execute(resource: resource, completion: completionHandler)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/// Check Vibes App Info Operation
|
|
2
|
+
internal class GetVibesAppInfoOperation: BaseOperation<VibesAppInfo> {
|
|
3
|
+
fileprivate let storage: LocalStorageType
|
|
4
|
+
fileprivate let resource: () -> HTTPResource<VibesAppInfo>
|
|
5
|
+
fileprivate var callback: GetVibesAppInfoCallback?
|
|
6
|
+
|
|
7
|
+
/// Completion handler responsible for notifying sdk users
|
|
8
|
+
fileprivate lazy var completionHandler: VibesCompletion<VibesAppInfo> = { [weak self] result in
|
|
9
|
+
switch result {
|
|
10
|
+
case let .success(status):
|
|
11
|
+
self?.callback?(status, nil)
|
|
12
|
+
case let .failure(error):
|
|
13
|
+
self?.callback?(nil, error)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/// Initialize this object
|
|
18
|
+
///
|
|
19
|
+
/// - parameters:
|
|
20
|
+
/// - credentialManager: an object to store credentials, keeping track of the current Credential..
|
|
21
|
+
/// - storage: an object that allows storing data locally
|
|
22
|
+
/// - api: an object that allows talking to the Vibes API
|
|
23
|
+
/// - advertisingId: AdSupport.advertisingId
|
|
24
|
+
/// - appId: the application ID provided by Vibes to identify this application
|
|
25
|
+
/// - callback: GetVibesAppInfoCallback (status?, Error?)
|
|
26
|
+
public init(credentials: CredentialManager,
|
|
27
|
+
storage: LocalStorageType,
|
|
28
|
+
api: VibesAPIType,
|
|
29
|
+
advertisingId: String,
|
|
30
|
+
appId: String,
|
|
31
|
+
callback: GetVibesAppInfoCallback? = nil) {
|
|
32
|
+
self.callback = callback
|
|
33
|
+
self.storage = storage
|
|
34
|
+
resource = {
|
|
35
|
+
APIDefinition.fetchVibesAppInfo(appId: appId)
|
|
36
|
+
}
|
|
37
|
+
super.init(credentials: credentials, api: api, advertisingId: advertisingId, appId: appId)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// Execute the operation
|
|
41
|
+
override func start() {
|
|
42
|
+
super.start()
|
|
43
|
+
super.execute(resource: resource, completion: completionHandler)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/// Migration callback Operation
|
|
2
|
+
internal class MigrationCallbackOperation: BaseOperation<Void> {
|
|
3
|
+
fileprivate let resource: () -> HTTPResource<Void>
|
|
4
|
+
fileprivate var callback: VibesCompletion<Void>?
|
|
5
|
+
|
|
6
|
+
/// Completion handler responsible for notifying sdk users
|
|
7
|
+
fileprivate lazy var completionHandler: VibesCompletion<Void> = { [weak self] result in
|
|
8
|
+
switch result {
|
|
9
|
+
case .success:
|
|
10
|
+
self?.callback?(.success(()))
|
|
11
|
+
case let .failure(error):
|
|
12
|
+
self?.callback?(.failure(error))
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/// Initialize this object
|
|
17
|
+
///
|
|
18
|
+
/// - parameters:
|
|
19
|
+
/// - credentialManager: an object to store credentials, keeping track of the current Credential..
|
|
20
|
+
/// - api: an object that allows talking to the Vibes API
|
|
21
|
+
/// - advertisingId: AdSupport.advertisingId
|
|
22
|
+
/// - appId: the application ID provided by Vibes to identify this application
|
|
23
|
+
/// - migrationItemId: The migration item Id
|
|
24
|
+
/// - vibesDeviceId: Vibes Device Id
|
|
25
|
+
/// - callback: MigrationCallback (Error?)
|
|
26
|
+
public init(credentials: CredentialManager,
|
|
27
|
+
api: VibesAPIType,
|
|
28
|
+
advertisingId: String,
|
|
29
|
+
appId: String,
|
|
30
|
+
migrationItemId: String,
|
|
31
|
+
vibesDeviceId: String,
|
|
32
|
+
callback: VibesCompletion<Void>? = nil) {
|
|
33
|
+
self.callback = callback
|
|
34
|
+
resource = {
|
|
35
|
+
APIDefinition.migrationCallback(appId: appId, migrationItemId: migrationItemId, vibesDeviceId: vibesDeviceId)
|
|
36
|
+
}
|
|
37
|
+
super.init(credentials: credentials, api: api, advertisingId: advertisingId, appId: appId)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// Execute the operation.
|
|
41
|
+
override func start() {
|
|
42
|
+
super.start()
|
|
43
|
+
super.execute(resource: resource, completion: completionHandler)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
//
|
|
2
|
+
// RegisterDeviceOperation.swift
|
|
3
|
+
// VibesPush-iOS
|
|
4
|
+
//
|
|
5
|
+
// Created by Jean-Michel Barbieri on 2/21/18.
|
|
6
|
+
// Copyright © 2018 Vibes. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
import Foundation
|
|
9
|
+
|
|
10
|
+
internal class RegisterDeviceOperation: BaseOperation<VibesCredential> {
|
|
11
|
+
fileprivate let resource: () -> HTTPResource<VibesCredential>
|
|
12
|
+
fileprivate weak var delegate: VibesAPIDelegate?
|
|
13
|
+
fileprivate var callback: VibesCompletion<VibesCredential>?
|
|
14
|
+
/// Completion handler responsible for notifying sdk users
|
|
15
|
+
private lazy var completionHandler: VibesCompletion<VibesCredential> = {[weak self] (result) in
|
|
16
|
+
switch result {
|
|
17
|
+
case .success(let credential):
|
|
18
|
+
self?.credentialManager.currentCredential = credential
|
|
19
|
+
self?.delegate?.didRegisterDevice?(deviceId: credential.deviceId, error: nil)
|
|
20
|
+
self?.callback?(.success(credential))
|
|
21
|
+
case .failure(let error):
|
|
22
|
+
self?.delegate?.didRegisterDevice?(deviceId: nil, error: error)
|
|
23
|
+
self?.callback?(.failure(error))
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/// Initialize this object
|
|
28
|
+
///
|
|
29
|
+
/// - parameters:
|
|
30
|
+
/// - credentialManager: an object to store credentials, keeping track of the current Credential..
|
|
31
|
+
/// - api: an object that allows talking to the Vibes API
|
|
32
|
+
/// - advertisingId: AdSupport.advertisingId
|
|
33
|
+
/// - appId: the application ID provided by Vibes to identify this application
|
|
34
|
+
/// - delegate: VibesAPIDelegate.
|
|
35
|
+
public init(credentials: CredentialManager,
|
|
36
|
+
api: VibesAPIType,
|
|
37
|
+
advertisingId: String,
|
|
38
|
+
appId: String,
|
|
39
|
+
delegate: VibesAPIDelegate?,
|
|
40
|
+
callback: VibesCompletion<VibesCredential>? = nil) {
|
|
41
|
+
self.delegate = delegate
|
|
42
|
+
self.callback = callback
|
|
43
|
+
resource = {
|
|
44
|
+
let device = Device(advertisingIdentifier: advertisingId)
|
|
45
|
+
return APIDefinition.registerDevice(appId: appId, device: device)
|
|
46
|
+
}
|
|
47
|
+
super.init(credentials: credentials, api: api, advertisingId: advertisingId, appId: appId)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// Override BaseOperation validateOperation: For this request we don't want to check
|
|
51
|
+
/// if the credentials exists.
|
|
52
|
+
override func validateOperation() -> VibesError? {
|
|
53
|
+
return nil
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Execute the operation
|
|
57
|
+
override func start() {
|
|
58
|
+
super.start()
|
|
59
|
+
if let credentials = self.credentialManager.currentCredential {
|
|
60
|
+
completionHandler(VibesResult<VibesCredential>.success(credentials))
|
|
61
|
+
finish()
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
super.execute(resource: resource, completion: completionHandler)
|
|
65
|
+
}
|
|
66
|
+
}
|