Merge branch 'master' of https://git.warp.ly/open-source/warply_sdk_framework
Showing
4 changed files
with
106 additions
and
23 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,12 +220,62 @@ public class swiftApi { | ... | @@ -220,12 +220,62 @@ public class swiftApi { |
220 | var data: Array<CouponItemModel> = [] | 220 | var data: Array<CouponItemModel> = [] |
221 | 221 | ||
222 | init() { //initializer method | 222 | init() { //initializer method |
223 | + | ||
224 | + } | ||
225 | + | ||
226 | + var getData: Array<CouponItemModel> { | ||
227 | + get { // getter | ||
228 | + return data.filter({ | ||
229 | + return $0.status == 1 | ||
230 | + }) | ||
231 | + } | ||
232 | + } | ||
233 | + | ||
234 | + | ||
235 | + var getOldCoupons: Array<CouponItemModel> { | ||
236 | + get { // getter | ||
237 | + return data.filter({ | ||
238 | + return $0.status != 1 | ||
239 | + }) | ||
240 | + } | ||
241 | + } | ||
242 | + | ||
243 | + | ||
244 | + func getCouponsData(_ getCouponsCallback: @escaping (_ couponsData: Array<CouponItemModel>?) -> Void) -> Void { | ||
245 | + | ||
246 | + var coupons: [AnyHashable : Any]? | ||
247 | + var couponSets: [AnyHashable : Any]? | ||
223 | let instanceOfMyApi = MyApi() | 248 | let instanceOfMyApi = MyApi() |
224 | - let coupons = instanceOfMyApi.getCoupons() | ||
225 | - let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil) | ||
226 | 249 | ||
227 | - var couponsArray:Array<CouponItemModel> = [] | 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 | + } | ||
228 | 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> = [] | ||
229 | 279 | ||
230 | if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] { | 280 | if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] { |
231 | let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! Array<NSMutableDictionary>) | 281 | let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! Array<NSMutableDictionary>) |
... | @@ -255,36 +305,40 @@ public class swiftApi { | ... | @@ -255,36 +305,40 @@ public class swiftApi { |
255 | } | 305 | } |
256 | } | 306 | } |
257 | 307 | ||
258 | -// if let myCouponsDictionary = coupons as? [String : AnyObject] { | 308 | + // if let myCouponsDictionary = coupons as? [String : AnyObject] { |
259 | -// let couponsData = (myCouponsDictionary["result"] as! NSArray) | 309 | + // let couponsData = (myCouponsDictionary["result"] as! NSArray) |
260 | -// | 310 | + // |
261 | -// | 311 | + // |
262 | -// for coupon in couponsData { | 312 | + // for coupon in couponsData { |
263 | -// let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any]) | 313 | + // let tempCoupon = CouponItemModel(dictionary: coupon as! [String : Any]) |
264 | -// couponsArray.append(tempCoupon) | 314 | + // couponsArray.append(tempCoupon) |
265 | -// } | 315 | + // } |
266 | -// | 316 | + // |
267 | -// } | 317 | + // } |
268 | - self.data = couponsArray | 318 | + |
319 | + return couponsArray | ||
320 | + | ||
269 | } | 321 | } |
270 | 322 | ||
271 | - var getData: Array<CouponItemModel> { | ||
272 | - get { // getter | ||
273 | - return data.filter({ | ||
274 | - return $0.status == 1 | ||
275 | - }) | ||
276 | } | 323 | } |
324 | + | ||
277 | } | 325 | } |
278 | 326 | ||
279 | 327 | ||
280 | - var getOldCoupons: Array<CouponItemModel> { | 328 | + public func filterActiveCoupons(_ coupons: Array<CouponItemModel>) -> Array<CouponItemModel> { |
281 | - get { // getter | 329 | + return coupons.filter({ |
282 | - return data.filter({ | 330 | + return $0.status == 1 |
283 | - return $0.status != 1 | ||
284 | }) | 331 | }) |
285 | } | 332 | } |
333 | + | ||
334 | + public func filterOldCoupons(_ coupons: Array<CouponItemModel>) -> Array<CouponItemModel> { | ||
335 | + return coupons.filter({ | ||
336 | + return $0.status != 1 | ||
337 | + }) | ||
286 | } | 338 | } |
287 | 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