Manos Chorianopoulos

add getProfileAsync request and Profile Model

...@@ -78,6 +78,8 @@ ...@@ -78,6 +78,8 @@
78 - (void)getCouponsWithSuccessBlock:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure; 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; 79 - (void)getCouponsetsAsync:(NSNumber*) active andVisible:(NSNumber*) visible andUuids:(NSArray*) uuids :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
80 - (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure; 80 - (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure;
81 +- (void)verifyTicketAsync:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
82 +- (void)getProfileAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
81 83
82 @end 84 @end
83 #endif /* MyApi_h */ 85 #endif /* MyApi_h */
......
...@@ -1297,4 +1297,28 @@ CMPedometer *pedometer; ...@@ -1297,4 +1297,28 @@ CMPedometer *pedometer;
1297 } 1297 }
1298 }]; 1298 }];
1299 } 1299 }
1300 +
1301 +- (void)verifyTicketAsync:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
1302 +{
1303 + [[Warply sharedService] verifyTicketWithSuccessBlock:guid :ticket :^(NSDictionary *response) {
1304 + if (success) {
1305 + success(response);
1306 + }
1307 + } failureBlock:^(NSError *error) {
1308 + if (failure) {
1309 + failure(error);
1310 + }
1311 + }];
1312 +}
1313 +
1314 +- (void)getProfileAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
1315 +{
1316 + [[Warply sharedService] getProfileWithSuccessBlock:^(NSDictionary *response) {
1317 + if (success) {
1318 + success(response);
1319 + }
1320 + } failureBlock:^(NSError *error) {
1321 + failure(error);
1322 + }];
1323 +}
1300 @end 1324 @end
......
...@@ -465,4 +465,120 @@ public class swiftApi { ...@@ -465,4 +465,120 @@ public class swiftApi {
465 // public func openSteps(parent: UIView) -> UIViewController { 465 // public func openSteps(parent: UIView) -> UIViewController {
466 // return UIHostingController(rootView: StepsView(parentView: parent)) 466 // return UIHostingController(rootView: StepsView(parentView: parent))
467 // } 467 // }
468 +
469 +
470 + public class ProfileModel {
471 + let ack_optin: Bool?
472 + let billing_info: [String: Any]?
473 + let birthday: String?
474 + let burnt_points: Double?
475 + let company_name: String?
476 + let consumer_metadata: [String: Any]?
477 + let display_name: String?
478 + let email: String?
479 + let firstname: String?
480 + let gender: String?
481 + let image_url: String?
482 + let language: String?
483 + let lastname: String?
484 + let loyalty_id: String?
485 + let msisdn: String?
486 + let nameday: String?
487 + let nickname: String?
488 + let password_set: Bool?
489 + let profile_metadata: [String: Any]?
490 + let redeemed_points: Double?
491 + let retrieved_points: Double?
492 + let salutation: String?
493 + let subscribe: Bool?
494 + let tags: [String: Any]?
495 + let tax_id: String?
496 + let user_points: Double?
497 + let uuid: String?
498 + let verified: Bool?
499 +
500 + // optin
501 + let optin_newsletter: Bool?
502 + let optin_sms: Bool?
503 + let optin_segmentation: Bool?
504 + let optin_sms_segmentation: Bool?
505 +
506 +
507 + init(dictionary: [String: Any]) {
508 + self.ack_optin = dictionary["ack_optin"] as? Bool? ?? false
509 + self.billing_info = dictionary["billing_info"] as? [String: Any]? ?? ["":""]
510 + self.birthday = dictionary["birthday"] as? String? ?? ""
511 + self.burnt_points = dictionary["burnt_points"] as? Double? ?? 0.0
512 + self.company_name = dictionary["company_name"] as? String? ?? ""
513 + self.consumer_metadata = dictionary["consumer_metadata"] as? [String: Any]? ?? ["":""]
514 + self.display_name = dictionary["display_name"] as? String? ?? ""
515 + self.email = dictionary["email"] as? String? ?? ""
516 + self.firstname = dictionary["firstname"] as? String? ?? ""
517 + self.gender = dictionary["gender"] as? String? ?? ""
518 + self.image_url = dictionary["image_url"] as? String? ?? ""
519 + self.language = dictionary["language"] as? String? ?? ""
520 + self.lastname = dictionary["lastname"] as? String? ?? ""
521 + self.loyalty_id = dictionary["loyalty_id"] as? String? ?? ""
522 + self.msisdn = dictionary["msisdn"] as? String? ?? ""
523 + self.nameday = dictionary["nameday"] as? String? ?? ""
524 + self.nickname = dictionary["nickname"] as? String? ?? ""
525 + self.password_set = dictionary["password_set"] as? Bool? ?? false
526 + self.profile_metadata = dictionary["profile_metadata"] as? [String: Any]? ?? ["":""]
527 + self.redeemed_points = dictionary["redeemed_points"] as? Double? ?? 0.0
528 + self.retrieved_points = dictionary["retrieved_points"] as? Double? ?? 0.0
529 + self.salutation = dictionary["salutation"] as? String? ?? ""
530 + self.subscribe = dictionary["subscribe"] as? Bool? ?? false
531 + self.tags = dictionary["tags"] as? [String: Any]? ?? ["":""]
532 + self.tax_id = dictionary["tax_id"] as? String? ?? ""
533 + self.user_points = dictionary["user_points"] as? Double? ?? 0.0
534 + self.uuid = dictionary["uuid"] as? String? ?? ""
535 + self.verified = dictionary["verified"] as? Bool? ?? false
536 +
537 + // optin
538 + let optin = dictionary["optin"] as? [String: Any]? ?? ["":""]
539 + self.optin_newsletter = optin?["newsletter"] as? Bool? ?? false
540 + self.optin_sms = optin?["sms"] as? Bool? ?? false
541 + self.optin_segmentation = optin?["segmentation"] as? Bool? ?? false
542 + self.optin_sms_segmentation = optin?["sms_segmentation"] as? Bool? ?? false
543 +
544 + }
545 + }
546 +
547 + public class ProfileDataModel {
548 +
549 + init() {
550 + }
551 +
552 + func getProfileData(_ getProfileCallback: @escaping (_ profileData: ProfileModel?) -> Void) -> Void {
553 +
554 + let instanceOfMyApi = MyApi()
555 + instanceOfMyApi.getProfileAsync(profileCallback, failureBlock: profileFailureCallback)
556 +
557 + func profileCallback(_ profileData: [AnyHashable: Any]?) -> Void {
558 +
559 + if let profileDataDictionary = profileData as? [String : AnyObject] {
560 + let profileDataResult = (profileDataDictionary["result"] as? [String: Any] ?? ["":""])
561 +
562 + let tempProfile = ProfileModel(dictionary: profileDataResult)
563 +
564 + getProfileCallback(tempProfile);
565 +
566 + } else {
567 + getProfileCallback(nil)
568 + }
569 +
570 + }
571 +
572 + func profileFailureCallback(_ error: Error?) -> Void {
573 + print("getProfile error: ")
574 + getProfileCallback(nil)
575 + }
576 +
577 + }
578 + }
579 +
580 +
581 + public func getProfileAsync(_ getProfileCallback: @escaping (_ profileData: ProfileModel?) -> Void) -> Void {
582 + ProfileDataModel().getProfileData(getProfileCallback)
583 + }
468 } 584 }
......