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.
Files changed (72) hide show
  1. package/ios/Vibes.swift +2 -3
  2. package/ios/VibesClient.swift +3 -4
  3. package/ios/VibesPluginLogger.swift +2 -5
  4. package/package.json +3 -2
  5. package/vendor/VibesPush/LICENSE +13 -0
  6. package/vendor/VibesPush/Sources/APIDefinition.swift +502 -0
  7. package/vendor/VibesPush/Sources/Actions.swift +24 -0
  8. package/vendor/VibesPush/Sources/AppObserver.swift +137 -0
  9. package/vendor/VibesPush/Sources/AuthTokenBehavior.swift +17 -0
  10. package/vendor/VibesPush/Sources/CombinedLogger.swift +53 -0
  11. package/vendor/VibesPush/Sources/ConsoleLogger.swift +97 -0
  12. package/vendor/VibesPush/Sources/Credential.swift +41 -0
  13. package/vendor/VibesPush/Sources/CredentialManager.swift +24 -0
  14. package/vendor/VibesPush/Sources/Date+iso8601.swift +34 -0
  15. package/vendor/VibesPush/Sources/Date+logPrefix.swift +20 -0
  16. package/vendor/VibesPush/Sources/DeviceToken.swift +15 -0
  17. package/vendor/VibesPush/Sources/DeviceType.swift +143 -0
  18. package/vendor/VibesPush/Sources/Dictionary+merged.swift +11 -0
  19. package/vendor/VibesPush/Sources/Event.swift +83 -0
  20. package/vendor/VibesPush/Sources/EventCollection.swift +36 -0
  21. package/vendor/VibesPush/Sources/EventTracker.swift +39 -0
  22. package/vendor/VibesPush/Sources/FoundationExtensions.swift +16 -0
  23. package/vendor/VibesPush/Sources/GitTag.swift +27 -0
  24. package/vendor/VibesPush/Sources/HTTP/HTTPBehavior.swift +19 -0
  25. package/vendor/VibesPush/Sources/HTTP/HTTPMethod.swift +20 -0
  26. package/vendor/VibesPush/Sources/HTTP/HTTPResource.swift +69 -0
  27. package/vendor/VibesPush/Sources/HTTP/HTTPResourceClient.swift +190 -0
  28. package/vendor/VibesPush/Sources/HTTP/JSONParser.swift +91 -0
  29. package/vendor/VibesPush/Sources/HTTP/Operations/AssociatePersonOperation.swift +56 -0
  30. package/vendor/VibesPush/Sources/HTTP/Operations/BaseOperation.swift +153 -0
  31. package/vendor/VibesPush/Sources/HTTP/Operations/EventOperation.swift +73 -0
  32. package/vendor/VibesPush/Sources/HTTP/Operations/GetGitTagsOperation.swift +61 -0
  33. package/vendor/VibesPush/Sources/HTTP/Operations/GetInboxMessageOperation.swift +59 -0
  34. package/vendor/VibesPush/Sources/HTTP/Operations/GetInboxMessagesOperation.swift +57 -0
  35. package/vendor/VibesPush/Sources/HTTP/Operations/GetPersonOperation.swift +53 -0
  36. package/vendor/VibesPush/Sources/HTTP/Operations/GetVibesAppInfoOperation.swift +45 -0
  37. package/vendor/VibesPush/Sources/HTTP/Operations/MigrationCallbackOperation.swift +45 -0
  38. package/vendor/VibesPush/Sources/HTTP/Operations/RegisterDeviceOperation.swift +66 -0
  39. package/vendor/VibesPush/Sources/HTTP/Operations/RegisterPushOperation.swift +73 -0
  40. package/vendor/VibesPush/Sources/HTTP/Operations/TrackProductActionOperation.swift +75 -0
  41. package/vendor/VibesPush/Sources/HTTP/Operations/TrackPurchaseActionOperation.swift +81 -0
  42. package/vendor/VibesPush/Sources/HTTP/Operations/UnregisterDeviceOperation.swift +64 -0
  43. package/vendor/VibesPush/Sources/HTTP/Operations/UnregisterPushOperation.swift +72 -0
  44. package/vendor/VibesPush/Sources/HTTP/Operations/UpdateDeviceOperationPatch.swift +57 -0
  45. package/vendor/VibesPush/Sources/HTTP/Operations/UpdateDeviceOperationPut.swift +59 -0
  46. package/vendor/VibesPush/Sources/HTTP/Operations/UpdateMessageOperation.swift +50 -0
  47. package/vendor/VibesPush/Sources/HTTP/Operations/VibesQueueOperation.swift +76 -0
  48. package/vendor/VibesPush/Sources/HTTP/ResourceResult.swift +38 -0
  49. package/vendor/VibesPush/Sources/HTTPURLResponse+cURL.swift +16 -0
  50. package/vendor/VibesPush/Sources/InboxMessage.swift +219 -0
  51. package/vendor/VibesPush/Sources/Info.plist +26 -0
  52. package/vendor/VibesPush/Sources/InputStream+readToString.swift +19 -0
  53. package/vendor/VibesPush/Sources/KeychainStorage.swift +64 -0
  54. package/vendor/VibesPush/Sources/LocalObject.swift +25 -0
  55. package/vendor/VibesPush/Sources/LocalStorageKeys.swift +19 -0
  56. package/vendor/VibesPush/Sources/LocalStorageType.swift +47 -0
  57. package/vendor/VibesPush/Sources/LocalValue.swift +67 -0
  58. package/vendor/VibesPush/Sources/PersistentEventStorage.swift +81 -0
  59. package/vendor/VibesPush/Sources/Person.swift +98 -0
  60. package/vendor/VibesPush/Sources/Product.swift +103 -0
  61. package/vendor/VibesPush/Sources/Purchase.swift +108 -0
  62. package/vendor/VibesPush/Sources/TrackedEventType.swift +48 -0
  63. package/vendor/VibesPush/Sources/URLRequest+cURL.swift +36 -0
  64. package/vendor/VibesPush/Sources/UserDefaultsStorage.swift +32 -0
  65. package/vendor/VibesPush/Sources/Vibes.swift +1069 -0
  66. package/vendor/VibesPush/Sources/VibesAPI.swift +81 -0
  67. package/vendor/VibesPush/Sources/VibesAPIDelegate.swift +41 -0
  68. package/vendor/VibesPush/Sources/VibesAppInfo.swift +77 -0
  69. package/vendor/VibesPush/Sources/VibesConfiguration.swift +108 -0
  70. package/vendor/VibesPush/Sources/VibesLogger.swift +65 -0
  71. package/vendor/VibesPush/Sources/VibesResult.swift +78 -0
  72. package/vibes-react-native.podspec +6 -2
@@ -0,0 +1,73 @@
1
+ //
2
+ // RegisterPushOperation.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 RegisterPushOperation: BaseOperation<Void> {
11
+ fileprivate let storage: LocalStorageType
12
+ fileprivate let resource: () -> HTTPResource<Void>
13
+ fileprivate weak var delegate: VibesAPIDelegate?
14
+ fileprivate var callback: VibesCompletion<Void>?
15
+
16
+ /// Completion handler responsible for notifying sdk users
17
+ fileprivate lazy var completionHandler: VibesCompletion<Void> = {[weak self] (result) in
18
+ switch result {
19
+ case .success :
20
+ let userDefaults = UserDefaults.standard
21
+ userDefaults.setValue(true, forKey: Vibes.REGISTER_PUSH_STATUS)
22
+ userDefaults.synchronize()
23
+ self?.callback?(.success(()))
24
+ self?.delegate?.didRegisterPush?(error: nil)
25
+ case .failure(let error) :
26
+ self?.callback?(.failure(error))
27
+ self?.delegate?.didRegisterPush?(error: error)
28
+ }
29
+ }
30
+
31
+ /// Initialize this object
32
+ ///
33
+ /// - parameters:
34
+ /// - credentialManager: an object to store credentials, keeping track of the current Credential..
35
+ /// - storage: an object that allows storing data locally
36
+ /// - api: an object that allows talking to the Vibes API
37
+ /// - advertisingId: AdSupport.advertisingId
38
+ /// - appId: the application ID provided by Vibes to identify this application
39
+ /// - delegate: VibesAPIDelegate.
40
+ public init(credentials: CredentialManager,
41
+ storage: LocalStorageType,
42
+ api: VibesAPIType,
43
+ advertisingId: String,
44
+ appId: String,
45
+ delegate: VibesAPIDelegate?,
46
+ callback: VibesCompletion<Void>? = nil) {
47
+ self.delegate = delegate
48
+ self.callback = callback
49
+ self.storage = storage
50
+ resource = {
51
+ let deviceId = credentials.currentCredential?.deviceId ?? VibesQueueConstant.NONE
52
+ let pushToken = storage.get(LocalStorageKeys.pushToken) ?? VibesQueueConstant.NONE
53
+ return APIDefinition.registerPush(appId: appId, deviceId: deviceId, pushToken: pushToken)
54
+ }
55
+ super.init(credentials: credentials, api: api, advertisingId: advertisingId, appId: appId)
56
+ }
57
+
58
+ /// Validate that the push token exists and the credentials aren't nil (super class)
59
+ /// - returns:
60
+ /// - VibesError: nullable error
61
+ override func validateOperation() -> VibesError? {
62
+ if self.storage.get(LocalStorageKeys.pushToken) == nil {
63
+ return .noPushToken
64
+ }
65
+ return super.validateOperation()
66
+ }
67
+
68
+ /// Execute the operation
69
+ override func start() {
70
+ super.start()
71
+ super.execute(resource: resource, completion: completionHandler)
72
+ }
73
+ }
@@ -0,0 +1,75 @@
1
+ //
2
+ // TrackProductActionOperation.swift
3
+ // VibesPush
4
+ //
5
+ // Created by Moin' Victor on 15/08/2022.
6
+ // Copyright © 2022 Vibes. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+ /// Track Product Action Operation
12
+ internal class TrackProductActionOperation: BaseOperation<Void> {
13
+ fileprivate let storage: LocalStorageType
14
+ fileprivate let resource: () -> HTTPResource<Void>
15
+ fileprivate var callback: TrackProductActionCallback?
16
+
17
+ /// Completion handler responsible for notifying sdk users
18
+ fileprivate lazy var completionHandler: VibesCompletion<Void> = { [weak self] result in
19
+ switch result {
20
+ case let .success(messages):
21
+ self?.callback?(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
+ /// - action: The product action
36
+ /// - product: The product
37
+ /// - data: The Vibes tracking data
38
+ /// - activityUid: The activity UID
39
+ /// - callback: GetInboxMessagesCallback ([InboxMessage], Error?)
40
+ public init(credentials: CredentialManager,
41
+ storage: LocalStorageType,
42
+ api: VibesAPIType,
43
+ advertisingId: String,
44
+ appId: String,
45
+ action: ProductAction,
46
+ product: Product,
47
+ data: VibesTrackingData,
48
+ activityUid: String?,
49
+ callback: TrackProductActionCallback? = nil) {
50
+ self.callback = callback
51
+ self.storage = storage
52
+ resource = {
53
+ APIDefinition.trackProductAction(action: action, product: product, data: data, activityUid: activityUid)
54
+ }
55
+ super.init(credentials: credentials, api: api, advertisingId: advertisingId, appId: appId)
56
+ }
57
+
58
+ /// Override BaseOperation validateOperation: For this request we don't want to check
59
+ /// if the credentials exists.
60
+ override func validateOperation() -> VibesError? {
61
+ return nil
62
+ }
63
+
64
+ /// Whether to inject the auth header, override and return false to disable `Authorization` header in the request
65
+ /// - Returns: `true` or `false`
66
+ override func injectAuthHeader() -> Bool {
67
+ return false
68
+ }
69
+
70
+ /// Execute the operation
71
+ override func start() {
72
+ super.start()
73
+ super.execute(resource: resource, completion: completionHandler)
74
+ }
75
+ }
@@ -0,0 +1,81 @@
1
+ //
2
+ // TrackPurchaseActionOperation.swift
3
+ // VibesPush
4
+ //
5
+ // Created by Clement Wekesa on 18/08/2022.
6
+ // Copyright © 2022 Vibes. All rights reserved.
7
+ //
8
+
9
+ import Foundation
10
+
11
+ /// Track Product Action Operation
12
+ internal class TrackPurchaseActionOperation: BaseOperation<Void> {
13
+ fileprivate let storage: LocalStorageType
14
+ fileprivate let resource: () -> HTTPResource<Void>
15
+ fileprivate var callback: TrackPurchaseActionCallback?
16
+
17
+ /// Completion handler responsible for notifying sdk users
18
+ fileprivate lazy var completionHandler: VibesCompletion<Void> = { [weak self] result in
19
+ switch result {
20
+ case let .success(messages):
21
+ self?.callback?(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
+ /// - action: The purchase action
36
+ /// - purchase: The purchase
37
+ /// - data: The Vibes tracking data
38
+ /// - activityUid: The activity UID
39
+ /// - callback: TrackPurchaseActionCallback ([Success], Error?)
40
+ public init(credentials: CredentialManager,
41
+ storage: LocalStorageType,
42
+ api: VibesAPIType,
43
+ advertisingId: String,
44
+ appId: String,
45
+ action: PurchaseAction,
46
+ purchase: Purchase,
47
+ data: VibesTrackingData,
48
+ activityUid: String?,
49
+ callback: TrackPurchaseActionCallback? = nil) {
50
+ self.callback = callback
51
+ self.storage = storage
52
+ resource = {
53
+ APIDefinition.trackPurchaseAction(action: action,
54
+ purchase: purchase,
55
+ data: data,
56
+ activityUid: activityUid)
57
+ }
58
+ super.init(credentials: credentials,
59
+ api: api,
60
+ advertisingId: advertisingId,
61
+ appId: appId)
62
+ }
63
+
64
+ /// Override BaseOperation validateOperation: For this request we don't want to check
65
+ /// if the credentials exists.
66
+ override func validateOperation() -> VibesError? {
67
+ return nil
68
+ }
69
+
70
+ /// Whether to inject the auth header, override and return false to disable `Authorization` header in the request
71
+ /// - Returns: `true` or `false`
72
+ override func injectAuthHeader() -> Bool {
73
+ return false
74
+ }
75
+
76
+ /// Execute the operation
77
+ override func start() {
78
+ super.start()
79
+ super.execute(resource: resource, completion: completionHandler)
80
+ }
81
+ }
@@ -0,0 +1,64 @@
1
+ //
2
+ // UnregisterDeviceOperation.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 UnregisterDeviceOperation: BaseOperation<Void> {
11
+ fileprivate weak var delegate: VibesAPIDelegate?
12
+ fileprivate let resource: () -> HTTPResource<Void>
13
+ fileprivate var callback: VibesCompletion<Void>?
14
+
15
+ /// Completion handler responsible for notifying sdk users
16
+ fileprivate lazy var completionHandler: VibesCompletion<Void> = {[weak self] (result) in
17
+ switch result {
18
+ case .success:
19
+ self?.credentialManager.currentCredential = nil
20
+ let userDefaults = UserDefaults.standard
21
+ userDefaults.removeObject(forKey: Vibes.REGISTER_PUSH_STATUS)
22
+ userDefaults.synchronize()
23
+ self?.callback?(.success(()))
24
+ self?.delegate?.didUnregisterDevice?(error: nil)
25
+ case .failure(let error):
26
+ self?.credentialManager.currentCredential = nil
27
+ let userDefaults = UserDefaults.standard
28
+ userDefaults.removeObject(forKey: Vibes.REGISTER_PUSH_STATUS)
29
+ userDefaults.synchronize()
30
+ self?.callback?(.success(()))
31
+ self?.delegate?.didUnregisterDevice?(error: nil)
32
+ }
33
+ }
34
+
35
+ /// Initialize this object
36
+ ///
37
+ /// - parameters:
38
+ /// - credentialManager: an object to store credentials, keeping track of the current Credential..
39
+ /// - storage: an object that allows storing data locally
40
+ /// - api: an object that allows talking to the Vibes API
41
+ /// - advertisingId: AdSupport.advertisingId
42
+ /// - appId: the application ID provided by Vibes to identify this application
43
+ /// - delegate: VibesAPIDelegate.
44
+ public init(credentials: CredentialManager,
45
+ api: VibesAPIType,
46
+ advertisingId: String,
47
+ appId: String,
48
+ delegate: VibesAPIDelegate?,
49
+ callback: VibesCompletion<Void>? = nil) {
50
+ self.delegate = delegate
51
+ self.callback = callback
52
+ resource = {
53
+ let deviceId = credentials.currentCredential?.deviceId ?? VibesQueueConstant.NONE
54
+ return APIDefinition.unregisterDevice(appId: appId, deviceId: deviceId)
55
+ }
56
+ super.init(credentials: credentials, api: api, advertisingId: advertisingId, appId: appId)
57
+ }
58
+
59
+ /// Execute the operation.
60
+ override func start() {
61
+ super.start()
62
+ super.execute(resource: resource, completion: completionHandler)
63
+ }
64
+ }
@@ -0,0 +1,72 @@
1
+ //
2
+ // UnregisterPushOperation.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 UnregisterPushOperation: BaseOperation<Void> {
11
+ fileprivate let resource: () -> HTTPResource<Void>
12
+ fileprivate let storage: LocalStorageType
13
+ fileprivate weak var delegate: VibesAPIDelegate?
14
+ fileprivate var callback: VibesCompletion<Void>?
15
+
16
+ /// Completion handler responsible for notifying sdk users
17
+ fileprivate lazy var completionHandler: VibesCompletion<Void> = {[weak self] (result) in
18
+ switch result {
19
+ case .success :
20
+ let userDefaults = UserDefaults.standard
21
+ userDefaults.removeObject(forKey: Vibes.REGISTER_PUSH_STATUS)
22
+ userDefaults.synchronize()
23
+ self?.callback?(.success(()))
24
+ self?.delegate?.didUnregisterPush?(error: nil)
25
+ case .failure(let error) :
26
+ self?.callback?(.failure(error))
27
+ self?.delegate?.didUnregisterPush?(error: error)
28
+ }
29
+ }
30
+
31
+ /// Initialize this object
32
+ ///
33
+ /// - parameters:
34
+ /// - credentialManager: an object to store credentials, keeping track of the current Credential..
35
+ /// - storage: an object that allows storing data locally
36
+ /// - api: an object that allows talking to the Vibes API
37
+ /// - advertisingId: AdSupport.advertisingId
38
+ /// - appId: the application ID provided by Vibes to identify this application
39
+ /// - delegate: VibesAPIDelegate.
40
+ public init(credentials: CredentialManager,
41
+ storage: LocalStorageType,
42
+ api: VibesAPIType,
43
+ advertisingId: String,
44
+ appId: String,
45
+ delegate: VibesAPIDelegate?,
46
+ callback: VibesCompletion<Void>? = nil) {
47
+ self.delegate = delegate
48
+ self.callback = callback
49
+ self.storage = storage
50
+ resource = {
51
+ let deviceId = credentials.currentCredential?.deviceId ?? VibesQueueConstant.NONE
52
+ return APIDefinition.unregisterPush(appId: appId, deviceId: deviceId)
53
+ }
54
+ super.init(credentials: credentials, api: api, advertisingId: advertisingId, appId: appId)
55
+ }
56
+
57
+ /// Validate that the push token exists and the credentials aren't nil (super class)
58
+ /// - returns:
59
+ /// - VibesError: nullable error
60
+ override func validateOperation() -> VibesError? {
61
+ if self.storage.get(LocalStorageKeys.pushToken) == nil {
62
+ return .noPushToken
63
+ }
64
+ return super.validateOperation()
65
+ }
66
+
67
+ /// Execute the operation
68
+ override func start() {
69
+ super.start()
70
+ super.execute(resource: resource, completion: completionHandler)
71
+ }
72
+ }
@@ -0,0 +1,57 @@
1
+ //
2
+ // UpdateDeviceOperationPatch.swift
3
+ // VibesPush
4
+ //
5
+ // Created by DHwty on 17/06/2021.
6
+ // Copyright © 2021 Vibes. All rights reserved.
7
+ //
8
+
9
+ internal class UpdateDeviceOperationPatch: BaseOperation<Void> {
10
+ fileprivate let resource: () -> HTTPResource<Void>
11
+ fileprivate weak var delegate: VibesAPIDelegate?
12
+ fileprivate var callback: VibesCompletion<Void>?
13
+
14
+ /// Completion handler responsible for notifying sdk users
15
+ fileprivate lazy var completionHandler: VibesCompletion<Void> = {[weak self] (result) in
16
+ switch result {
17
+ case .success :
18
+ self?.callback?(.success(()))
19
+ self?.delegate?.didUpdateDevice?(error: nil)
20
+ case .failure(let error) :
21
+ self?.callback?(.failure(error))
22
+ self?.delegate?.didUpdateDevice?(error: error)
23
+ }
24
+ }
25
+
26
+ /// Initialize this object
27
+ ///
28
+ /// - parameters:
29
+ /// - credentialManager: an object to store credentials, keeping track of the current Credential..
30
+ /// - api: an object that allows talking to the Vibes API
31
+ /// - advertisingId: AdSupport.advertisingId
32
+ /// - appId: the application ID provided by Vibes to identify this application
33
+ /// - delegate: VibesAPIDelegate.
34
+ /// - location: contains the current longitude and latitude
35
+ public init(credentials: CredentialManager,
36
+ api: VibesAPIType,
37
+ advertisingId: String,
38
+ appId: String,
39
+ delegate: VibesAPIDelegate?,
40
+ location: (lat: Double, long: Double)?,
41
+ callback: VibesCompletion<Void>? = nil) {
42
+ self.delegate = delegate
43
+ self.callback = callback
44
+ let device = Device(advertisingIdentifier: advertisingId, location: location)
45
+ resource = {
46
+ let deviceId = credentials.currentCredential?.deviceId ?? VibesQueueConstant.NONE
47
+ return APIDefinition.updateDeviceInfoPatch(appId: appId, deviceId: deviceId, device: device)
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(retry: 0, resource: resource, completion: completionHandler)
56
+ }
57
+ }
@@ -0,0 +1,59 @@
1
+ //
2
+ // UpdateDeviceOperationPut.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 UpdateDeviceOperationPut: BaseOperation<Void> {
10
+ fileprivate let resource: () -> HTTPResource<VibesCredential>
11
+ fileprivate weak var delegate: VibesAPIDelegate?
12
+ fileprivate var callback: VibesCompletion<Void>?
13
+
14
+ /// Completion handler responsible for notifying sdk users
15
+ fileprivate lazy var completionHandler: VibesCompletion<VibesCredential> = {[weak self] (result) in
16
+ switch result {
17
+ case .success(let value):
18
+ // we want to update the new credential to our local
19
+ self?.credentialManager.currentCredential = value
20
+ self?.callback?(.success(()))
21
+ self?.delegate?.didUpdateDevice?(error: nil)
22
+ case .failure(let error) :
23
+ self?.callback?(.failure(error))
24
+ self?.delegate?.didUpdateDevice?(error: error)
25
+ }
26
+ }
27
+
28
+ /// Initialize this object
29
+ ///
30
+ /// - parameters:
31
+ /// - credentialManager: an object to store credentials, keeping track of the current Credential..
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
+ /// - delegate: VibesAPIDelegate.
36
+ /// - location: contains the current longitude and latitude
37
+ public init(credentials: CredentialManager,
38
+ api: VibesAPIType,
39
+ advertisingId: String,
40
+ appId: String,
41
+ delegate: VibesAPIDelegate?,
42
+ location: (lat: Double, long: Double)?,
43
+ callback: VibesCompletion<Void>? = nil) {
44
+ self.delegate = delegate
45
+ self.callback = callback
46
+ let device = Device(advertisingIdentifier: advertisingId, location: location)
47
+ resource = {
48
+ let deviceId = credentials.currentCredential?.deviceId ?? VibesQueueConstant.NONE
49
+ return APIDefinition.updateDeviceInfoPut(appId: appId, deviceId: deviceId, device: device)
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(retry: 0, resource: resource, completion: completionHandler)
58
+ }
59
+ }
@@ -0,0 +1,50 @@
1
+ /// Update Inbox Messages Operation
2
+ internal class UpdateMessageOperation: BaseOperation<InboxMessage> {
3
+ fileprivate let storage: LocalStorageType
4
+ fileprivate let resource: () -> HTTPResource<InboxMessage>
5
+ fileprivate var callback: UpdateMessageCallback?
6
+
7
+ /// Completion handler responsible for notifying sdk users
8
+ fileprivate lazy var completionHandler: VibesCompletion<InboxMessage> = { [weak self] result in
9
+ switch result {
10
+ case let .success(message):
11
+ self?.callback?(message, 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
+ /// - personKey: The alppanumeric person key
26
+ /// - messageUID: The unique UID of message to update
27
+ /// - callback: UpdateMessageCallback (InboxMessage?, Error?)
28
+ public init(credentials: CredentialManager,
29
+ storage: LocalStorageType,
30
+ api: VibesAPIType,
31
+ advertisingId: String,
32
+ appId: String,
33
+ personKey: String,
34
+ messageUID: String,
35
+ payload: VibesJSONDictionary,
36
+ callback: UpdateMessageCallback? = nil) {
37
+ self.callback = callback
38
+ self.storage = storage
39
+ resource = {
40
+ APIDefinition.updateMessage(appId: appId, personKey: personKey, messageUID: messageUID, payload: payload)
41
+ }
42
+ super.init(credentials: credentials, api: api, advertisingId: advertisingId, appId: appId)
43
+ }
44
+
45
+ /// Execute the operation
46
+ override func start() {
47
+ super.start()
48
+ super.execute(resource: resource, completion: completionHandler)
49
+ }
50
+ }
@@ -0,0 +1,76 @@
1
+ //
2
+ // VibesQueueOperation.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 VibesQueueOperation: Operation {
11
+ fileprivate var _isReady: Bool
12
+ fileprivate var _isExecuting: Bool
13
+ fileprivate var _isFinished: Bool
14
+ fileprivate var _isCancelled: Bool
15
+
16
+ public override var isReady: Bool {
17
+ get { return _isReady }
18
+ set { update({ self._isReady = newValue }, key: "isReady") }
19
+ }
20
+
21
+ public override var isExecuting: Bool {
22
+ get { return _isExecuting }
23
+ set { update({ self._isExecuting = newValue }, key: "isExecuting") }
24
+ }
25
+
26
+ public override var isFinished: Bool {
27
+ get { return _isFinished }
28
+ set { update({ self._isFinished = newValue }, key: "isFinished") }
29
+ }
30
+
31
+ public override var isCancelled: Bool {
32
+ get { return _isCancelled }
33
+ set { update({ self._isCancelled = newValue }, key: "isCancelled") }
34
+ }
35
+
36
+ override var isAsynchronous: Bool {
37
+ return true
38
+ }
39
+
40
+ override init() {
41
+ _isReady = true
42
+ _isExecuting = false
43
+ _isFinished = false
44
+ _isCancelled = false
45
+ super.init()
46
+ }
47
+
48
+ public override func start() {
49
+ if self.isExecuting == false {
50
+ self.isReady = false
51
+ self.isFinished = false
52
+ self.isCancelled = false
53
+ self.isExecuting = true
54
+ }
55
+ }
56
+
57
+ private func update(_ change: () -> Void, key: String) {
58
+ willChangeValue(forKey: key)
59
+ change()
60
+ didChangeValue(forKey: key)
61
+ }
62
+
63
+ func finish() {
64
+ self.isReady = false
65
+ self.isExecuting = false
66
+ self.isCancelled = false
67
+ self.isFinished = true
68
+ }
69
+
70
+ public override func cancel() {
71
+ self.isReady = false
72
+ self.isFinished = false
73
+ self.isExecuting = false
74
+ self.isCancelled = true
75
+ }
76
+ }
@@ -0,0 +1,38 @@
1
+ import Foundation
2
+ /// A custom error enum that indicates why requesting a resource has failed.
3
+ enum ResourceError: Error {
4
+ /// Error 401
5
+ case unauthorized
6
+ /// An error indicating the request times out or there is no network.
7
+ case unreachable
8
+ /// An error indicating that a non-success HTTP status code (i.e. non-200)
9
+ /// was returned.
10
+ case invalidResponse(statusCode: Int, responseText: String)
11
+
12
+ /// An error indicating that no data was returned in the HTTP response.
13
+ case noData
14
+
15
+ /// An error indicating that data was returned, but could not be parsed into
16
+ /// the desired Type (using the `HTTPResource`'s `parse` property).
17
+ case couldNotParse(data: Data)
18
+
19
+ /// A catch-all error, for errors that fall outside the above specifically-
20
+ /// delineated errors.
21
+ case other(Error?)
22
+ }
23
+
24
+ /// A generic result object to created a tagged union of success or failure for
25
+ /// requesting an `HTTPResource`.
26
+ ///
27
+ /// The result of successfully parsing an `HTTPResource` is encoded in the `T`
28
+ /// type attached to the `success` case; a `ResourceError` is attached to the
29
+ /// `failure` case.
30
+ enum ResourceResult<T> {
31
+ /// Used to indicate that an HTTP request was successful and the response was
32
+ /// parsed from `Data` into the Type indicated by `T`.
33
+ case success(T)
34
+
35
+ /// Used to indicate that an HTTP request failed; the reason why is attached
36
+ /// as an `HTTPResourceError`.
37
+ case failure(ResourceError)
38
+ }
@@ -0,0 +1,16 @@
1
+ import Foundation
2
+
3
+ extension HTTPURLResponse {
4
+ public var responseCodeDescription: String {
5
+ let status = HTTPURLResponse.localizedString(forStatusCode: statusCode).capitalized
6
+ return "[HTTP/1.1 \(statusCode) \(status)]"
7
+ }
8
+
9
+ public var headersDescription: String {
10
+ var output = ""
11
+ for (key, value) in allHeaderFields {
12
+ output.append("\(key): \(value)")
13
+ }
14
+ return output
15
+ }
16
+ }