Skip to content

Commit

Permalink
Merge branch 'main' of github.com:decentralised-dataexchange/bb-conse…
Browse files Browse the repository at this point in the history
…nt-ios-privacy-dashboard into feature/148-Update-new-data-sharing-UI-Flow

# Conflicts:
#	PrivacyDashboardiOS/Example/PrivacyDashboardiOS/ViewController.swift
  • Loading branch information
Mumthasir mohammed committed Nov 14, 2023
2 parents 19c1471 + 0c7f2e2 commit b7e0b9c
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
70 changes: 68 additions & 2 deletions PrivacyDashboardiOS/Classes/PrivacyDashboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public class PrivacyDashboard {

readDataAgreementRecordApi(dataAgreementId: dataAgreementId) { success, resultVal in
if resultVal["errorCode"] as? Int != 500 && !(resultVal["consentRecord"] is NSNull) {
// If existing record found for the data agreement ID (status code will be !500)
// If existing record found for the data agreement ID
// Return the records reponse
self.receiveDataBackFromPrivacyDashboard?(resultVal)
} else {
// If no record found for the data agreement ID (status code will be 500)
// If no record found for the data agreement ID
// Navigate to Data sharing UI screen
let navVC = UINavigationController.init(rootViewController: sharingVC)
navVC.modalPresentationStyle = .fullScreen
Expand All @@ -64,6 +64,72 @@ public class PrivacyDashboard {
}
}

public static func configure(withApiKey: String, withUserId: String, withOrgId: String, withBaseUrl: String, accessToken: String = "") {
let frameworkBundle = Bundle(for: BBConsentOrganisationViewController.self)
let bundleURL = frameworkBundle.resourceURL?.appendingPathComponent("PrivacyDashboardiOS.bundle")
var storyboard = UIStoryboard()
if let resourceBundle = Bundle(url: bundleURL!) {
storyboard = UIStoryboard(name: "PrivacyDashboard", bundle: resourceBundle)
} else {
let myBundle = Bundle(for: BBConsentOrganisationViewController.self)
storyboard = UIStoryboard(name: "PrivacyDashboard", bundle: myBundle)
}
BBConsentPrivacyDashboardiOS.shared.userId = withUserId
BBConsentPrivacyDashboardiOS.shared.accessToken = accessToken
let sharingVC = storyboard.instantiateViewController(withIdentifier: "BBConsentDataSharingVC") as? BBConsentDataSharingVC ?? BBConsentDataSharingVC()
// Passing other required info
let data = withApiKey.data(using: .utf8) ?? Data()
_ = BBConsentKeyChainUtils.save(key: "BBConsentApiKey", data: data)
BBConsentPrivacyDashboardiOS.shared.baseUrl = withBaseUrl
sharingVC.dataAgreementId = withOrgId
}

public static func updateDataAgreementStatus(dataAgreementId: String, status: Bool) {
readDataAgreementRecordApi(dataAgreementId: dataAgreementId) { success, resultVal in
if resultVal["errorCode"] as? Int != 500 && !(resultVal["consentRecord"] is NSNull) {
// If existing record found for the data agreement ID
let resultDict = resultVal["consentRecord"] as? [String: Any]
guard let recordId = resultDict?["id"] else { return }
updateRecordApiCall(dataAgreementId: dataAgreementId, recordId: recordId as! String, status: status) { resultVal in
debugPrint(resultVal)
self.receiveDataBackFromPrivacyDashboard?(resultVal)
}
} else {
// If no record found for the data agreement ID
createRecordApiCall(dataAgreementId: dataAgreementId) { resultVal in
debugPrint(resultVal)
self.receiveDataBackFromPrivacyDashboard?(resultVal)
}
}
}
}

private static func createRecordApiCall(dataAgreementId: String, completion: @escaping (_ resultVal: [String: Any]) -> Void) {
BBConsentBaseWebService.shared.makeAPICall(urlString: Constant.URLStrings.fetchDataAgreement + (dataAgreementId), parameters: [:], method: .post) { success, resultVal in
if success {
debugPrint(resultVal)
completion(resultVal)
} else {
debugPrint(resultVal)
completion(resultVal)
}
}
}

private static func updateRecordApiCall(dataAgreementId: String, recordId: String, status: Bool, completion: @escaping (_ resultVal: [String: Any]) -> Void) {
let parameters = ["optIn" : status]
let url = BBConsentPrivacyDashboardiOS.shared.baseUrl + "/service/individual/record/consent-record/" + (recordId) + "?dataAgreementId=" + dataAgreementId
BBConsentBaseWebService.shared.makeAPICall(urlString: url, parameters: parameters, method: .put) { success, resultVal in
if success {
debugPrint(resultVal)
completion(resultVal)
} else {
debugPrint(resultVal)
completion(resultVal)
}
}
}

// MARK: - Read data agreement api call
private static func readDataAgreementRecordApi(dataAgreementId: String, completionBlock:@escaping (_ success: Bool, _ resultVal: [String: Any]) -> Void){
BBConsentBaseWebService.shared.makeAPICall(urlString: Constant.URLStrings.fetchDataAgreement + dataAgreementId, parameters: [:], method: .get) { success, resultVal in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ class ViewController: UIViewController {
termsOfServiceText: "Terms of service.",
termsOfServiceUrl: "http://google.com",
cancelButtonText: "Cancel")


// 3. Call back method to receive response back
PrivacyDashboard.receiveDataBackFromPrivacyDashboard = { data in
debugPrint("Data receieved here:\(data)")
}


// 4. Setting API configuring params
// PrivacyDashboard.configure(withApiKey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTY29wZXMiOlsic2VydmljZSJdLCJPcmdhbmlzYXRpb25JZCI6IjY1MjY1Nzk2OTM4MGYzNWZhMWMzMDI0NSIsIk9yZ2FuaXNhdGlvbkFkbWluSWQiOiI2NTI2NTc5NjkzODBmMzVmYTFjMzAyNDMiLCJleHAiOjE3MDA3MjkxOTF9.2rkHNiLDjQi8WOy4CWn96sMBx8KkvFCUMU0Xe6oXNbY", withUserId: "65378403b3f442eb9381b38d", withOrgId: "64f09f778e5f3800014a879a", withBaseUrl: "https://staging-consent-bb-api.igrant.io/v2")

Expand Down

0 comments on commit b7e0b9c

Please sign in to comment.