Showing
5 changed files
with
204 additions
and
0 deletions
... | @@ -90,6 +90,8 @@ | ... | @@ -90,6 +90,8 @@ |
90 | - (void)cosmoteCouponSharingAsync:(NSString*) coupon :(NSString*)sender :(NSString*)receiver :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 90 | - (void)cosmoteCouponSharingAsync:(NSString*) coupon :(NSString*)sender :(NSString*)receiver :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
91 | - (void)submitOrderAsync:(NSString*) campaign_session_uuid :(NSString*)user_msisdn :(NSString*)businessService :(NSString*)offerName :(NSString*)productType :(NSString*)provDuration :(NSString*)noOfRecurrance :(NSString*)price :(NSString*)discount :(NSString*)voiceCategory :(NSString*)dataCategory :(NSString*)minsValue :(NSString*)dataValue :(NSString*)provStepValueMins :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 91 | - (void)submitOrderAsync:(NSString*) campaign_session_uuid :(NSString*)user_msisdn :(NSString*)businessService :(NSString*)offerName :(NSString*)productType :(NSString*)provDuration :(NSString*)noOfRecurrance :(NSString*)price :(NSString*)discount :(NSString*)voiceCategory :(NSString*)dataCategory :(NSString*)minsValue :(NSString*)dataValue :(NSString*)provStepValueMins :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
92 | - (void)postEventAsync:(NSString*)Session_ID :(NSString*)OfferAudienceLevel :(NSString*)msisdn :(NSString*)UACIOfferTrackingCode :(NSString*)OFFERCODE1 :(NSString*)SCORE :(NSString*)ZONE :(NSString*)WAVE :(NSString*)VALIDITY :(NSString*)TREATMENT_CODE :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 92 | - (void)postEventAsync:(NSString*)Session_ID :(NSString*)OfferAudienceLevel :(NSString*)msisdn :(NSString*)UACIOfferTrackingCode :(NSString*)OFFERCODE1 :(NSString*)SCORE :(NSString*)ZONE :(NSString*)WAVE :(NSString*)VALIDITY :(NSString*)TREATMENT_CODE :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
93 | +- (void)getCampaignsAsyncNew:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure; | ||
94 | +- (void)getCampaignsPersonalizedAsync:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure; | ||
93 | 95 | ||
94 | @end | 96 | @end |
95 | #endif /* MyApi_h */ | 97 | #endif /* MyApi_h */ | ... | ... |
... | @@ -1468,4 +1468,30 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; | ... | @@ -1468,4 +1468,30 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; |
1468 | }]; | 1468 | }]; |
1469 | } | 1469 | } |
1470 | 1470 | ||
1471 | +- (void)getCampaignsAsyncNew:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure | ||
1472 | +{ | ||
1473 | + [[Warply sharedService] getCampaignsWithSuccessBlock:language :filters :^(NSDictionary *response) { | ||
1474 | + if (success) { | ||
1475 | + success(response); | ||
1476 | + } | ||
1477 | + } failureBlock:^(NSError *error) { | ||
1478 | + if (failure) { | ||
1479 | + failure(error); | ||
1480 | + } | ||
1481 | + }]; | ||
1482 | +} | ||
1483 | + | ||
1484 | +- (void)getCampaignsPersonalizedAsync:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure | ||
1485 | +{ | ||
1486 | + [[Warply sharedService] getCampaignsPersonalizedWithSuccessBlock:language :filters :^(NSDictionary *response) { | ||
1487 | + if (success) { | ||
1488 | + success(response); | ||
1489 | + } | ||
1490 | + } failureBlock:^(NSError *error) { | ||
1491 | + if (failure) { | ||
1492 | + failure(error); | ||
1493 | + } | ||
1494 | + }]; | ||
1495 | +} | ||
1496 | + | ||
1471 | @end | 1497 | @end | ... | ... |
... | @@ -299,6 +299,10 @@ WL_VERSION_INTERFACE() | ... | @@ -299,6 +299,10 @@ WL_VERSION_INTERFACE() |
299 | 299 | ||
300 | - (BOOL)getInbox2WithSuccessBlock:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure; | 300 | - (BOOL)getInbox2WithSuccessBlock:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure; |
301 | 301 | ||
302 | +- (BOOL)getCampaignsWithSuccessBlock:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure; | ||
303 | + | ||
304 | +- (void)getCampaignsPersonalizedWithSuccessBlock:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure; | ||
305 | + | ||
302 | - (void)getProductsWithSuccessBlock:(NSString*)filter :(void(^)(NSMutableArray *params))success failureBlock:(void(^)(NSError *error))failure; | 306 | - (void)getProductsWithSuccessBlock:(NSString*)filter :(void(^)(NSMutableArray *params))success failureBlock:(void(^)(NSError *error))failure; |
303 | 307 | ||
304 | - (void)sendContactWithSuccessBlock:(NSString *)name andEmail:(NSString *)email andMsisdn:msisdn andMessage:message :(void(^)(NSMutableArray *params)) success failureBlock:(void(^)(NSError *error))failure; | 308 | - (void)sendContactWithSuccessBlock:(NSString *)name andEmail:(NSString *)email andMsisdn:msisdn andMessage:message :(void(^)(NSMutableArray *params)) success failureBlock:(void(^)(NSError *error))failure; | ... | ... |
... | @@ -517,6 +517,73 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -517,6 +517,73 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
517 | return [self isRegistrationValid]; | 517 | return [self isRegistrationValid]; |
518 | } | 518 | } |
519 | 519 | ||
520 | +- (BOOL)getCampaignsWithSuccessBlock:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure | ||
521 | +{ | ||
522 | + // if (self.allOffers.count > 0) { | ||
523 | + // success(self.allOffers); | ||
524 | + // } else { | ||
525 | + NSDictionary *postDictionary = @{@"campaigns": @{@"action": @"retrieve", @"language": language, @"filters": filters}}; | ||
526 | + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL]; | ||
527 | + | ||
528 | + [self sendContext:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
529 | + if (success) { | ||
530 | + success(contextResponse); | ||
531 | + } | ||
532 | + NSLog(@"**************** WARPLY Response *****************" ); | ||
533 | + NSLog(@"%@", contextResponse ); | ||
534 | + } failureBlock:^(NSError *error) { | ||
535 | + if (failure) { | ||
536 | + failure(error); | ||
537 | + } | ||
538 | + NSLog(@"Error at get Campaigns %@", error ); | ||
539 | + }]; | ||
540 | + // } | ||
541 | + | ||
542 | + | ||
543 | + return [self isRegistrationValid]; | ||
544 | +} | ||
545 | + | ||
546 | +- (void)getCampaignsPersonalizedWithSuccessBlock:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure | ||
547 | +{ | ||
548 | + NSDictionary *postDictionary = @{@"campaigns": @{@"action": @"retrieve", @"language": language, @"filters": filters}}; | ||
549 | + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL]; | ||
550 | + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
551 | + if (success) { | ||
552 | + success(contextResponse); | ||
553 | + } | ||
554 | + NSLog(@"**************** WARPLY Response *****************" ); | ||
555 | + NSLog(@"%@", contextResponse ); | ||
556 | + } failureBlock:^(NSError *error) { | ||
557 | + if (failure) { | ||
558 | + NSDictionary* dict = [NSDictionary alloc]; | ||
559 | + dict = [error userInfo]; | ||
560 | + NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"]; | ||
561 | + if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) { | ||
562 | + [self refreshToken:^(NSDictionary *response) { | ||
563 | + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
564 | + if (success) { | ||
565 | + success(contextResponse); | ||
566 | + } | ||
567 | + NSLog(@"**************** WARPLY Response *****************" ); | ||
568 | + NSLog(@"%@", contextResponse ); | ||
569 | + } failureBlock:^(NSError *error) { | ||
570 | + if (failure) { | ||
571 | + failure(error); | ||
572 | + } | ||
573 | + }]; | ||
574 | + } failureBlock:^(NSError *error) { | ||
575 | + if (failure) { | ||
576 | + [_db executeUpdate:@"DROP TABLE requestVariables"]; | ||
577 | + failure(error); | ||
578 | + } | ||
579 | + NSLog(@"Error at token %@", error ); | ||
580 | + }]; | ||
581 | + } | ||
582 | + NSLog(@"Error at get Campaigns Personalized %@", error ); | ||
583 | + } | ||
584 | + }]; | ||
585 | +} | ||
586 | + | ||
520 | - (NSString*)getAccessToken { | 587 | - (NSString*)getAccessToken { |
521 | [self createDBIfNeeded]; | 588 | [self createDBIfNeeded]; |
522 | [self initDBIfNeeded]; | 589 | [self initDBIfNeeded]; | ... | ... |
... | @@ -764,6 +764,111 @@ public class swiftApi { | ... | @@ -764,6 +764,111 @@ public class swiftApi { |
764 | } | 764 | } |
765 | 765 | ||
766 | 766 | ||
767 | + public func getCampaignsAsyncNew(language: String, filters: [String: Any], _ getCampaignsCallback: @escaping (_ campaignsData: Array<CampaignItemModel>?) -> Void) -> Void { | ||
768 | + let instanceOfMyApi = MyApi() | ||
769 | + instanceOfMyApi.getCampaignsAsyncNew(language, filters, campaignsCallback, failureBlock: campaignsFailureCallback) | ||
770 | + | ||
771 | + | ||
772 | + func campaignsCallback(_ campaignsData: [AnyHashable: Any]?) -> Void { | ||
773 | + var campaignsArray:Array<CampaignItemModel> = [] | ||
774 | + | ||
775 | + if let responseDataDictionary = campaignsData as? [String: AnyObject] { | ||
776 | + | ||
777 | + if (responseDataDictionary["MAPP_CAMPAIGNING-status"] as? Int == 1) { | ||
778 | + if let responseDataMapp = responseDataDictionary["MAPP_CAMPAIGNING"] as? [String: Any] { | ||
779 | + if let responseDataCampaigns = responseDataMapp["campaigns"] as? [[String : Any]?] { | ||
780 | + | ||
781 | + for item in responseDataCampaigns { | ||
782 | + if let itemDictionary = item { | ||
783 | + let tempCampaign = CampaignItemModel(dictionary: itemDictionary) | ||
784 | + campaignsArray.append(tempCampaign) | ||
785 | + } | ||
786 | + } | ||
787 | + } | ||
788 | + } else { | ||
789 | + getCampaignsCallback(nil) | ||
790 | + } | ||
791 | + | ||
792 | + swiftApi().getCampaignsPersonalizedAsync(language: language, filters: filters, {campaignsPersonalizedData in | ||
793 | + | ||
794 | + campaignsArray = campaignsArray + (campaignsPersonalizedData ?? []) | ||
795 | + | ||
796 | + swiftApi().setUniqueCampaignList(campaignsArray) | ||
797 | + | ||
798 | + let filteredCampaigns = campaignsArray.filter { | ||
799 | + let tempCampaign = $0 | ||
800 | + let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true") | ||
801 | + let isTelco = (tempCampaign._type != nil && tempCampaign._type == "telco") | ||
802 | + | ||
803 | + return (!(isCcmsOffer || isTelco)) | ||
804 | + } | ||
805 | + getCampaignsCallback(filteredCampaigns); | ||
806 | + }) | ||
807 | + | ||
808 | + } else { | ||
809 | + getCampaignsCallback(nil) | ||
810 | + } | ||
811 | + | ||
812 | + } else { | ||
813 | + getCampaignsCallback(nil) | ||
814 | + } | ||
815 | + } | ||
816 | + | ||
817 | + func campaignsFailureCallback(_ error: Error?) -> Void { | ||
818 | + print("getCampaigns error: ") | ||
819 | + print(error) | ||
820 | + print("====================") | ||
821 | + getCampaignsCallback(nil) | ||
822 | + } | ||
823 | + } | ||
824 | + | ||
825 | + | ||
826 | + public func getCampaignsPersonalizedAsync(language: String, filters: [String: Any], _ getCampaignsCallback: @escaping (_ campaignsData: Array<CampaignItemModel>?) -> Void) -> Void { | ||
827 | + let instanceOfMyApi = MyApi() | ||
828 | + instanceOfMyApi.getCampaignsPersonalizedAsync(language, filters, campaignsCallback, failureBlock: campaignsFailureCallback) | ||
829 | + | ||
830 | + | ||
831 | + func campaignsCallback(_ campaignsData: [AnyHashable: Any]?) -> Void { | ||
832 | + var campaignsArray:Array<CampaignItemModel> = [] | ||
833 | + | ||
834 | + if let responseDataDictionary = campaignsData as? [String: AnyObject] { | ||
835 | + | ||
836 | + if (responseDataDictionary["MAPP_CAMPAIGNING-status"] as? Int == 1) { | ||
837 | + | ||
838 | + if let responseDataMapp = responseDataDictionary["MAPP_CAMPAIGNING"] as? [String: Any] { | ||
839 | + if let responseDataCampaigns = responseDataMapp["campaigns"] as? [[String : Any]?] { | ||
840 | + | ||
841 | + for item in responseDataCampaigns { | ||
842 | + if let itemDictionary = item { | ||
843 | + let tempCampaign = CampaignItemModel(dictionary: itemDictionary) | ||
844 | + campaignsArray.append(tempCampaign) | ||
845 | + } | ||
846 | + } | ||
847 | + | ||
848 | + getCampaignsCallback(campaignsArray); | ||
849 | + } | ||
850 | + } else { | ||
851 | + getCampaignsCallback(nil) | ||
852 | + } | ||
853 | + | ||
854 | + } else { | ||
855 | + getCampaignsCallback(nil) | ||
856 | + } | ||
857 | + | ||
858 | + } else { | ||
859 | + getCampaignsCallback(nil) | ||
860 | + } | ||
861 | + } | ||
862 | + | ||
863 | + func campaignsFailureCallback(_ error: Error?) -> Void { | ||
864 | + print("getCampaignsPersonalized error: ") | ||
865 | + print(error) | ||
866 | + print("====================") | ||
867 | + getCampaignsCallback(nil) | ||
868 | + } | ||
869 | + } | ||
870 | + | ||
871 | + | ||
767 | public class LoyaltyContextualOfferModel: Codable { | 872 | public class LoyaltyContextualOfferModel: Codable { |
768 | private var sessionId: String | 873 | private var sessionId: String |
769 | private var eligibleAssets: Array<String> | 874 | private var eligibleAssets: Array<String> | ... | ... |
-
Please register or login to post a comment