swiftApi.swift
9.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
//
// swiftApi.swift
// WarplySDKFrameworkIOS
//
// Created by Βασιλης Σκουρας on 21/4/22.
//
import Foundation
public class swiftApi {
public init() {
}
public func getUserTag() -> String {
return "1"
}
public func setDFY(couponCode: String, merchantId: String) {
}
public func setActiveDFYCoupons(campaignIds: Array<String>) {
}
public func setCCMSLoyaltyCampaigns(campaigns: Array<LoyaltyContextualOfferModel>) {
}
public class LoyaltyContextualOfferModel {
var sessionId: String
var eligibleAssets: Array<String>
var id: String
init(sessionId: String, eligibleAssets: Array<String>, id: String) {
self.sessionId = sessionId
self.eligibleAssets = eligibleAssets
self.id = id
}
}
public class CouponSetItemModel {
let uuid: String?
let admin_name: String?
let name: String?
let img_preview: String?
let expiration: String?
let description: String?
let short_description: String?
let discount: String?
let sorting: Int?
let inner_text: String?
let buyable: Bool?
let visible: Bool?
init(dictionary: [String: Any]) {
self.uuid = dictionary["uuid"] as? String? ?? ""
self.admin_name = dictionary["admin_name"] as? String? ?? ""
self.name = dictionary["name"] as? String? ?? ""
self.img_preview = dictionary["img_preview"] as? String? ?? ""
self.description = dictionary["description"] as? String? ?? ""
self.short_description = dictionary["short_description"] as? String? ?? ""
self.discount = dictionary["discount"] as? String? ?? ""
self.sorting = dictionary["sorting"] as? Int? ?? nil
self.inner_text = dictionary["inner_text"] as? String? ?? ""
self.buyable = dictionary["buyable"] as? Bool? ?? false
self.visible = dictionary["visible"] as? Bool? ?? false
let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""]
let expirationString = expirationObject?["value"] as? String? ?? ""
// Example expirationString: Optional(2022-12-05 01:55)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm"
if let date = dateFormatter.date(from: expirationString ?? "") {
dateFormatter.dateFormat = "dd/MM/yyyy"
let resultString = dateFormatter.string(from: date)
self.expiration = resultString
} else {
self.expiration = ""
}
}
// var asDictionary : [String:Any] {
// let mirror = Mirror(reflecting: self)
// let dict = Dictionary(uniqueKeysWithValues: mirror.children.lazy.map({ (label:String?, value:Any) -> (String, Any)? in
// guard let label = label else { return nil }
// return (label, value)
// }).compactMap { $0 })
// return dict
// }
}
public class CouponSetsDataModel {
var data: Array<CouponSetItemModel> = []
init() { //initializer method
let instanceOfMyApi = MyApi()
let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil)
var couponSetsArray:Array<CouponSetItemModel> = []
if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] {
let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! NSArray)
for couponset in couponSetsData {
let tempCouponset = CouponSetItemModel(dictionary: couponset as! [String : Any])
couponSetsArray.append(tempCouponset)
}
}
self.data = couponSetsArray
}
var getData: Array<CouponSetItemModel> {
get { // getter
return data
}
}
}
public func getCouponSets() -> Array<CouponSetItemModel> {
return CouponSetsDataModel().getData
}
public class CouponItemModel {
let couponset_uuid: String?
let name: String?
let image: String?
let expiration: String?
let description: String?
let discount: String?
let coupon: String?
let category: String?
let barcode: String?
let status: Int?
init(dictionary: [String: Any]) {
self.couponset_uuid = dictionary["couponset_uuid"] as? String? ?? ""
self.name = dictionary["name"] as? String? ?? ""
self.image = dictionary["image"] as? String? ?? ""
self.description = dictionary["description"] as? String? ?? ""
self.discount = dictionary["discount"] as? String? ?? ""
self.coupon = dictionary["coupon"] as? String? ?? ""
self.category = dictionary["category"] as? String? ?? ""
self.barcode = dictionary["barcode"] as? String? ?? ""
self.status = dictionary["status"] as? Int? ?? nil
let expirationObject = dictionary["expiration"] as? [String: Any]? ?? ["":""]
let expirationString = expirationObject?["value"] as? String? ?? ""
// Example expirationString: Optional(2022-12-05 01:55)
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd hh:mm"
if let date = dateFormatter.date(from: expirationString ?? "") {
dateFormatter.dateFormat = "dd/MM/yyyy"
let resultString = dateFormatter.string(from: date)
self.expiration = resultString
} else {
self.expiration = ""
}
}
// var asDictionary : [String:Any] {
// let mirror = Mirror(reflecting: self)
// let dict = Dictionary(uniqueKeysWithValues: mirror.children.lazy.map({ (label:String?, value:Any) -> (String, Any)? in
// guard let label = label else { return nil }
// return (label, value)
// }).compactMap { $0 })
// return dict
// }
}
public class CouponsDataModel {
var data: Array<CouponItemModel> = []
init() { //initializer method
let instanceOfMyApi = MyApi()
let coupons = instanceOfMyApi.getCoupons()
var couponsArray:Array<CouponItemModel> = []
if let myCouponsDictionary = coupons as? [String : AnyObject] {
let couponsData = (myCouponsDictionary["result"] as! NSArray)
for coupon in couponsData {
let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any])
couponsArray.append(tempCoupon)
}
}
self.data = couponsArray
}
var getData: Array<CouponItemModel> {
get { // getter
return data
}
}
}
public func getCoupons() -> Array<CouponItemModel> {
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
}
}