Showing
5 changed files
with
254 additions
and
0 deletions
| ... | @@ -92,6 +92,7 @@ | ... | @@ -92,6 +92,7 @@ |
| 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; | 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; | 94 | - (void)getCampaignsPersonalizedAsync:(NSString*)language :(NSDictionary*)filters :(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure; |
| 95 | +- (void)getSharingHistoryAsync:(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure; | ||
| 95 | 96 | ||
| 96 | @end | 97 | @end |
| 97 | #endif /* MyApi_h */ | 98 | #endif /* MyApi_h */ | ... | ... |
| ... | @@ -1494,4 +1494,17 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; | ... | @@ -1494,4 +1494,17 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify"; |
| 1494 | }]; | 1494 | }]; |
| 1495 | } | 1495 | } |
| 1496 | 1496 | ||
| 1497 | +- (void)getSharingHistoryAsync:(void (^)(NSDictionary *response))success failureBlock:(void (^)(NSError *error))failure | ||
| 1498 | +{ | ||
| 1499 | + [[Warply sharedService] getSharingHistoryWithSuccessBlock:^(NSDictionary *response) { | ||
| 1500 | + if (success) { | ||
| 1501 | + success(response); | ||
| 1502 | + } | ||
| 1503 | + } failureBlock:^(NSError *error) { | ||
| 1504 | + if (failure) { | ||
| 1505 | + failure(error); | ||
| 1506 | + } | ||
| 1507 | + }]; | ||
| 1508 | +} | ||
| 1509 | + | ||
| 1497 | @end | 1510 | @end | ... | ... |
| ... | @@ -359,6 +359,8 @@ WL_VERSION_INTERFACE() | ... | @@ -359,6 +359,8 @@ WL_VERSION_INTERFACE() |
| 359 | 359 | ||
| 360 | - (void)getPointsHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 360 | - (void)getPointsHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
| 361 | 361 | ||
| 362 | +- (void)getSharingHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ||
| 363 | + | ||
| 362 | - (void)verifyTicketWithSuccessBlock:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 364 | - (void)verifyTicketWithSuccessBlock:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; |
| 363 | 365 | ||
| 364 | - (void)getCosmoteUserWithSuccessBlock:(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | 366 | - (void)getCosmoteUserWithSuccessBlock:(NSString*)guid :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; | ... | ... |
| ... | @@ -1646,6 +1646,47 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) | ... | @@ -1646,6 +1646,47 @@ WL_VERSION_IMPLEMENTATION(WL_VERSION) |
| 1646 | }]; | 1646 | }]; |
| 1647 | } | 1647 | } |
| 1648 | 1648 | ||
| 1649 | +- (void)getSharingHistoryWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | ||
| 1650 | +{ | ||
| 1651 | + NSDictionary *postDictionary = @{@"coupon": @{@"action": @"sharing_history"}}; | ||
| 1652 | + NSData *jsonData = [NSJSONSerialization dataWithJSONObject:postDictionary options:0 error:NULL]; | ||
| 1653 | + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
| 1654 | + if (success) { | ||
| 1655 | + success(contextResponse); | ||
| 1656 | + } | ||
| 1657 | + NSLog(@"**************** WARPLY Response *****************" ); | ||
| 1658 | + NSLog(@"%@", contextResponse ); | ||
| 1659 | + } failureBlock:^(NSError *error) { | ||
| 1660 | + if (failure) { | ||
| 1661 | + NSDictionary* dict = [NSDictionary alloc]; | ||
| 1662 | + dict = [error userInfo]; | ||
| 1663 | + NSString* errorCode = [dict objectForKey:@"NSLocalizedDescription"]; | ||
| 1664 | + if ([errorCode isEqual:@"Request failed: unauthorized (401)"]) { | ||
| 1665 | + [self refreshToken:^(NSDictionary *response) { | ||
| 1666 | + [self sendContext8:jsonData successBlock:^(NSDictionary *contextResponse) { | ||
| 1667 | + if (success) { | ||
| 1668 | + success(contextResponse); | ||
| 1669 | + } | ||
| 1670 | + NSLog(@"**************** WARPLY Response *****************" ); | ||
| 1671 | + NSLog(@"%@", contextResponse ); | ||
| 1672 | + } failureBlock:^(NSError *error) { | ||
| 1673 | + if (failure) { | ||
| 1674 | + failure(error); | ||
| 1675 | + } | ||
| 1676 | + }]; | ||
| 1677 | + } failureBlock:^(NSError *error) { | ||
| 1678 | + if (failure) { | ||
| 1679 | + [_db executeUpdate:@"DROP TABLE requestVariables"]; | ||
| 1680 | + failure(error); | ||
| 1681 | + } | ||
| 1682 | + NSLog(@"Error at token %@", error ); | ||
| 1683 | + }]; | ||
| 1684 | + } | ||
| 1685 | + NSLog(@"Error at get Sharing History %@", error ); | ||
| 1686 | + } | ||
| 1687 | + }]; | ||
| 1688 | +} | ||
| 1689 | + | ||
| 1649 | - (void)addAddressWithSuccessBlock:(NSString*)friendlyName :(NSString*)addressName :(NSString*)addressNumber :(NSString*)postalCode :(NSNumber*)floorNumber :(NSString*)doorbel :(NSString*)region :(NSString*)latitude :(NSString*)longitude :(NSString*)notes :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure | 1690 | - (void)addAddressWithSuccessBlock:(NSString*)friendlyName :(NSString*)addressName :(NSString*)addressNumber :(NSString*)postalCode :(NSNumber*)floorNumber :(NSString*)doorbel :(NSString*)region :(NSString*)latitude :(NSString*)longitude :(NSString*)notes :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure |
| 1650 | { | 1691 | { |
| 1651 | NSDictionary *postDictionary = @{@"consumer_data" : @{@"action": @"handle_addresses_new", @"process": @"add", @"data": @{@"friendly_name": friendlyName,@"address_name": addressName, @"address_number": addressNumber, @"postal_code": postalCode, @"floor_number": floorNumber, @"doorbel": doorbel, @"region": region, @"latitude": latitude, @"longitude": longitude, @"notes": notes}}}; | 1692 | NSDictionary *postDictionary = @{@"consumer_data" : @{@"action": @"handle_addresses_new", @"process": @"add", @"data": @{@"friendly_name": friendlyName,@"address_name": addressName, @"address_number": addressNumber, @"postal_code": postalCode, @"floor_number": floorNumber, @"doorbel": doorbel, @"region": region, @"latitude": latitude, @"longitude": longitude, @"notes": notes}}}; | ... | ... |
| ... | @@ -3460,4 +3460,201 @@ public class swiftApi { | ... | @@ -3460,4 +3460,201 @@ public class swiftApi { |
| 3460 | } | 3460 | } |
| 3461 | } | 3461 | } |
| 3462 | 3462 | ||
| 3463 | + | ||
| 3464 | + public class SharingCouponModel: Codable { | ||
| 3465 | + // public let transactionMetadata: String? | ||
| 3466 | + // public let sharingType: String? | ||
| 3467 | + // public let discount: Float | ||
| 3468 | + // public let date: Date? | ||
| 3469 | + // public let couponsetUuid: String? | ||
| 3470 | + // public let name: String? | ||
| 3471 | + | ||
| 3472 | + private var couponset_uuid: String? | ||
| 3473 | + private var date: String? | ||
| 3474 | + private var discount: String? | ||
| 3475 | + private var sharing_type: String? | ||
| 3476 | + // private var transaction_metadata: String? | ||
| 3477 | + private var name: String? | ||
| 3478 | + private var receiver_msisdn: String? | ||
| 3479 | + private var sender_msisdn: String? | ||
| 3480 | + | ||
| 3481 | + public init() { | ||
| 3482 | + self.couponset_uuid = "" | ||
| 3483 | + self.date = "" | ||
| 3484 | + self.discount = "" | ||
| 3485 | + self.sharing_type = "" | ||
| 3486 | + // self.transaction_metadata = "" | ||
| 3487 | + self.name = "" | ||
| 3488 | + self.receiver_msisdn = "" | ||
| 3489 | + self.sender_msisdn = "" | ||
| 3490 | + } | ||
| 3491 | + | ||
| 3492 | + public init(dictionary: [String: Any]) { | ||
| 3493 | + // self.transactionMetadata = dictionary["transaction_metadata"] as? String? ?? "" | ||
| 3494 | + // self.sharingType = dictionary["sharing_type"] as? String? ?? "" | ||
| 3495 | + // self.discount = dictionary["discount"] as? Float ?? 0.0 | ||
| 3496 | + // self.couponsetUuid = dictionary["couponsetUuid"] as? String? ?? "" | ||
| 3497 | + // self.name = dictionary["name"] as? String? ?? "" | ||
| 3498 | + | ||
| 3499 | + // let dateString = dictionary["date"] as? String? ?? "" | ||
| 3500 | + | ||
| 3501 | + // let dateFormatter = DateFormatter() | ||
| 3502 | + // dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss" | ||
| 3503 | + // if let date = dateFormatter.date(from: dateString ?? "") { | ||
| 3504 | + // self.date = date | ||
| 3505 | + // } else { | ||
| 3506 | + // self.date = nil | ||
| 3507 | + // } | ||
| 3508 | + | ||
| 3509 | + | ||
| 3510 | + self.couponset_uuid = dictionary["couponset_uuid"] as? String? ?? "" | ||
| 3511 | + self.discount = dictionary["discount"] as? String? ?? "" | ||
| 3512 | + self.sharing_type = dictionary["sharing_type"] as? String? ?? "" | ||
| 3513 | + // self.transaction_metadata = dictionary["transaction_metadata"] as? String? ?? "" | ||
| 3514 | + self.name = dictionary["name"] as? String? ?? "" | ||
| 3515 | + | ||
| 3516 | + | ||
| 3517 | + // Example "date": "Thu, Jun 23 2022 16:24:44", | ||
| 3518 | + let dateString = dictionary["date"] as? String? ?? "" | ||
| 3519 | + let dateFormatter = DateFormatter() | ||
| 3520 | + // dateFormatter.dateFormat = "yyyy-MM-dd hh:mm:ss" | ||
| 3521 | + dateFormatter.dateFormat = "E, MMM dd yyyy HH:mm:ss" | ||
| 3522 | + if let date = dateFormatter.date(from: dateString ?? "") { | ||
| 3523 | + dateFormatter.dateFormat = "dd/MM/yyyy" | ||
| 3524 | + let resultString = dateFormatter.string(from: date) | ||
| 3525 | + self.date = resultString | ||
| 3526 | + } else { | ||
| 3527 | + self.date = "" | ||
| 3528 | + } | ||
| 3529 | + | ||
| 3530 | + let transaction_metadata_json = dictionary["transaction_metadata"] as AnyObject | ||
| 3531 | + var transaction_metadata_parsed:[String: Any] | ||
| 3532 | + | ||
| 3533 | + let json = transaction_metadata_json.data(using: String.Encoding.utf8.rawValue) | ||
| 3534 | + do { | ||
| 3535 | + if let jsonArray = try JSONSerialization.jsonObject(with: json!, options: .allowFragments) as? [String:AnyObject] | ||
| 3536 | + { | ||
| 3537 | + transaction_metadata_parsed = jsonArray; | ||
| 3538 | + self.receiver_msisdn = transaction_metadata_parsed["receiver_msisdn"] as? String? ?? "" | ||
| 3539 | + self.sender_msisdn = transaction_metadata_parsed["sender_msisdn"] as? String? ?? "" | ||
| 3540 | + } else { | ||
| 3541 | + self.receiver_msisdn = "" | ||
| 3542 | + self.sender_msisdn = "" | ||
| 3543 | + print("bad json") | ||
| 3544 | + } | ||
| 3545 | + } catch let error as NSError { | ||
| 3546 | + self.receiver_msisdn = "" | ||
| 3547 | + self.sender_msisdn = "" | ||
| 3548 | + print(error) | ||
| 3549 | + } | ||
| 3550 | + } | ||
| 3551 | + | ||
| 3552 | + public var _couponset_uuid: String { | ||
| 3553 | + get { // getter | ||
| 3554 | + return self.couponset_uuid ?? "" | ||
| 3555 | + } | ||
| 3556 | + set(newValue) { //setter | ||
| 3557 | + self.couponset_uuid = newValue | ||
| 3558 | + } | ||
| 3559 | + } | ||
| 3560 | + | ||
| 3561 | + public var _date: String { | ||
| 3562 | + get { // getter | ||
| 3563 | + return self.date ?? "" | ||
| 3564 | + } | ||
| 3565 | + set(newValue) { //setter | ||
| 3566 | + self.date = newValue | ||
| 3567 | + } | ||
| 3568 | + } | ||
| 3569 | + | ||
| 3570 | + public var _discount: String { | ||
| 3571 | + get { // getter | ||
| 3572 | + return self.discount ?? "" | ||
| 3573 | + } | ||
| 3574 | + set(newValue) { //setter | ||
| 3575 | + self.discount = newValue | ||
| 3576 | + } | ||
| 3577 | + } | ||
| 3578 | + | ||
| 3579 | + public var _sharing_type: String { | ||
| 3580 | + get { // getter | ||
| 3581 | + return self.sharing_type ?? "" | ||
| 3582 | + } | ||
| 3583 | + set(newValue) { //setter | ||
| 3584 | + self.sharing_type = newValue | ||
| 3585 | + } | ||
| 3586 | + } | ||
| 3587 | + | ||
| 3588 | + public var _name: String { | ||
| 3589 | + get { // getter | ||
| 3590 | + return self.name ?? "" | ||
| 3591 | + } | ||
| 3592 | + set(newValue) { //setter | ||
| 3593 | + self.name = newValue | ||
| 3594 | + } | ||
| 3595 | + } | ||
| 3596 | + | ||
| 3597 | + public var _receiver_msisdn: String { | ||
| 3598 | + get { // getter | ||
| 3599 | + return self.receiver_msisdn ?? "" | ||
| 3600 | + } | ||
| 3601 | + set(newValue) { //setter | ||
| 3602 | + self.receiver_msisdn = newValue | ||
| 3603 | + } | ||
| 3604 | + } | ||
| 3605 | + | ||
| 3606 | + public var _sender_msisdn: String { | ||
| 3607 | + get { // getter | ||
| 3608 | + return self.sender_msisdn ?? "" | ||
| 3609 | + } | ||
| 3610 | + set(newValue) { //setter | ||
| 3611 | + self.sender_msisdn = newValue | ||
| 3612 | + } | ||
| 3613 | + } | ||
| 3614 | + } | ||
| 3615 | + | ||
| 3616 | + | ||
| 3617 | + public func getSharingHistoryAsync(_ getSharingHistoryCallback: @escaping (_ sharingHistoryData: Array<SharingCouponModel>?) -> Void) -> Void { | ||
| 3618 | + let instanceOfMyApi = MyApi() | ||
| 3619 | + instanceOfMyApi.getSharingHistoryAsync(requestCallback, failureBlock: requestFailureCallback) | ||
| 3620 | + | ||
| 3621 | + | ||
| 3622 | + func requestCallback(_ sharingHistoryData: [AnyHashable: Any]?) -> Void { | ||
| 3623 | + var historyArray:Array<SharingCouponModel> = [] | ||
| 3624 | + | ||
| 3625 | + if let responseDataDictionary = sharingHistoryData as? [String: AnyObject] { | ||
| 3626 | + | ||
| 3627 | + if (responseDataDictionary["status"] as? Int == 1) { | ||
| 3628 | + | ||
| 3629 | + if let responseDataResult = responseDataDictionary["result"] as? [[String : Any]?] { | ||
| 3630 | + | ||
| 3631 | + for item in responseDataResult { | ||
| 3632 | + if let itemDictionary = item { | ||
| 3633 | + let tempHistoyItem = SharingCouponModel(dictionary: itemDictionary) | ||
| 3634 | + historyArray.append(tempHistoyItem) | ||
| 3635 | + } | ||
| 3636 | + } | ||
| 3637 | + | ||
| 3638 | + getSharingHistoryCallback(historyArray); | ||
| 3639 | + } else { | ||
| 3640 | + getSharingHistoryCallback(nil) | ||
| 3641 | + } | ||
| 3642 | + | ||
| 3643 | + } else { | ||
| 3644 | + getSharingHistoryCallback(nil) | ||
| 3645 | + } | ||
| 3646 | + | ||
| 3647 | + } else { | ||
| 3648 | + getSharingHistoryCallback(nil) | ||
| 3649 | + } | ||
| 3650 | + } | ||
| 3651 | + | ||
| 3652 | + func requestFailureCallback(_ error: Error?) -> Void { | ||
| 3653 | + print("getSharingHistory error: ") | ||
| 3654 | + print(error) | ||
| 3655 | + print("====================") | ||
| 3656 | + getSharingHistoryCallback(nil) | ||
| 3657 | + } | ||
| 3658 | + } | ||
| 3659 | + | ||
| 3463 | } | 3660 | } | ... | ... |
-
Please register or login to post a comment