Merge branch 'master' of https://git.warp.ly/open-source/warply_sdk_framework
Showing
4 changed files
with
129 additions
and
46 deletions
No preview for this file type
... | @@ -75,6 +75,8 @@ | ... | @@ -75,6 +75,8 @@ |
75 | - (NSDictionary*)redeemCouponWithCoupon:(NSString*)coupon; | 75 | - (NSDictionary*)redeemCouponWithCoupon:(NSString*)coupon; |
76 | - (NSDictionary*)validateCouponWithCoupon:(NSString*)coupon; | 76 | - (NSDictionary*)validateCouponWithCoupon:(NSString*)coupon; |
77 | - (NSDictionary*)loginCosmoteWithGuid:(NSString*)guid andAppUuid:(NSString*)appUuid andTicket:(NSString*)ticket; | 77 | - (NSDictionary*)loginCosmoteWithGuid:(NSString*)guid andAppUuid:(NSString*)appUuid andTicket:(NSString*)ticket; |
78 | +- (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ||
79 | +- (void)getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ||
78 | 80 | ||
79 | @end | 81 | @end |
80 | #endif /* MyApi_h */ | 82 | #endif /* MyApi_h */ | ... | ... |
... | @@ -1257,4 +1257,31 @@ CMPedometer *pedometer; | ... | @@ -1257,4 +1257,31 @@ CMPedometer *pedometer; |
1257 | } | 1257 | } |
1258 | return resp; | 1258 | return resp; |
1259 | } | 1259 | } |
1260 | + | ||
1261 | +- (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | ||
1262 | +{ | ||
1263 | + | ||
1264 | + [[Warply sharedService] getCouponsWithSuccessBlock:^(NSDictionary *response) { | ||
1265 | + if (success) { | ||
1266 | + success(response); | ||
1267 | + } | ||
1268 | + } failureBlock:^(NSError *error) { | ||
1269 | + if (failure) { | ||
1270 | + failure(error); | ||
1271 | + } | ||
1272 | + }]; | ||
1273 | +} | ||
1274 | + | ||
1275 | +- (void) getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | ||
1276 | +{ | ||
1277 | + [[Warply sharedService] getCouponSetsWithSuccessBlock:active andVisible:visible andUuids:uuids :^(NSDictionary *response) { | ||
1278 | + if (success) { | ||
1279 | + success(response); | ||
1280 | + } | ||
1281 | + } failureBlock:^(NSError *error) { | ||
1282 | + if (failure) { | ||
1283 | + failure(error); | ||
1284 | + } | ||
1285 | + }]; | ||
1286 | +} | ||
1260 | @end | 1287 | @end | ... | ... |
... | @@ -220,54 +220,9 @@ public class swiftApi { | ... | @@ -220,54 +220,9 @@ public class swiftApi { |
220 | var data: Array<CouponItemModel> = [] | 220 | var data: Array<CouponItemModel> = [] |
221 | 221 | ||
222 | init() { //initializer method | 222 | init() { //initializer method |
223 | - let instanceOfMyApi = MyApi() | ||
224 | - let coupons = instanceOfMyApi.getCoupons() | ||
225 | - let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil) | ||
226 | - | ||
227 | - var couponsArray:Array<CouponItemModel> = [] | ||
228 | - | ||
229 | 223 | ||
230 | - if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] { | ||
231 | - let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! Array<NSMutableDictionary>) | ||
232 | - if let myCouponsDictionary = coupons as? [String : AnyObject] { | ||
233 | - let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>) | ||
234 | - if let sets = couponSetsData as? NSArray { | ||
235 | - for set in sets { | ||
236 | - let s = set as! NSDictionary | ||
237 | - if let cpns = couponsData as? NSArray { | ||
238 | - for coupon in cpns { | ||
239 | - var c = coupon as! NSDictionary | ||
240 | - // var temp = NSMutableDictionary(dictionary: s); | ||
241 | - if c["couponset_uuid"] as! String == s["uuid"] as! String { | ||
242 | - let temp = NSMutableDictionary(dictionary: c); | ||
243 | - | ||
244 | - temp.setValue(s as! [AnyHashable : Any],forKey: "couponset_data") | ||
245 | - | ||
246 | - let tempCoupon = CouponItemModel(dictionary: temp as! [String : Any]) | ||
247 | - couponsArray.append(tempCoupon) | ||
248 | - } | ||
249 | - | ||
250 | - } | ||
251 | - } | ||
252 | - | ||
253 | - } | ||
254 | - } | ||
255 | - } | ||
256 | - } | ||
257 | - | ||
258 | -// if let myCouponsDictionary = coupons as? [String : AnyObject] { | ||
259 | -// let couponsData = (myCouponsDictionary["result"] as! NSArray) | ||
260 | -// | ||
261 | -// | ||
262 | -// for coupon in couponsData { | ||
263 | -// let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any]) | ||
264 | -// couponsArray.append(tempCoupon) | ||
265 | -// } | ||
266 | -// | ||
267 | -// } | ||
268 | - self.data = couponsArray | ||
269 | } | 224 | } |
270 | - | 225 | + |
271 | var getData: Array<CouponItemModel> { | 226 | var getData: Array<CouponItemModel> { |
272 | get { // getter | 227 | get { // getter |
273 | return data.filter({ | 228 | return data.filter({ |
... | @@ -285,6 +240,105 @@ public class swiftApi { | ... | @@ -285,6 +240,105 @@ public class swiftApi { |
285 | } | 240 | } |
286 | } | 241 | } |
287 | 242 | ||
243 | + | ||
244 | + func getCouponsData(_ getCouponsCallback: @escaping (_ couponsData: Array<CouponItemModel>?) -> Void) -> Void { | ||
245 | + | ||
246 | + var coupons: [AnyHashable : Any]? | ||
247 | + var couponSets: [AnyHashable : Any]? | ||
248 | + let instanceOfMyApi = MyApi() | ||
249 | + | ||
250 | + instanceOfMyApi.getCouponsWithSuccessBlock(couponsCallback, failureBlock: (couponsFailureCallback)) | ||
251 | + | ||
252 | + func couponsCallback(_ couponsData: [AnyHashable : Any]?) -> Void { | ||
253 | + coupons = couponsData ?? ["":""] | ||
254 | + | ||
255 | + // On Coupons request success, make CouponSets request | ||
256 | + instanceOfMyApi.getCouponsetsAsync(true, andVisible: true, andUuids: nil, couponSetsCallback, failureBlock: couponSetsFailureCallback) | ||
257 | + } | ||
258 | + | ||
259 | + func couponsFailureCallback(_ error: Error?) -> Void { | ||
260 | + print("getCoupons error: ") | ||
261 | + getCouponsCallback(nil) | ||
262 | + } | ||
263 | + | ||
264 | + func couponSetsCallback(_ couponSetsData: [AnyHashable : Any]?) -> Void { | ||
265 | + couponSets = couponSetsData ?? ["":""] | ||
266 | + | ||
267 | + // On CouponSets request Success, match coupons with couponsets | ||
268 | + let tempCoupons = matchCoupons() | ||
269 | + getCouponsCallback(tempCoupons) | ||
270 | + } | ||
271 | + | ||
272 | + func couponSetsFailureCallback(_ error: Error?) -> Void { | ||
273 | + print("getCouponSets error: ") | ||
274 | + getCouponsCallback(nil) | ||
275 | + } | ||
276 | + | ||
277 | + func matchCoupons() -> Array<CouponItemModel> { | ||
278 | + var couponsArray:Array<CouponItemModel> = [] | ||
279 | + | ||
280 | + if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] { | ||
281 | + let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! Array<NSMutableDictionary>) | ||
282 | + if let myCouponsDictionary = coupons as? [String : AnyObject] { | ||
283 | + let couponsData = (myCouponsDictionary["result"] as! Array<NSMutableDictionary>) | ||
284 | + if let sets = couponSetsData as? NSArray { | ||
285 | + for set in sets { | ||
286 | + let s = set as! NSDictionary | ||
287 | + if let cpns = couponsData as? NSArray { | ||
288 | + for coupon in cpns { | ||
289 | + var c = coupon as! NSDictionary | ||
290 | + // var temp = NSMutableDictionary(dictionary: s); | ||
291 | + if c["couponset_uuid"] as! String == s["uuid"] as! String { | ||
292 | + let temp = NSMutableDictionary(dictionary: c); | ||
293 | + | ||
294 | + temp.setValue(s as! [AnyHashable : Any],forKey: "couponset_data") | ||
295 | + | ||
296 | + let tempCoupon = CouponItemModel(dictionary: temp as! [String : Any]) | ||
297 | + couponsArray.append(tempCoupon) | ||
298 | + } | ||
299 | + | ||
300 | + } | ||
301 | + } | ||
302 | + | ||
303 | + } | ||
304 | + } | ||
305 | + } | ||
306 | + } | ||
307 | + | ||
308 | + // if let myCouponsDictionary = coupons as? [String : AnyObject] { | ||
309 | + // let couponsData = (myCouponsDictionary["result"] as! NSArray) | ||
310 | + // | ||
311 | + // | ||
312 | + // for coupon in couponsData { | ||
313 | + // let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any]) | ||
314 | + // couponsArray.append(tempCoupon) | ||
315 | + // } | ||
316 | + // | ||
317 | + // } | ||
318 | + | ||
319 | + return couponsArray | ||
320 | + | ||
321 | + } | ||
322 | + | ||
323 | + } | ||
324 | + | ||
325 | + } | ||
326 | + | ||
327 | + | ||
328 | + public func filterActiveCoupons(_ coupons: Array<CouponItemModel>) -> Array<CouponItemModel> { | ||
329 | + return coupons.filter({ | ||
330 | + return $0.status == 1 | ||
331 | + }) | ||
332 | + } | ||
333 | + | ||
334 | + public func filterOldCoupons(_ coupons: Array<CouponItemModel>) -> Array<CouponItemModel> { | ||
335 | + return coupons.filter({ | ||
336 | + return $0.status != 1 | ||
337 | + }) | ||
338 | + } | ||
339 | + | ||
340 | + public func getCouponsAsync(_ getCouponsCallback: @escaping (_ couponsData: Array<CouponItemModel>?) -> Void) -> Void { | ||
341 | + CouponsDataModel().getCouponsData(getCouponsCallback) | ||
288 | } | 342 | } |
289 | 343 | ||
290 | public func getCoupons() -> Array<CouponItemModel> { | 344 | public func getCoupons() -> Array<CouponItemModel> { | ... | ... |
-
Please register or login to post a comment