Skip to content

Commit

Permalink
Merge pull request #582 from SourcePointUSA/DIA-4457_mobile-core_cons…
Browse files Browse the repository at this point in the history
…ent-status

DIA-4457 use mobil-core `/consent-status`
  • Loading branch information
andresilveirah authored Sep 12, 2024
2 parents 5510630 + b04e396 commit 3e9143d
Show file tree
Hide file tree
Showing 22 changed files with 4,049 additions and 3,924 deletions.
2 changes: 1 addition & 1 deletion ConsentViewController.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Pod::Spec.new do |s|
s.source = { :git => 'https://github.com/SourcePointUSA/ios-cmp-app.git', :tag => s.version.to_s }
s.swift_version = '5.1'
s.source_files = 'ConsentViewController/Classes/**/*'
s.dependency 'SPMobileCore', '0.0.3'
s.dependency 'SPMobileCore', '0.0.4'
s.ios.deployment_target = '10.0'
s.ios.exclude_files = 'ConsentViewController/Classes/Views/tvOS'
s.tvos.deployment_target = '12.0'
Expand Down
2 changes: 1 addition & 1 deletion ConsentViewController/Classes/SPDate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public struct SPDate: Codable, Equatable {
public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
originalDateString = try container.decode(String.self)
date = Self.format.date(from: originalDateString) ?? Date() // TODO: potentially throw an error here...
date = Self.format.date(from: originalDateString) ?? Date()
}

static func now() -> SPDate {
Expand Down
106 changes: 106 additions & 0 deletions ConsentViewController/Classes/SourcePointClient/Adapters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,112 @@
import Foundation
import SPMobileCore

extension SPMobileCore.CCPAConsent.CCPAConsentStatus {
func toNative() -> CCPAConsentStatus {
switch name {
case "ConsentedAll": return .ConsentedAll
case "RejectedAll": return .RejectedAll
case "RejectedSome": return .RejectedSome
case "RejectedNone": return .RejectedNone
case "LinkedNoAction": return .LinkedNoAction
default: return .Unknown
}
}
}

extension SPMobileCore.USNatConsent.USNatConsentSection {
func toNative() -> SPUSNatConsent.ConsentString {
.init(
sectionId: Int(sectionId),
sectionName: sectionName,
consentString: consentString
)
}
}

extension SPMobileCore.USNatConsent.USNatConsentable {
func toNative() -> SPConsentable {
.init(id: id, consented: consented)
}
}

extension SPMobileCore.USNatConsent.USNatUserConsents {
func toNative() -> SPUSNatConsent.UserConsents {
.init(
vendors: vendors.map { $0.toNative() },
categories: categories.map { $0.toNative() }
)
}
}

extension SPMobileCore.GDPRConsent.VendorGrantsValue {
func toNative() -> SPGDPRVendorGrant {
.init(
granted: vendorGrant,
purposeGrants: purposeGrants.mapValues { $0.boolValue }
)
}
}

extension SPMobileCore.GDPRConsent.GCMStatus {
func toNative() -> SPGCMData {
.init(
adStorage: .init(rawValue: adStorage ?? ""),
analyticsStorage: .init(rawValue: analyticsStorage ?? ""),
adUserData: .init(rawValue: adUserData ?? ""),
adPersonalization: .init(rawValue: adPersonalization ?? "")
)
}
}

extension SPMobileCore.ConsentStatus {
func toNative() -> ConsentStatus {
.init(
granularStatus: granularStatus?.toNative(),
rejectedAny: rejectedAny?.boolValue,
rejectedLI: rejectedLI?.boolValue,
consentedAll: consentedAll?.boolValue,
consentedToAll: consentedToAll?.boolValue,
consentedToAny: consentedToAny?.boolValue,
rejectedAll: rejectedAll?.boolValue,
vendorListAdditions: vendorListAdditions?.boolValue,
legalBasisChanges: legalBasisChanges?.boolValue,
hasConsentData: hasConsentData?.boolValue
)
}
}

extension [String: Kotlinx_serialization_jsonJsonPrimitive] {
func toNative() -> SPJson? {
try? SPJson(compactMapValues { ($0.isString ? $0.content : Int($0.content) as Any) })
}
}

extension SPMobileCore.ConsentStatus.ConsentStatusGranularStatus {
func toNative() -> ConsentStatus.GranularStatus {
.init(
vendorConsent: vendorConsent,
vendorLegInt: vendorLegInt,
purposeConsent: purposeConsent,
purposeLegInt: purposeLegInt,
previousOptInAll: previousOptInAll?.boolValue,
defaultConsent: defaultConsent?.boolValue
)
}
}

extension SPIDFAStatus {
func toCore() -> SPMobileCore.SPIDFAStatus {
switch self {
case .accepted: return .accepted
case .denied: return .denied
case .unavailable: return .unavailable
case .unknown: return .unknown
default: return .unknown
}
}
}

extension SPDate {
init(string: String) {
originalDateString = string
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typealias GDPRConsentHandler = (Result<GDPRChoiceResponse, SPError>) -> Void
typealias USNatConsentHandler = (Result<SPUSNatConsent, SPError>) -> Void
typealias ConsentHandler<T: Decodable & Equatable> = (Result<(SPJson, T), SPError>) -> Void
typealias AddOrDeleteCustomConsentHandler = (Result<AddOrDeleteCustomConsentResponse, SPError>) -> Void
typealias ConsentStatusHandler = (Result<ConsentStatusResponse, SPError>) -> Void
typealias ConsentStatusHandler = (Result<SPMobileCore.ConsentStatusResponse, SPError>) -> Void
typealias MessagesHandler = (Result<MessagesResponse, SPError>) -> Void
typealias PvDataHandler = (Result<PvDataResponse, SPError>) -> Void
typealias MetaDataHandler = (Result<SPMobileCore.MetaDataResponse, SPError>) -> Void
Expand Down Expand Up @@ -144,10 +144,8 @@ protocol SourcePointProtocol {
)

func consentStatus(
propertyId: Int,
metadata: ConsentStatusMetaData,
metadata: SPMobileCore.ConsentStatusRequest.MetaData,
authId: String?,
includeData: IncludeData,
handler: @escaping ConsentStatusHandler
)

Expand Down Expand Up @@ -422,43 +420,20 @@ class SourcePointClient: SourcePointProtocol {

// MARK: V7 - cost optimised APIs
extension SourcePointClient {
func consentStatusURLWithParams(
propertyId: Int,
metadata: ConsentStatusMetaData,
includeData: IncludeData,
authId: String?) -> URL? {
var url = Constants.Urls.CONSENT_STATUS_URL.appendQueryItems([
"propertyId": String(propertyId),
"metadata": metadata.stringified(),
"hasCsp": "true",
"withSiteActions": "false",
"includeData": includeData.string
])
if let authId = authId {
url = url?.appendQueryItems(["authId": authId])
}
return url
}

func consentStatus(
propertyId: Int,
metadata: ConsentStatusMetaData,
metadata: SPMobileCore.ConsentStatusRequest.MetaData,
authId: String?,
includeData: IncludeData,
handler: @escaping ConsentStatusHandler
) {
guard let url = consentStatusURLWithParams(
propertyId: propertyId,
metadata: metadata,
includeData: includeData,
authId: authId
) else {
handler(Result.failure(InvalidConsentStatusQueryParamsError()))
return
}

client.get(urlString: url.absoluteString, apiCode: .CONSENT_STATUS) {
Self.parseResponse($0, InvalidConsentStatusResponseError(), handler)
coreClient.getConsentStatus(
authId: authId,
metadata: metadata
) { response, error in
if error != nil || response == nil {
handler(Result.failure(InvalidConsentStatusResponseError()))
} else {
handler(Result.success(response!)) // swiftlint:disable:this force_unwrapping
}
}
}

Expand Down
Loading

0 comments on commit 3e9143d

Please sign in to comment.