Skip to content

Commit

Permalink
Fix #242: Data Agreements are empty
Browse files Browse the repository at this point in the history
Signed-off-by: George Padayatti <[email protected]>
  • Loading branch information
georgepadayatti committed Jun 23, 2024
1 parent 0a33f0c commit f2257d8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -354,48 +354,52 @@ extension BBConsentBaseWebService {
}

func makeAPICall(urlString: String, parameters: [String: Any] = [:], headers: [String: String] = [:], method: ApiType, completion:@escaping (_ success: Bool, _ resultVal: [String: Any]) -> Void) {
if BBConsentPrivacyDashboardiOS.shared.accessToken != "" && BBConsentPrivacyDashboardiOS.shared.accessToken != nil {
let accessToken = BBConsentPrivacyDashboardiOS.shared.accessToken ?? ""
let hearDict = ["Authorization":"Bearer \(accessToken)"]
header = hearDict
} else {
if let tokendata = BBConsentKeyChainUtils.load(key: "BBConsentApiKey") {
let token = String(data: tokendata, encoding: .utf8) ?? ""
let hearDict = ["Authorization":"ApiKey \(token)", "X-ConsentBB-IndividualId": BBConsentPrivacyDashboardiOS.shared.userId ?? ""]
header = hearDict
} else {
debugPrint("### No API key available!")
var finalHeaders = headers

if let accessToken = BBConsentPrivacyDashboardiOS.shared.accessToken, !accessToken.isEmpty {
finalHeaders["Authorization"] = "Bearer \(accessToken)"
} else if let tokenData = BBConsentKeyChainUtils.load(key: "BBConsentApiKey"), let token = String(data: tokenData, encoding: .utf8), !token.isEmpty {
finalHeaders["Authorization"] = "ApiKey \(token)"
if let userId = BBConsentPrivacyDashboardiOS.shared.userId, !userId.isEmpty {
finalHeaders["X-ConsentBB-IndividualId"] = userId
}
} else {
debugPrint("### No API key available!")
}

/// Specify organisation ID in the header to support multi-tenancy
header?["organizationId"] = BBConsentPrivacyDashboardiOS.shared.orgId ?? ""
if let orgId = BBConsentPrivacyDashboardiOS.shared.orgId, !orgId.isEmpty {
finalHeaders["organizationId"] = orgId
}

var encoding: ParameterEncoding = JSONEncoding.default
if method == .get {
encoding = URLEncoding.default
}

AF.request(urlString, method: HTTPMethod(rawValue: method.rawValue), parameters: parameters, encoding: encoding, headers: HTTPHeaders.init(header ?? [:]))
AF.request(urlString, method: HTTPMethod(rawValue: method.rawValue), parameters: parameters, encoding: encoding, headers: HTTPHeaders(finalHeaders))
.responseJSON { response in
debugPrint("### URL Request: \(String(describing: response.request))")
debugPrint("### URL Response: \(String(describing: response.response))")
debugPrint("### Data: \(String(describing: response.data))")
debugPrint("### Result: \(response.result)")
debugPrint("### Parameters: \(parameters)")

switch response.result {
case .success(let value):
let json = JSON(value as Any)
completion(true, json.rawValue as! [String : Any])
case .failure(let error):
debugPrint(error)
completion(false, [:])
debugPrint("### URL Request: \(String(describing: response.request))")
debugPrint("### URL Response: \(String(describing: response.response))")
debugPrint("### Data: \(String(describing: response.data))")
debugPrint("### Result: \(response.result)")
debugPrint("### Parameters: \(parameters)")

switch response.result {
case .success(let value):
if let json = value as? [String: Any] {
completion(true, json)
} else {
completion(false, [:])
}
case .failure(let error):
debugPrint(error)
completion(false, [:])
}
}
}
}
}


let kResponseBaseKey = "data"
protocol WebServiceTaskManagerProtocol {

Expand Down
6 changes: 3 additions & 3 deletions PrivacyDashboardiOS/Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PODS:
- IQKeyboardManagerSwift (6.5.11)
- Kingfisher (6.3.1)
- MiniLayout (1.3.0)
- PrivacyDashboardiOS (2024.2.1):
- PrivacyDashboardiOS (2024.6.1):
- AFDateHelper
- Alamofire (~> 5.4.1)
- ExpandableLabel
Expand Down Expand Up @@ -51,7 +51,7 @@ SPEC CHECKSUMS:
IQKeyboardManagerSwift: c7955c0bdbf7b2eb29bb7daaa44e3d90f55a9a85
Kingfisher: 016c8b653a35add51dd34a3aba36b580041acc74
MiniLayout: 57c42e7e44cb47a9ef95650970ee1d2718725518
PrivacyDashboardiOS: fef5a33d9beba1ccd8e54b0903ee2b0f690111dc
PrivacyDashboardiOS: d64c21df09198f6a9f4a1c4dd6bf9a307486b9f1
SDStateTableView: 9c69677cc23e56428116dce3f4d7650cb2f6947e
StepProgressView: 6f23d95d0ebb912fc82dbd6a2ba96e805a0a7846
SweeterSwift: 3910bab8ba35b6964d5169a3c52b2c87d930b61c
Expand All @@ -60,4 +60,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 003542bb17705062f2dd63058a21683778c5d454

COCOAPODS: 1.14.2
COCOAPODS: 1.15.2
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ class ViewController: UIViewController {

override func viewDidAppear(_ animated: Bool) {
// 1. For showing Privacy Dashboard
// PrivacyDashboard.showPrivacyDashboard(withApiKey: <API Key>,
// withUserId: <User ID>,
// withOrgId: <Organisation ID>,
// withBaseUrl: <Base Url>,
// withLocale: "en",
// turnOnAskme: false,
// turnOnUserRequest: false,
// turnOnAttributeDetail: false)
PrivacyDashboard.showPrivacyDashboard(withApiKey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTY29wZXMiOlsiY29uZmlnIiwiYXVkaXQiLCJzZXJ2aWNlIiwib25ib2FyZCJdLCJPcmdhbmlzYXRpb25JZCI6IjYzOGRkM2IxMmY1ZDE3MDAwMTQ0MzFlYyIsIk9yZ2FuaXNhdGlvbkFkbWluSWQiOiI2MzhkZDM3ODJmNWQxNzAwMDE0NDMxZWIiLCJEYXRhVmVyaWZpZXJVc2VySWQiOiIiLCJFbnYiOiIiLCJleHAiOjE3NDk2NTA4NzZ9.a2nXRztms8PrE4i3cjElTpn9ktQVmyVd1-NGNoFJ7QU",
withUserId: "6606870683175119a9ab6740",
withOrgId: "638dd3b12f5d1700014431ec",
withBaseUrl: "https://staging-api.igrant.io/v2",
withLocale: "en",
turnOnAskme: false,
turnOnUserRequest: false,
turnOnAttributeDetail: false)

// 2. For showing Data sharing UI
// PrivacyDashboard.showDataSharingUI(apiKey: <API Key >,
Expand All @@ -45,10 +45,11 @@ class ViewController: UIViewController {


// 4. Setting API configuring params
// PrivacyDashboard.configure(withApiKey: <API Key >,
// withUserId: <User ID>,
// withOrgId: <Organisation ID>,
// withBaseUrl: <Base Url>)
PrivacyDashboard.configure(withApiKey: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJTY29wZXMiOlsiY29uZmlnIiwiYXVkaXQiLCJzZXJ2aWNlIiwib25ib2FyZCJdLCJPcmdhbmlzYXRpb25JZCI6IjYzOGRkM2IxMmY1ZDE3MDAwMTQ0MzFlYyIsIk9yZ2FuaXNhdGlvbkFkbWluSWQiOiI2MzhkZDM3ODJmNWQxNzAwMDE0NDMxZWIiLCJEYXRhVmVyaWZpZXJVc2VySWQiOiIiLCJFbnYiOiIiLCJleHAiOjE3NDk2NTA4NzZ9.a2nXRztms8PrE4i3cjElTpn9ktQVmyVd1-NGNoFJ7QU",
withUserId: "6606870683175119a9ab6740",
withOrgId: "638dd3b12f5d1700014431ec",
withBaseUrl: "https://staging-api.igrant.io/v2",
withLocale: "en")


// 5. Update Data agreement
Expand All @@ -64,9 +65,9 @@ class ViewController: UIViewController {
// PrivacyDashboard.showDataAgreementPolicy(dataAgreementRecord: <JSON data of "dataAgreement" response>)

// 8. Read data agreement
// PrivacyDashboard.readDataAgreementApi(dataAgreementId: <Organisation ID>) { success, resultVal in
// print(resultVal)
// }
PrivacyDashboard.readDataAgreementApi(dataAgreementId: "65f22388e41f97425dcf284c") { success, resultVal in
print(resultVal)
}

}

Expand Down

0 comments on commit f2257d8

Please sign in to comment.