I have a class that handles interaction with an external API, and I'm trying to figure out the best way to break them into descreat chunks.
At the moment, it looks something like this:
- (BOOL) testCredentialsWithUsername:(NSString *)username password:(NSString *)password {
acUsername = username;
acPassword = password;
[self loadLoginPage];
return YES;
}
- (void)loadLoginPage {
[NSURLConnection sendAsynchronousRequest:...
completionHandler:^(...) {
[self logIntoMyAPI:response];
}];
}
- (void)logIntoMyAPI:(NSURLResponse *)response {
[NSURLConnection sendAsynchronousRequest:...
completionHandler:^(...) {
[self recieveLoginResponse:response data:data];
}];
}
- (void)recieveLoginResponse:(NSURLResponse *) response data:(NSData *)data {
if (...) {
NSLog(@"Logged into MyAPI!");
} else if (...) {
NSLog(@"Invalid username or password");
} else if (...) {
NSLog(@"Locked account");
} else {
NSLog(@"An unexpected error");
}
}
Basically, I want to call testCredtionalsWithUsername:password:
from my View Controller and, probably using success/failure blocks, know the outcome.
What's the best way to do this without tieing the callbacks to the test testCredtionalsWithUsername:password:
method?