Skip to content

Commit 64f04de

Browse files
SP-8288 ott unexpected response message endpoint (#353)
* implement onSPFinished callback * make sure onAction is called on the main thread * URL? is replaced with String? for policyUrl both in Vendor and GDPRVendor structs * URL? is replaced with String? for policyUrl to avoid crash when policyUrl is malformed during ccpaPrivacyManagerView * fix * Revert all changes * Now init(from decoder) is implemented for handling typos in policyUrl Co-authored-by: André Herculano <[email protected]>
1 parent e139fdc commit 64f04de

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

ConsentViewController/Classes/SourcePointClient/GDPRPrivacyManagerViewResponse.swift

+34-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,35 @@ struct GDPRVendor: Decodable {
2525
let vendorType: VendorType
2626
let consentCategories, legIntCategories: [Category]
2727
let iabSpecialPurposes, iabFeatures, iabSpecialFeatures: [String]
28+
29+
enum Keys: String, CodingKey {
30+
case policyUrl, vendorId, name
31+
case iabId
32+
case iabSpecialPurposes, iabFeatures, iabSpecialFeatures
33+
case description, cookieHeader
34+
case vendorType
35+
case consentCategories, legIntCategories
36+
}
37+
38+
init(from decoder: Decoder) throws {
39+
let container = try decoder.container(keyedBy: Keys.self)
40+
do {
41+
policyUrl = try container.decodeIfPresent(URL.self, forKey: .policyUrl)
42+
} catch {
43+
policyUrl = nil
44+
}
45+
iabId = try container.decodeIfPresent(Int.self, forKey: .iabId)
46+
vendorId = try container.decode(String.self, forKey: .vendorId)
47+
name = try container.decode(String.self, forKey: .name)
48+
iabSpecialPurposes = try container.decode([String].self, forKey: .iabSpecialPurposes)
49+
iabFeatures = try container.decode([String].self, forKey: .iabFeatures)
50+
iabSpecialFeatures = try container.decode([String].self, forKey: .iabSpecialFeatures)
51+
description = try container.decodeIfPresent(String.self, forKey: .description)
52+
cookieHeader = try container.decodeIfPresent(String.self, forKey: .cookieHeader)
53+
vendorType = try container.decode(VendorType.self, forKey: .vendorType)
54+
consentCategories = try container.decode([Category].self, forKey: .consentCategories)
55+
legIntCategories = try container.decode([Category].self, forKey: .legIntCategories)
56+
}
2857
}
2958

3059
extension GDPRVendor: Identifiable, Equatable, Hashable {
@@ -81,7 +110,11 @@ extension CCPAVendor: Decodable {
81110
let container = try decoder.container(keyedBy: Keys.self)
82111
_id = try container.decode(String.self, forKey: ._id)
83112
name = try container.decode(String.self, forKey: .name)
84-
policyUrl = try container.decodeIfPresent(URL.self, forKey: .policyUrl)
113+
do {
114+
policyUrl = try container.decodeIfPresent(URL.self, forKey: .policyUrl)
115+
} catch {
116+
policyUrl = nil
117+
}
85118
nullablePurposes = try container.decodeIfPresent([String?].self, forKey: .nullablePurposes)
86119
}
87120

ConsentViewController/Classes/SourcePointClient/SPPrivacyManagerRequestresponse.swift

+18
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,24 @@ import Foundation
1717
let vendorId: String?
1818
let policyUrl: URL?
1919
let vendorType: GDPRVendor.VendorType?
20+
21+
enum Keys: String, CodingKey {
22+
case name
23+
case vendorId
24+
case policyUrl
25+
case vendorType
26+
}
27+
28+
init(from decoder: Decoder) throws {
29+
let container = try decoder.container(keyedBy: Keys.self)
30+
do {
31+
policyUrl = try container.decodeIfPresent(URL.self, forKey: .policyUrl)
32+
} catch {
33+
policyUrl = nil
34+
}
35+
vendorId = try container.decodeIfPresent(String.self, forKey: .vendorId)
36+
name = try container.decode(String.self, forKey: .name)
37+
vendorType = try container.decodeIfPresent(GDPRVendor.VendorType.self, forKey: .vendorType) }
2038
}
2139

2240
let iabId: Int?

0 commit comments

Comments
 (0)