Manos Chorianopoulos

add getCoupons async Request

......@@ -75,6 +75,8 @@
- (NSDictionary*)redeemCouponWithCoupon:(NSString*)coupon;
- (NSDictionary*)validateCouponWithCoupon:(NSString*)coupon;
- (NSDictionary*)loginCosmoteWithGuid:(NSString*)guid andAppUuid:(NSString*)appUuid andTicket:(NSString*)ticket;
- (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
@end
#endif /* MyApi_h */
......
......@@ -1257,4 +1257,31 @@ CMPedometer *pedometer;
}
return resp;
}
- (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
[[Warply sharedService] getCouponsWithSuccessBlock:^(NSDictionary *response) {
if (success) {
success(response);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
}
- (void) getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
[[Warply sharedService] getCouponSetsWithSuccessBlock:active andVisible:visible andUuids:uuids :^(NSDictionary *response) {
if (success) {
success(response);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
}
@end
......
......@@ -220,12 +220,62 @@ public class swiftApi {
var data: Array<CouponItemModel> = []
init() { //initializer method
}
var getData: Array<CouponItemModel> {
get { // getter
return data.filter({
return $0.status == 1
})
}
}
var getOldCoupons: Array<CouponItemModel> {
get { // getter
return data.filter({
return $0.status != 1
})
}
}
func getCouponsData(_ getCouponsCallback: @escaping (_ couponsData: Array<CouponItemModel>?) -> Void) -> Void {
var coupons: [AnyHashable : Any]?
var couponSets: [AnyHashable : Any]?
let instanceOfMyApi = MyApi()
let coupons = instanceOfMyApi.getCoupons()
let couponSets = instanceOfMyApi.getCouponSets(withActive: true, andVisible: true, andUuids: nil)
var couponsArray:Array<CouponItemModel> = []
instanceOfMyApi.getCouponsWithSuccessBlock(couponsCallback, failureBlock: (couponsFailureCallback))
func couponsCallback(_ couponsData: [AnyHashable : Any]?) -> Void {
coupons = couponsData ?? ["":""]
// On Coupons request success, make CouponSets request
instanceOfMyApi.getCouponsetsAsync(true, andVisible: true, andUuids: nil, couponSetsCallback, failureBlock: couponSetsFailureCallback)
}
func couponsFailureCallback(_ error: Error?) -> Void {
print("getCoupons error: ")
getCouponsCallback(nil)
}
func couponSetsCallback(_ couponSetsData: [AnyHashable : Any]?) -> Void {
couponSets = couponSetsData ?? ["":""]
// On CouponSets request Success, match coupons with couponsets
let tempCoupons = matchCoupons()
getCouponsCallback(tempCoupons)
}
func couponSetsFailureCallback(_ error: Error?) -> Void {
print("getCouponSets error: ")
getCouponsCallback(nil)
}
func matchCoupons() -> Array<CouponItemModel> {
var couponsArray:Array<CouponItemModel> = []
if let myCouponsSetsDictionary = couponSets as? [String : AnyObject] {
let couponSetsData = (myCouponsSetsDictionary["MAPP_COUPON"] as! Array<NSMutableDictionary>)
......@@ -255,36 +305,40 @@ public class swiftApi {
}
}
// 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
// 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)
// }
//
// }
return couponsArray
}
var getData: Array<CouponItemModel> {
get { // getter
return data.filter({
return $0.status == 1
})
}
}
var getOldCoupons: Array<CouponItemModel> {
get { // getter
return data.filter({
return $0.status != 1
public func filterActiveCoupons(_ coupons: Array<CouponItemModel>) -> Array<CouponItemModel> {
return coupons.filter({
return $0.status == 1
})
}
public func filterOldCoupons(_ coupons: Array<CouponItemModel>) -> Array<CouponItemModel> {
return coupons.filter({
return $0.status != 1
})
}
public func getCouponsAsync(_ getCouponsCallback: @escaping (_ couponsData: Array<CouponItemModel>?) -> Void) -> Void {
CouponsDataModel().getCouponsData(getCouponsCallback)
}
public func getCoupons() -> Array<CouponItemModel> {
......