Manos Chorianopoulos

Add handleSMDealsCampaign

...@@ -3382,6 +3382,44 @@ public class swiftApi { ...@@ -3382,6 +3382,44 @@ public class swiftApi {
3382 } 3382 }
3383 3383
3384 3384
3385 + public func constructSMCampaignParams(_ campaign: CampaignItemModel, _ from_widget: Bool, _ dlParam: String) -> String {
3386 + let instanceOfMyApi = MyApi()
3387 + let campaignInfo = instanceOfMyApi.provideInfoForCampaign()
3388 +
3389 + let jsonObject: [String: String] = [
3390 + "web_id": (campaignInfo?["web_id"] as! String),
3391 + "app_uuid": (campaignInfo?["app_uuid"] as! String),
3392 + "api_key": (campaignInfo?["api_key"] as! String),
3393 + "session_uuid": (campaign.session_uuid ?? ""),
3394 + "access_token": (campaignInfo?["access_token"] as! String),
3395 + "refresh_token": (campaignInfo?["refresh_token"] as! String),
3396 + "client_id": (campaignInfo?["client_id"] as! String),
3397 + "client_secret": (campaignInfo?["client_secret"] as! String),
3398 + "from_widget": (from_widget ? "true" : "false"),
3399 + "dl_param": dlParam
3400 + ]
3401 +
3402 + let encoder = JSONEncoder()
3403 + encoder.outputFormatting = .prettyPrinted
3404 + let data = try! encoder.encode(jsonObject)
3405 + let stringData = String(data: data, encoding: .utf8) ?? ""
3406 +
3407 + print("constructSMCampaignParams: " + stringData)
3408 + return stringData
3409 +
3410 + // do {
3411 + // let data = try JSONSerialization.data(withJSONObject: jsonObject, options: .prettyPrinted)
3412 + // let stringData = String(data: data, encoding: String.Encoding.utf8) ?? ""
3413 + // print("constructCampaignParams: " + stringData)
3414 + // return stringData
3415 + // } catch {
3416 + // print("constructCampaignParams: ")
3417 + // return ""
3418 + // }
3419 +
3420 + }
3421 +
3422 +
3385 public func constructCcmsParams(_ campaign: LoyaltyContextualOfferModel) -> String { 3423 public func constructCcmsParams(_ campaign: LoyaltyContextualOfferModel) -> String {
3386 3424
3387 for item in GlobalVariables.campaigns { 3425 for item in GlobalVariables.campaigns {
...@@ -4084,6 +4122,29 @@ public class swiftApi { ...@@ -4084,6 +4122,29 @@ public class swiftApi {
4084 } 4122 }
4085 4123
4086 4124
4125 + public func handleSMDealsCampaign(_ controller: UIViewController, _ dlParam: String) -> Void {
4126 + let status = swiftApi().getNetworkStatus()
4127 + if (status == -1 || status == 0) {
4128 + swiftApi().showDialog(controller, "Δεν υπάρχει σύνδεση","Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.")
4129 +
4130 + } else {
4131 + for item in GlobalVariables.campaigns {
4132 + if (item.session_uuid == "39e70f0548884020809dda5f78d06c85" || item.session_uuid == "8314046c83a44576a03ccc3cd9e825db") {
4133 + let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
4134 + let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController
4135 + let url = swiftApi().constructCampaignUrl(item)
4136 + let params = swiftApi().constructSMCampaignParams(item, true, dlParam)
4137 + print("handleSMDealsCampaign url: " + url)
4138 + vc.campaignUrl = url
4139 + vc.params = params
4140 + vc.showHeader = false
4141 + controller.navigationController?.pushViewController(vc, animated: true)
4142 + break;
4143 + }
4144 + }
4145 + }
4146 + }
4147 +
4087 public func openPacing(_ controller: UIViewController) -> Void { 4148 public func openPacing(_ controller: UIViewController) -> Void {
4088 let status = swiftApi().getNetworkStatus() 4149 let status = swiftApi().getNetworkStatus()
4089 if (status == -1 || status == 0) { 4150 if (status == -1 || status == 0) {
......