Vasilis

addition of campaigns at swiftApi

......@@ -200,4 +200,72 @@ public class swiftApi {
return CouponsDataModel().getData
}
public class CampaignItemModel {
let index_url: String?
let logo_url: String?
let offer_category: String?
let title: String?
let subtitle: String?
let session_uuid: String?
let subcategory: String?
init(dictionary: [String: Any]) {
self.index_url = dictionary["index_url"] as? String? ?? ""
self.logo_url = dictionary["logo_url"] as? String? ?? ""
self.offer_category = dictionary["offer_category"] as? String? ?? ""
self.title = dictionary["title"] as? String? ?? ""
self.subtitle = dictionary["subtitle"] as? String? ?? ""
self.session_uuid = dictionary["session_uuid"] as? String? ?? ""
// let extra_fields = dictionary["extra_fields"] as? [String: Any]? ?? ["":""]
let extra_fields = dictionary["extra_fields"] as AnyObject
var extra_fields_parsed:[String: Any]
let json = extra_fields.data(using: String.Encoding.utf8.rawValue)
do {
if let jsonArray = try JSONSerialization.jsonObject(with: json!, options: .allowFragments) as? [String:AnyObject]
{
extra_fields_parsed = jsonArray;
self.subcategory = extra_fields_parsed["subcategory"] as? String? ?? ""
} else {
self.subcategory = ""
print("bad json")
}
} catch let error as NSError {
self.subcategory = ""
print(error)
}
}
}
public class CampaignDataModel {
var data: Array<CampaignItemModel> = []
init() { //initializer method
let instanceOfMyApi = MyApi()
let products = instanceOfMyApi.getInbox() as NSMutableArray?
var giftsArray:Array<CampaignItemModel> = []
for gift in products ?? [] {
let tempGift = CampaignItemModel(dictionary: gift as! [String : Any])
giftsArray.append(tempGift)
}
self.data = giftsArray;
}
var getData: Array<CampaignItemModel> {
get { // getter
return data
}
}
}
public func getCampaigns() -> Array<CampaignItemModel> {
return CampaignDataModel().getData
}
}
......