Manos Chorianopoulos

add getProfileAsync request and Profile Model

......@@ -78,6 +78,8 @@
- (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;
- (void)getInboxAsync:(void (^)(NSArray *list))success failureBlock:(void (^)(NSError *error))failure;
- (void)verifyTicketAsync:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
- (void)getProfileAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure;
@end
#endif /* MyApi_h */
......
......@@ -1297,4 +1297,28 @@ CMPedometer *pedometer;
}
}];
}
- (void)verifyTicketAsync:(NSString*)guid :(NSString*)ticket :(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
[[Warply sharedService] verifyTicketWithSuccessBlock:guid :ticket :^(NSDictionary *response) {
if (success) {
success(response);
}
} failureBlock:^(NSError *error) {
if (failure) {
failure(error);
}
}];
}
- (void)getProfileAsync:(void(^)(NSDictionary *response))success failureBlock:(void(^)(NSError *error))failure
{
[[Warply sharedService] getProfileWithSuccessBlock:^(NSDictionary *response) {
if (success) {
success(response);
}
} failureBlock:^(NSError *error) {
failure(error);
}];
}
@end
......
......@@ -465,4 +465,120 @@ public class swiftApi {
// public func openSteps(parent: UIView) -> UIViewController {
// return UIHostingController(rootView: StepsView(parentView: parent))
// }
public class ProfileModel {
let ack_optin: Bool?
let billing_info: [String: Any]?
let birthday: String?
let burnt_points: Double?
let company_name: String?
let consumer_metadata: [String: Any]?
let display_name: String?
let email: String?
let firstname: String?
let gender: String?
let image_url: String?
let language: String?
let lastname: String?
let loyalty_id: String?
let msisdn: String?
let nameday: String?
let nickname: String?
let password_set: Bool?
let profile_metadata: [String: Any]?
let redeemed_points: Double?
let retrieved_points: Double?
let salutation: String?
let subscribe: Bool?
let tags: [String: Any]?
let tax_id: String?
let user_points: Double?
let uuid: String?
let verified: Bool?
// optin
let optin_newsletter: Bool?
let optin_sms: Bool?
let optin_segmentation: Bool?
let optin_sms_segmentation: Bool?
init(dictionary: [String: Any]) {
self.ack_optin = dictionary["ack_optin"] as? Bool? ?? false
self.billing_info = dictionary["billing_info"] as? [String: Any]? ?? ["":""]
self.birthday = dictionary["birthday"] as? String? ?? ""
self.burnt_points = dictionary["burnt_points"] as? Double? ?? 0.0
self.company_name = dictionary["company_name"] as? String? ?? ""
self.consumer_metadata = dictionary["consumer_metadata"] as? [String: Any]? ?? ["":""]
self.display_name = dictionary["display_name"] as? String? ?? ""
self.email = dictionary["email"] as? String? ?? ""
self.firstname = dictionary["firstname"] as? String? ?? ""
self.gender = dictionary["gender"] as? String? ?? ""
self.image_url = dictionary["image_url"] as? String? ?? ""
self.language = dictionary["language"] as? String? ?? ""
self.lastname = dictionary["lastname"] as? String? ?? ""
self.loyalty_id = dictionary["loyalty_id"] as? String? ?? ""
self.msisdn = dictionary["msisdn"] as? String? ?? ""
self.nameday = dictionary["nameday"] as? String? ?? ""
self.nickname = dictionary["nickname"] as? String? ?? ""
self.password_set = dictionary["password_set"] as? Bool? ?? false
self.profile_metadata = dictionary["profile_metadata"] as? [String: Any]? ?? ["":""]
self.redeemed_points = dictionary["redeemed_points"] as? Double? ?? 0.0
self.retrieved_points = dictionary["retrieved_points"] as? Double? ?? 0.0
self.salutation = dictionary["salutation"] as? String? ?? ""
self.subscribe = dictionary["subscribe"] as? Bool? ?? false
self.tags = dictionary["tags"] as? [String: Any]? ?? ["":""]
self.tax_id = dictionary["tax_id"] as? String? ?? ""
self.user_points = dictionary["user_points"] as? Double? ?? 0.0
self.uuid = dictionary["uuid"] as? String? ?? ""
self.verified = dictionary["verified"] as? Bool? ?? false
// optin
let optin = dictionary["optin"] as? [String: Any]? ?? ["":""]
self.optin_newsletter = optin?["newsletter"] as? Bool? ?? false
self.optin_sms = optin?["sms"] as? Bool? ?? false
self.optin_segmentation = optin?["segmentation"] as? Bool? ?? false
self.optin_sms_segmentation = optin?["sms_segmentation"] as? Bool? ?? false
}
}
public class ProfileDataModel {
init() {
}
func getProfileData(_ getProfileCallback: @escaping (_ profileData: ProfileModel?) -> Void) -> Void {
let instanceOfMyApi = MyApi()
instanceOfMyApi.getProfileAsync(profileCallback, failureBlock: profileFailureCallback)
func profileCallback(_ profileData: [AnyHashable: Any]?) -> Void {
if let profileDataDictionary = profileData as? [String : AnyObject] {
let profileDataResult = (profileDataDictionary["result"] as? [String: Any] ?? ["":""])
let tempProfile = ProfileModel(dictionary: profileDataResult)
getProfileCallback(tempProfile);
} else {
getProfileCallback(nil)
}
}
func profileFailureCallback(_ error: Error?) -> Void {
print("getProfile error: ")
getProfileCallback(nil)
}
}
}
public func getProfileAsync(_ getProfileCallback: @escaping (_ profileData: ProfileModel?) -> Void) -> Void {
ProfileDataModel().getProfileData(getProfileCallback)
}
}
......