Merge branch 'master' of https://git.warp.ly/open-source/warply_sdk_framework
Showing
2 changed files
with
68 additions
and
0 deletions
No preview for this file type
... | @@ -200,4 +200,72 @@ public class swiftApi { | ... | @@ -200,4 +200,72 @@ public class swiftApi { |
200 | return CouponsDataModel().getData | 200 | return CouponsDataModel().getData |
201 | } | 201 | } |
202 | 202 | ||
203 | + public class CampaignItemModel { | ||
204 | + let index_url: String? | ||
205 | + let logo_url: String? | ||
206 | + let offer_category: String? | ||
207 | + let title: String? | ||
208 | + let subtitle: String? | ||
209 | + let session_uuid: String? | ||
210 | + let subcategory: String? | ||
211 | + | ||
212 | + init(dictionary: [String: Any]) { | ||
213 | + self.index_url = dictionary["index_url"] as? String? ?? "" | ||
214 | + self.logo_url = dictionary["logo_url"] as? String? ?? "" | ||
215 | + self.offer_category = dictionary["offer_category"] as? String? ?? "" | ||
216 | + self.title = dictionary["title"] as? String? ?? "" | ||
217 | + self.subtitle = dictionary["subtitle"] as? String? ?? "" | ||
218 | + self.session_uuid = dictionary["session_uuid"] as? String? ?? "" | ||
219 | + | ||
220 | + // let extra_fields = dictionary["extra_fields"] as? [String: Any]? ?? ["":""] | ||
221 | + let extra_fields = dictionary["extra_fields"] as AnyObject | ||
222 | + var extra_fields_parsed:[String: Any] | ||
223 | + | ||
224 | + let json = extra_fields.data(using: String.Encoding.utf8.rawValue) | ||
225 | + do { | ||
226 | + if let jsonArray = try JSONSerialization.jsonObject(with: json!, options: .allowFragments) as? [String:AnyObject] | ||
227 | + { | ||
228 | + extra_fields_parsed = jsonArray; | ||
229 | + self.subcategory = extra_fields_parsed["subcategory"] as? String? ?? "" | ||
230 | + } else { | ||
231 | + self.subcategory = "" | ||
232 | + print("bad json") | ||
233 | + } | ||
234 | + } catch let error as NSError { | ||
235 | + self.subcategory = "" | ||
236 | + print(error) | ||
237 | + } | ||
238 | + | ||
239 | + } | ||
240 | + } | ||
241 | + | ||
242 | + public class CampaignDataModel { | ||
243 | + var data: Array<CampaignItemModel> = [] | ||
244 | + | ||
245 | + init() { //initializer method | ||
246 | + let instanceOfMyApi = MyApi() | ||
247 | + let products = instanceOfMyApi.getInbox() as NSMutableArray? | ||
248 | + | ||
249 | + var giftsArray:Array<CampaignItemModel> = [] | ||
250 | + | ||
251 | + | ||
252 | + for gift in products ?? [] { | ||
253 | + let tempGift = CampaignItemModel(dictionary: gift as! [String : Any]) | ||
254 | + giftsArray.append(tempGift) | ||
255 | + } | ||
256 | + | ||
257 | + self.data = giftsArray; | ||
258 | + | ||
259 | + } | ||
260 | + | ||
261 | + var getData: Array<CampaignItemModel> { | ||
262 | + get { // getter | ||
263 | + return data | ||
264 | + } | ||
265 | + } | ||
266 | + } | ||
267 | + | ||
268 | + public func getCampaigns() -> Array<CampaignItemModel> { | ||
269 | + return CampaignDataModel().getData | ||
270 | + } | ||
203 | } | 271 | } | ... | ... |
-
Please register or login to post a comment