Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SP-7885 add pubData loadMessage #362

Merged
merged 3 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ConsentViewController/Classes/SPAction.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import Foundation
return nil
}
public var pmPayload: SPJson = SPJson()
public var publisherData: [String: SPJson?] = [:]
public var publisherData: SPPublisherData = [:]
public var customActionId: String?

public override var description: String {
Expand Down
3 changes: 2 additions & 1 deletion ConsentViewController/Classes/SPConsentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,14 @@ import UIKit
/// Returns the user data **stored in the `UserDefaults`**.
public var userData: SPUserData { storage.userData }

public func loadMessage(forAuthId authId: String? = nil) {
public func loadMessage(forAuthId authId: String? = nil, publisherData: SPPublisherData? = [:]) {
self.authId = authId
responsesToReceive += 1
spClient.getMessages(
campaigns: campaigns,
authId: authId,
localState: storage.localState,
pubData: publisherData ?? [:],
idfaStaus: idfaStatus,
consentLanguage: messageLanguage
) { [weak self] result in
Expand Down
6 changes: 3 additions & 3 deletions ConsentViewController/Classes/SPSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import Foundation
campaigns: SPCampaigns,
delegate: SPDelegate?
)
@objc func loadMessage(forAuthId authId: String?)
@objc func loadMessage(forAuthId authId: String?, publisherData: SPPublisherData?)
@objc func customConsentGDPR(
vendors: [String],
categories: [String],
Expand All @@ -52,8 +52,8 @@ public extension SPSDK {
self.init(accountId: accountId, propertyName: propertyName, campaignsEnv: campaignsEnv, campaigns: campaigns, delegate: delegate)
}

func loadMessage(forAuthId authId: String? = "") {
loadMessage(forAuthId: authId)
func loadMessage(forAuthId authId: String? = "", pubData: SPPublisherData? = [:]) {
loadMessage(forAuthId: authId, publisherData: pubData)
}

func loadCCPAPrivacyManager(withId id: String, tab: SPPrivacyManagerTab = .Default) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,24 @@ struct GDPRConsentRequest: Encodable, Equatable {
let idfaStatus: SPIDFAStatus
let localState: SPJson
let pmSaveAndExitVariables: SPJson?
let publisherData: [String: SPJson?]?
let pubData: SPPublisherData
let requestUUID: UUID
let includeData = [
"localState": ["type": "RecordString"],
"TCData": ["type": "RecordString"]
]

enum CodingKeys: String, CodingKey {
case authId, localState, idfaStatus, pmSaveAndExitVariables, requestUUID, includeData
case publisherData = "pubData"
}
}

struct CCPAConsentRequest: Encodable, Equatable {
let authId: String?
let localState: SPJson
let publisherData: [String: SPJson?]?
let pubData: SPPublisherData
let pmSaveAndExitVariables: SPJson?
let requestUUID: UUID
let includeData = [
"localState": ["type": "RecordString"],
"TCData": ["type": "RecordString"]
]

enum CodingKeys: String, CodingKey {
case authId, localState, pmSaveAndExitVariables, requestUUID, includeData
case publisherData = "pubData"
}
}

struct ConsentResponse: Decodable & Equatable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ struct MessageRequest: Equatable, Encodable {
let localState: SPJson
let consentLanguage: SPMessageLanguage
let campaigns: CampaignsRequest
let pubData: SPPublisherData
let includeData = [
"localState": ["type": "RecordString"],
"TCData": ["type": "RecordString"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// SPPublisherData.swift
// Pods
//
// Created by Andre Herculano on 03.02.22.
//

import Foundation

/// A dictionary of `[String: String]` of arbitrary key/values used to send data from the publisher
/// app to our data pipeline so it can be later retrieved by the publisher via specific APIs.
///
/// Example: The publisher can send user identifiers that will be aggregated to our data. When the publisher
/// pull the data from our APIs they will be able to match our data against the data they have sent.
public typealias SPPublisherData = [String: String]
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ protocol SourcePointProtocol {
campaigns: SPCampaigns,
authId: String?,
localState: SPJson,
pubData: SPPublisherData,
idfaStaus: SPIDFAStatus,
consentLanguage: SPMessageLanguage,
handler: @escaping MessagesHandler)
Expand Down Expand Up @@ -154,6 +155,7 @@ class SourcePointClient: SourcePointProtocol {
campaigns: SPCampaigns,
authId: String?,
localState: SPJson,
pubData: SPPublisherData,
idfaStaus: SPIDFAStatus,
consentLanguage: SPMessageLanguage,
handler: @escaping MessagesHandler) {
Expand All @@ -166,7 +168,8 @@ class SourcePointClient: SourcePointProtocol {
idfaStatus: idfaStaus,
localState: localState,
consentLanguage: consentLanguage,
campaigns: CampaignsRequest(from: campaigns)
campaigns: CampaignsRequest(from: campaigns),
pubData: pubData
)).map { body in
client.post(urlString: Constants.Urls.GET_MESSAGES_URL.absoluteString, body: body) { result in
handler(Result {
Expand Down Expand Up @@ -261,7 +264,7 @@ class SourcePointClient: SourcePointProtocol {
_ = JSONEncoder().encodeResult(CCPAConsentRequest(
authId: authId,
localState: localState,
publisherData: action.publisherData,
pubData: action.publisherData,
pmSaveAndExitVariables: action.pmPayload,
requestUUID: requestUUID
)).map { body in
Expand All @@ -285,7 +288,7 @@ class SourcePointClient: SourcePointProtocol {
idfaStatus: SPIDFAStatus.current(),
localState: localState,
pmSaveAndExitVariables: action.pmPayload,
publisherData: action.publisherData,
pubData: action.publisherData,
requestUUID: requestUUID
)).map { body in
client.post(urlString: consentUrl(Constants.Urls.GDPR_CONSENT_URL, action.type)!.absoluteString, body: body) { result in
Expand Down
14 changes: 3 additions & 11 deletions Example/ConsentViewController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@
8255B6D227A9661100C9A70D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8255B6D027A9661100C9A70D /* Main.storyboard */; };
8255B6D427A9661200C9A70D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 8255B6D327A9661200C9A70D /* Assets.xcassets */; };
8255B6D727A9661200C9A70D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 8255B6D527A9661200C9A70D /* LaunchScreen.storyboard */; };
8255B6E027A9818100C9A70D /* ConsentViewController in Frameworks */ = {isa = PBXBuildFile; productRef = 8255B6DF27A9818100C9A70D /* ConsentViewController */; };
8255B6E227A981A100C9A70D /* ConsentViewController in Frameworks */ = {isa = PBXBuildFile; productRef = 8255B6E127A981A100C9A70D /* ConsentViewController */; };
8258D626272191A1005AAB2E /* ExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8258D625272191A1005AAB2E /* ExampleApp.swift */; };
82665C312444ECF600CCE738 /* SPJsonSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82665C302444ECF600CCE738 /* SPJsonSpec.swift */; };
Expand Down Expand Up @@ -487,7 +486,6 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
8255B6E027A9818100C9A70D /* ConsentViewController in Frameworks */,
64B6B37A1D93FA0A7D4913C6 /* Pods_ConsentViewController_Example.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1413,7 +1411,6 @@
);
name = ConsentViewController_Example;
packageProductDependencies = (
8255B6DF27A9818100C9A70D /* ConsentViewController */,
);
productName = ConsentViewController;
productReference = 607FACD01AFB9204008FA782 /* SPGDPRExampleApp.app */;
Expand Down Expand Up @@ -1766,7 +1763,7 @@
);
mainGroup = 607FACC71AFB9204008FA782;
packageReferences = (
8255B6DE27A9818100C9A70D /* XCRemoteSwiftPackageReference "ios-cmp-app.git" */,
8255B6DE27A9818100C9A70D /* XCRemoteSwiftPackageReference "ios-cmp-app" */,
);
productRefGroup = 607FACD11AFB9204008FA782 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -4069,7 +4066,7 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
8255B6DE27A9818100C9A70D /* XCRemoteSwiftPackageReference "ios-cmp-app.git" */ = {
8255B6DE27A9818100C9A70D /* XCRemoteSwiftPackageReference "ios-cmp-app" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "http://github.com/SourcePointUSA/ios-cmp-app.git";
requirement = {
Expand All @@ -4080,14 +4077,9 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
8255B6DF27A9818100C9A70D /* ConsentViewController */ = {
isa = XCSwiftPackageProductDependency;
package = 8255B6DE27A9818100C9A70D /* XCRemoteSwiftPackageReference "ios-cmp-app.git" */;
productName = ConsentViewController;
};
8255B6E127A981A100C9A70D /* ConsentViewController */ = {
isa = XCSwiftPackageProductDependency;
package = 8255B6DE27A9818100C9A70D /* XCRemoteSwiftPackageReference "ios-cmp-app.git" */;
package = 8255B6DE27A9818100C9A70D /* XCRemoteSwiftPackageReference "ios-cmp-app" */;
productName = ConsentViewController;
};
/* End XCSwiftPackageProductDependency section */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "http://github.com/SourcePointUSA/ios-cmp-app.git",
"state": {
"branch": null,
"revision": "cc3c5e6cd89796977818c541f7c5c2fcf35b01b1",
"version": "6.4.1"
"revision": "2e9492e767387b4647af903a454e8a6f2edede01",
"version": "6.4.1-beta.0"
}
}
]
Expand Down
4 changes: 3 additions & 1 deletion Example/ConsentViewController/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
updateIDFAStatusLabel()
consentManager.loadMessage()
consentManager.loadMessage(forAuthId: nil, publisherData: ["foo": "load message"])
}
}

Expand All @@ -73,6 +73,8 @@ extension ViewController: SPDelegate {

func onAction(_ action: SPAction, from controller: UIViewController) {
print(action)
action.publisherData = ["foo": "action"]
print(action)
}

func onSPUIFinished(_ controller: UIViewController) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class SourcePointClientSpec: QuickSpec {
),
ccpa: CampaignRequest(targetingParams: [:]),
ios14: CampaignRequest(targetingParams: [:])
)))
),
pubData: [:]
))
}

override func spec() {
Expand All @@ -71,12 +73,12 @@ class SourcePointClientSpec: QuickSpec {

describe("getMessage") {
it("calls POST on the http client with the right url") {
client.getMessages(campaigns: self.campaigns, authId: nil, localState: SPJson(), idfaStaus: .unknown, consentLanguage: .English) { _ in }
client.getMessages(campaigns: self.campaigns, authId: nil, localState: SPJson(), pubData: [:], idfaStaus: .unknown, consentLanguage: .English) { _ in }
expect(httpClient?.postWasCalledWithUrl).to(equal("https://cdn.privacy-mgmt.com/wrapper/unified/v1/gdpr/message?inApp=true"))
}

it("calls POST on the http client with the right body") {
client.getMessages(campaigns: self.campaigns, authId: nil, localState: SPJson(), idfaStaus: .unknown, consentLanguage: .English) { _ in }
client.getMessages(campaigns: self.campaigns, authId: nil, localState: SPJson(), pubData: [:], idfaStaus: .unknown, consentLanguage: .English) { _ in }
let parsed = httpClient!.postWasCalledWithBody!
expect(parsed).toEventually(equal(self.getMessageRequest(client)))
}
Expand All @@ -96,13 +98,13 @@ class SourcePointClientSpec: QuickSpec {

it("calls POST on the http client with the right body") {
let action = SPAction(type: .AcceptAll, consentLanguage: "EN")
action.publisherData = ["foo": try? SPJson("bar")]
action.publisherData = ["foo": "bar"]
let consentRequest = GDPRConsentRequest(
authId: nil,
idfaStatus: .accepted,
localState: SPJson(),
pmSaveAndExitVariables: nil,
publisherData: nil,
publisherData: [:],
requestUUID: UUID()
)
// client.postAction(
Expand Down
2 changes: 1 addition & 1 deletion Example/ObjC-ExampleApp/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ - (void)viewDidLoad {
campaigns: campaigns
delegate: self];

[consentManager loadMessageForAuthId: NULL];
[consentManager loadMessageForAuthId: NULL publisherData:NULL];
}

- (void)onSPUIReady:(SPMessageViewController * _Nonnull)controller {
Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 4f125b76b86e28773fe5e6f3001f3274b43e77b3

COCOAPODS: 1.10.1
COCOAPODS: 1.11.2
2 changes: 1 addition & 1 deletion Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading