I'm having a little trouble thinking through this and deciding if it's a design flaw on my behalf or if I'm missing a piece that could make this work. Basically I'm using the new SLRequest to make a Twitter API call. After the data is returned, I'd like to put it into an object and return that object:
-(AUDSlide *) getFollowerSlide {
SLRequest *getRequest = [SLRequest
requestForServiceType:SLServiceTypeTwitter
requestMethod:SLRequestMethodGET
URL:[NSURL URLWithString:[NSString stringWithFormat:@"https://api.twitter.com/1.1/followers/ids.json?user_id=%@", [[self.twitterAccount valueForKey:@"properties"] valueForKey:@"user_id"]]]
parameters:nil];
getRequest.account = twitterAccount;
AUDSlide *slide = [[AUDSlide alloc] init];
[getRequest performRequestWithHandler:^(NSData *responseData,
NSHTTPURLResponse *urlResponse, NSError *error)
{
if ([urlResponse statusCode] == 200) {
NSError *jsonError = nil;
NSDictionary *list = [NSJSONSerialization JSONObjectWithData:responseData
options:0
error:&jsonError];
NSLog(@"Number of Followers: %u", [[list objectForKey:@"ids"] count]);
slide.title = @"Followers";
slide.number = [NSString stringWithFormat:@"%u",[[list objectForKey:@"ids"] count]];
}
else{
slide.title = @"Error";
slide.number = [NSString stringWithFormat: @"E%u", [urlResponse statusCode]];
}
}];
return slide;
}
Of course the slide is returned before the call is complete and returns a nil object. So I'm not sure if I should try to force this into a synchronous request (that seems like it could be a bad idea) or rethink the design. Does anyone have any advice?