Skip to content

Instantly share code, notes, and snippets.

@seivan
Last active August 29, 2015 13:56
Show Gist options
  • Save seivan/b371906fdf405121d7a7 to your computer and use it in GitHub Desktop.
Save seivan/b371906fdf405121d7a7 to your computer and use it in GitHub Desktop.
+(void)setupAuthenticationCallbacksWithUserModel:(XXXWebScaleUserModel *)theWebScaleUserModel onCompleteBlock:(XXXCurrentUserBlock)theBlock; {
NSParameterAssert(theBlock);
NSParameterAssert(theWebScaleUserModel.phoneNumber);
NSParameterAssert(theWebScaleUserModel.password);
//Hmm lets not clear up the blocks because lol. ~ Seivan.
__block XXXCurrentUser * user = nil;
dispatch_group_t grouprequestNetOperatorsOnComplete = dispatch_group_create();
dispatch_group_t groupRequestMyProfile = dispatch_group_create();
dispatch_group_t groupRequestMyApplications = dispatch_group_create();
dispatch_group_t groupRequestMyNotifications = dispatch_group_create();
[[XXXClient sharedManager] setObserverDidSignInBlock:^(XXXAccessCredential *accessCredential, NSError *error) {
[[LUKeychainAccess standardKeychainAccess] setObject:accessCredential forKey:NSStringFromClass([self class])];
if(error)theBlock(nil,error);
else dispatch_group_leave(grouprequestNetOperatorsOnComplete);
}];
dispatch_group_enter(grouprequestNetOperatorsOnComplete);
dispatch_group_notify(grouprequestNetOperatorsOnComplete, dispatch_get_main_queue(), ^{
[XXXNetOperator requestNetworkOperatorsOnCompleteBlock:^(NSArray *responseObjects, NSError *error) {
if(error) theBlock(nil, error);
else dispatch_group_leave(groupRequestMyProfile);
}];
});
dispatch_group_enter(groupRequestMyProfile);
dispatch_group_notify(groupRequestMyProfile, dispatch_get_main_queue(), ^{
[self requestMyProfileOnCompleteBlock:^(XXXCurrentUser *currentUser, NSError *error) {
if(error) theBlock(currentUser, error);
else {
user = currentUser;
dispatch_group_leave(groupRequestMyApplications);
}
}];
});
dispatch_group_enter(groupRequestMyApplications);
dispatch_group_notify(groupRequestMyApplications, dispatch_get_main_queue(), ^{
[user requestGrantedApplicationsOnCompleteBlock:^(XXXCurrentUser *currentUser, NSError *error) {
if(error) theBlock(nil,error);
else dispatch_group_leave(groupRequestMyNotifications);
}];
});
dispatch_group_enter(groupRequestMyNotifications);
dispatch_group_notify(groupRequestMyNotifications, dispatch_get_main_queue(), ^{
[user requestActionsOnCompleteBlock:^(XXXCurrentUser *currentUser, NSError *error) {
if(error) theBlock(nil,error);
else theBlock(currentUser, error);
}];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment