Skip to content

Commit f0c67fc

Browse files
committed
Merge branch 'release/1.2.4' into main
2 parents 64ac6fb + c25ad6b commit f0c67fc

File tree

6 files changed

+100
-54
lines changed

6 files changed

+100
-54
lines changed

Sources/Pam/HttpClient.swift

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ enum HttpClient {
4343
request.httpBody = try? JSONSerialization.data(withJSONObject: json, options: [])
4444
}
4545

46+
if Pam.shared.isEnableLog {
47+
print("🛺 Request POST: ", request.curlString )
48+
}
4649
let session = URLSession.shared
4750
session.dataTask(with: request) { data, _, error in
4851
if error == nil, let data = data {
@@ -77,9 +80,10 @@ enum HttpClient {
7780

7881

7982
if Pam.shared.isEnableLog {
80-
print("🛺 Request GET: ", url )
83+
print("🛺 Request GET: ", request.curlString )
8184
}
8285

86+
8387
let session = URLSession.shared
8488
session.dataTask(with: request) { data, _, error in
8589
if error == nil, let data = data {
@@ -95,3 +99,41 @@ enum HttpClient {
9599
}.resume()
96100
}
97101
}
102+
103+
extension URLRequest {
104+
105+
/**
106+
Returns a cURL command representation of this URL request.
107+
*/
108+
public var curlString: String {
109+
guard let url = url else { return "" }
110+
var baseCommand = #"curl "\#(url.absoluteString)""#
111+
112+
if httpMethod == "HEAD" {
113+
baseCommand += " --head"
114+
}
115+
116+
var command = [baseCommand]
117+
118+
if let method = httpMethod, method != "GET" && method != "HEAD" {
119+
command.append("-X \(method)")
120+
}
121+
122+
if let headers = allHTTPHeaderFields {
123+
for (key, value) in headers where key != "Cookie" {
124+
command.append("-H '\(key): \(value)'")
125+
}
126+
}
127+
128+
if let data = httpBody, let body = String(data: data, encoding: .utf8) {
129+
command.append("-d '\(body)'")
130+
}
131+
132+
return command.joined(separator: " \\\n\t")
133+
}
134+
135+
init?(curlString: String) {
136+
return nil
137+
}
138+
139+
}

Sources/Pam/Pam+Static.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ extension Pam {
2626
return UIDevice.current.identifierForVendor?.uuidString
2727
}
2828

29-
public static func userLogin() {
30-
Pam.shared.updateCustomerID()
29+
public static func userLogin(customerID: String) {
30+
Pam.shared.userLogin(custID: customerID)
3131
}
3232

3333
public static func userLogout() {
@@ -98,12 +98,10 @@ extension Pam {
9898
api.loadConsent(consentMessageID: consentMessageIds)
9999
}
100100

101-
public static func loadConsentDetails(consentMessageIds: String, onLoad: @escaping (ConsentMessage) -> Void) {
101+
public static func loadConsentDetails(consentMessageIds: String, onLoad: @escaping (ConsentMessage?) -> Void) {
102102
loadConsentDetails(consentMessageIds: [consentMessageIds]) { result in
103-
if let msg = result[consentMessageIds] {
104-
DispatchQueue.main.async {
105-
onLoad(msg)
106-
}
103+
DispatchQueue.main.async {
104+
onLoad(result[consentMessageIds])
107105
}
108106
}
109107
}

Sources/Pam/Pam.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ public class Pam: NSObject {
8080

8181
var pushToken:String?
8282

83-
var onGetCustomerID:( ()->String? )?
84-
8583
var _allowTracking:Bool = false
8684
var allowTracking: Bool {
8785
set{
@@ -168,12 +166,6 @@ public class Pam: NSObject {
168166
// }
169167
}
170168

171-
func updateCustomerID(){
172-
if let customerId = onGetCustomerID?() {
173-
self.userLogin(custID: customerId)
174-
}
175-
}
176-
177169
func listen(_ event: String, callBack: @escaping ListenerCallBack) {
178170
if event.lowercased() == "ontoken" {
179171
onToken.append(callBack)
@@ -193,8 +185,6 @@ public class Pam: NSObject {
193185
dispatch("onPushNotification", data: $0)
194186
}
195187
pendingNotification = []
196-
197-
updateCustomerID()
198188
}
199189
}
200190

Sources/Pam/consent/ConsentAPI.swift

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ class ConsentAPI {
116116

117117
isLoading = true
118118
let pamServerURL = Pam.shared.config?.pamServer ?? ""
119-
120-
print("LOAD CONSENT = ","\(pamServerURL)/consent-message/\(consentMessageID)")
121-
119+
122120
HttpClient.getReturnData(url: "\(pamServerURL)/consent-message/\(consentMessageID)", queryString: nil, headers: nil){ data in
123121

124122
if let data = data {
@@ -157,18 +155,33 @@ class ConsentAPI {
157155

158156
isLoading = true
159157
let pamServerURL = Pam.shared.config?.pamServer ?? ""
160-
let contactID = Pam.shared.getContactID() ?? ""
161-
162-
HttpClient.getReturnData(url: "\(pamServerURL)/contacts/\(contactID)/consents/\(consentMessageID)", queryString: nil, headers: nil){ data in
158+
if let contactID = Pam.shared.getContactID() {
163159

164-
if let data = data {
165-
let json = Json(raw: String(data:data, encoding: .utf8) ?? "{}")
166-
let userConsent = UserConsentPermissions.parse(json: json)
167-
self.resultUserConsentLoad?[consentMessageID] = userConsent
160+
HttpClient.getReturnData(url: "\(pamServerURL)/contacts/\(contactID)/consents/\(consentMessageID)", queryString: nil, headers: nil){ data in
161+
162+
if let data = data {
163+
let json = Json(raw: String(data:data, encoding: .utf8) ?? "{}")
164+
165+
let userConsent = UserConsentPermissions.parse(json: json)
166+
self.resultUserConsentLoad?[consentMessageID] = userConsent
167+
}
168+
169+
self.startLoadPermissions()
168170
}
169-
171+
}else{
172+
let userConsent = UserConsentPermissions(consentID: nil,
173+
type: nil,
174+
consentMessageId: consentMessageID,
175+
version: nil,
176+
permissions: nil,
177+
needToReview: true,
178+
lastConsentVersion: nil,
179+
contactID: nil,
180+
lastConsentAt: nil)
181+
self.resultUserConsentLoad?[consentMessageID] = userConsent
170182
self.startLoadPermissions()
171183
}
184+
172185
}
173186

174187
}

Sources/Pam/consent/ConsentMessage.swift

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,14 @@ public struct ConsentMessage: BaseConsentMessage{
141141
}
142142
}
143143

144-
public func setPermission(name: ConsentPermissionName, isAllow: Bool) {
145-
for var item in self.permission{
146-
if item.name.rawValue == name.rawValue {
147-
item.allow = false
144+
public mutating func setPermission(name: ConsentPermissionName, isAllow: Bool) {
145+
146+
for index in 0..<self.permission.count {
147+
if self.permission[index].name == name {
148+
self.permission[index].allow = isAllow
149+
150+
print("SET", self.permission[index].name, "TO" , self.permission[index].allow)
151+
break
148152
}
149153
}
150154
}
@@ -345,7 +349,7 @@ public struct ConsentPermission{
345349

346350

347351
public func getSubmitKey() -> String{
348-
return "_allow_\(name)"
352+
return "_allow_\(name.key)"
349353
}
350354
}
351355

Sources/Pam/consent/UserConsentPermissions.swift

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
public struct UserConsentPermissions{
44

5-
let consentID:String?
6-
let type: ConsentType?
7-
let consentMessageId:String?
8-
let version: Int?
9-
let permissions: [ConsentPermission]?
10-
let needToReview: Bool?
11-
let lastConsentVersion: Int?
12-
let contactID: String?
13-
let lastConsentAt: String?
5+
public let consentID:String?
6+
public let type: ConsentType?
7+
public let consentMessageId:String?
8+
public let version: Int?
9+
public let permissions: [ConsentPermission]?
10+
public let needToReview: Bool?
11+
public let lastConsentVersion: Int?
12+
public let contactID: String?
13+
public let lastConsentAt: String?
1414

1515
private static func getType(type:String?)->ConsentType?{
1616
if(type == "tracking_type"){
@@ -61,7 +61,6 @@ public struct UserConsentPermissions{
6161
fullDescriptionEnabled: false,
6262
require: true,
6363
allow: it)
64-
list.append(perm)
6564
}
6665

6766
if let it = json[\.privacy_overview].bool {
@@ -75,7 +74,7 @@ public struct UserConsentPermissions{
7574
list.append(perm)
7675
}
7776

78-
if let it = json[\.privacy_overview].bool {
77+
if let it = json[\.necessary_cookies].bool {
7978
let perm = ConsentPermission(
8079
name: .necessaryCookies,
8180
shortDescription: nil,
@@ -86,7 +85,7 @@ public struct UserConsentPermissions{
8685
list.append(perm)
8786
}
8887

89-
if let it = json[\.privacy_overview].bool {
88+
if let it = json[\.preferences_cookies].bool {
9089
let perm = ConsentPermission(
9190
name: .preferencesCookies,
9291
shortDescription: nil,
@@ -97,7 +96,7 @@ public struct UserConsentPermissions{
9796
list.append(perm)
9897
}
9998

100-
if let it = json[\.privacy_overview].bool {
99+
if let it = json[\.analytics_cookies].bool {
101100
let perm = ConsentPermission(
102101
name: .analyticsCookies,
103102
shortDescription: nil,
@@ -108,7 +107,7 @@ public struct UserConsentPermissions{
108107
list.append(perm)
109108
}
110109

111-
if let it = json[\.privacy_overview].bool {
110+
if let it = json[\.marketing_cookies].bool {
112111
let perm = ConsentPermission(
113112
name: .marketingCookies,
114113
shortDescription: nil,
@@ -119,7 +118,7 @@ public struct UserConsentPermissions{
119118
list.append(perm)
120119
}
121120

122-
if let it = json[\.privacy_overview].bool {
121+
if let it = json[\.socialMedia_cookies].bool {
123122
let perm = ConsentPermission(
124123
name: .socialMediaCookies,
125124
shortDescription: nil,
@@ -134,7 +133,7 @@ public struct UserConsentPermissions{
134133

135134
if let json = json?[\.contacting_permission].json {
136135

137-
if let it = json[\.privacy_overview].bool {
136+
if let it = json[\.email].bool {
138137
let perm = ConsentPermission(
139138
name: .email,
140139
shortDescription: nil,
@@ -145,7 +144,7 @@ public struct UserConsentPermissions{
145144
list.append(perm)
146145
}
147146

148-
if let it = json[\.privacy_overview].bool {
147+
if let it = json[\.sms].bool {
149148
let perm = ConsentPermission(name: .sms,
150149
shortDescription: nil,
151150
fullDescription: nil,
@@ -155,7 +154,7 @@ public struct UserConsentPermissions{
155154
list.append(perm)
156155
}
157156

158-
if let it = json[\.privacy_overview].bool {
157+
if let it = json[\.line].bool {
159158
let perm = ConsentPermission(name: .line,
160159
shortDescription: nil,
161160
fullDescription: nil,
@@ -165,7 +164,7 @@ public struct UserConsentPermissions{
165164
list.append(perm)
166165
}
167166

168-
if let it = json[\.privacy_overview].bool {
167+
if let it = json[\.facebook_messenger].bool {
169168
let perm = ConsentPermission(name: .facebookMessenger,
170169
shortDescription: nil,
171170
fullDescription: nil,
@@ -175,7 +174,7 @@ public struct UserConsentPermissions{
175174
list.append(perm)
176175
}
177176

178-
if let it = json[\.privacy_overview].bool {
177+
if let it = json[\.push_notification].bool {
179178
let perm = ConsentPermission(name: .pushNotification,
180179
shortDescription: nil,
181180
fullDescription: nil,

0 commit comments

Comments
 (0)