Manos Chorianopoulos

add getCampaignsAsyncNew request

......@@ -90,6 +90,8 @@
- (void)cosmoteCouponSharingAsync:(NSString*) coupon :(NSString*)sender :(NSString*)receiver :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (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;
- (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;
- (void)getCampaignsAsyncNew:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure;
- (void)getCampaignsPersonalizedAsync:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure;
@end
#endif /* MyApi_h */
......
......@@ -1468,4 +1468,30 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
}];
}
- (void)getCampaignsAsyncNew:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure
{
[[Warply sharedService] getCampaignsWithSuccessBlock:language :filters :^(NSDictionary *response) {
if (success) {
success(response);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
}
- (void)getCampaignsPersonalizedAsync:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure
{
[[Warply sharedService] getCampaignsPersonalizedWithSuccessBlock:language :filters :^(NSDictionary *response) {
if (success) {
success(response);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
}
@end
......
......@@ -299,6 +299,10 @@ WL_VERSION_INTERFACE()
- (BOOL)getInbox2WithSuccessBlock:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure;
- (BOOL)getCampaignsWithSuccessBlock:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure;
- (void)getCampaignsPersonalizedWithSuccessBlock:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure;
- (void)getProductsWithSuccessBlock:(NSString*)filter :(void(^)(NSMutableArray *params))success failureBlock:(void(^)(NSError *error))failure;
- (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)
return [self isRegistrationValid];
}
- (BOOL)getCampaignsWithSuccessBlock:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure
{
// if (self.allOffers.count > 0) {
// success(self.allOffers);
// } else {
NSDictionary *postDictionary = @{@"campaigns": @{@"action": @"retrieve", @"language": language, @"filters": filters}};
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL];
[self sendContext:jsonData successBlock:^(NSDictionary *contextResponse) {
if (success) {
success(contextResponse);
}
NSLog(@"**************** WARPLY Response *****************" );
NSLog(@"%@", contextResponse );
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
NSLog(@"Error at get Campaigns %@", error );
}];
// }
return [self isRegistrationValid];
}
- (void)getCampaignsPersonalizedWithSuccessBlock:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure
{
NSDictionary *postDictionary = @{@"campaigns": @{@"action": @"retrieve", @"language": language, @"filters": filters}};
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL];
[self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
if (success) {
success(contextResponse);
}
NSLog(@"**************** WARPLY Response *****************" );
NSLog(@"%@", contextResponse );
} failureBlock:^(NSError *error) {
if (failure) {
NSDictionary* dict = [NSDictionary alloc];
dict = [error userInfo];
NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"];
if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) {
[self refreshToken:^(NSDictionary *response) {
[self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) {
if (success) {
success(contextResponse);
}
NSLog(@"**************** WARPLY Response *****************" );
NSLog(@"%@", contextResponse );
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
} failureBlock:^(NSError *error) {
if (failure) {
[_db executeUpdate:@"DROP TABLE requestVariables"];
failure(error);
}
NSLog(@"Error at token %@", error );
}];
}
NSLog(@"Error at get Campaigns Personalized %@", error );
}
}];
}
- (NSString*)getAccessToken {
[self createDBIfNeeded];
[self initDBIfNeeded];
......
......@@ -764,6 +764,111 @@ public class swiftApi {
}
public func getCampaignsAsyncNew(language: String, filters: [String: Any], _ getCampaignsCallback: @escaping (_ campaignsData: Array<CampaignItemModel>?) -> Void) -> Void {
let instanceOfMyApi = MyApi()
instanceOfMyApi.getCampaignsAsyncNew(language, filters, campaignsCallback, failureBlock: campaignsFailureCallback)
func campaignsCallback(_ campaignsData: [AnyHashable: Any]?) -> Void {
var campaignsArray:Array<CampaignItemModel> = []
if let responseDataDictionary = campaignsData as? [String: AnyObject] {
if (responseDataDictionary["MAPP_CAMPAIGNING-status"] as? Int == 1) {
if let responseDataMapp = responseDataDictionary["MAPP_CAMPAIGNING"] as? [String: Any] {
if let responseDataCampaigns = responseDataMapp["campaigns"] as? [[String : Any]?] {
for item in responseDataCampaigns {
if let itemDictionary = item {
let tempCampaign = CampaignItemModel(dictionary: itemDictionary)
campaignsArray.append(tempCampaign)
}
}
}
} else {
getCampaignsCallback(nil)
}
swiftApi().getCampaignsPersonalizedAsync(language: language, filters: filters, {campaignsPersonalizedData in
campaignsArray = campaignsArray + (campaignsPersonalizedData ?? [])
swiftApi().setUniqueCampaignList(campaignsArray)
let filteredCampaigns = campaignsArray.filter {
let tempCampaign = $0
let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true")
let isTelco = (tempCampaign._type != nil && tempCampaign._type == "telco")
return (!(isCcmsOffer || isTelco))
}
getCampaignsCallback(filteredCampaigns);
})
} else {
getCampaignsCallback(nil)
}
} else {
getCampaignsCallback(nil)
}
}
func campaignsFailureCallback(_ error: Error?) -> Void {
print("getCampaigns error: ")
print(error)
print("====================")
getCampaignsCallback(nil)
}
}
public func getCampaignsPersonalizedAsync(language: String, filters: [String: Any], _ getCampaignsCallback: @escaping (_ campaignsData: Array<CampaignItemModel>?) -> Void) -> Void {
let instanceOfMyApi = MyApi()
instanceOfMyApi.getCampaignsPersonalizedAsync(language, filters, campaignsCallback, failureBlock: campaignsFailureCallback)
func campaignsCallback(_ campaignsData: [AnyHashable: Any]?) -> Void {
var campaignsArray:Array<CampaignItemModel> = []
if let responseDataDictionary = campaignsData as? [String: AnyObject] {
if (responseDataDictionary["MAPP_CAMPAIGNING-status"] as? Int == 1) {
if let responseDataMapp = responseDataDictionary["MAPP_CAMPAIGNING"] as? [String: Any] {
if let responseDataCampaigns = responseDataMapp["campaigns"] as? [[String : Any]?] {
for item in responseDataCampaigns {
if let itemDictionary = item {
let tempCampaign = CampaignItemModel(dictionary: itemDictionary)
campaignsArray.append(tempCampaign)
}
}
getCampaignsCallback(campaignsArray);
}
} else {
getCampaignsCallback(nil)
}
} else {
getCampaignsCallback(nil)
}
} else {
getCampaignsCallback(nil)
}
}
func campaignsFailureCallback(_ error: Error?) -> Void {
print("getCampaignsPersonalized error: ")
print(error)
print("====================")
getCampaignsCallback(nil)
}
}
public class LoyaltyContextualOfferModel: Codable {
private var sessionId: String
private var eligibleAssets: Array<String>
......