Skip to content

Instantly share code, notes, and snippets.

@pita5
Created July 23, 2012 13:37
Show Gist options
  • Save pita5/3163637 to your computer and use it in GitHub Desktop.
Save pita5/3163637 to your computer and use it in GitHub Desktop.
- (void)_updateEntries:(void (^)(void))block forEvent:(SKEvent *)event caller:(dispatch_queue_t)callerqueue
{
void(^block_c)(void) = ^(void) {
NSLog(@"completed update entries for %@", event.uid);
if (block) block();
};
// Fail early if no event
if (!event)
{
[self _didFailUpdateEntries:block_c forEvent:event caller:callerqueue];
return;
}
NSURLResponse* __autoreleasing response = nil;
NSError* __autoreleasing responseError = nil;
NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kSKEntriesFormat,event.actid]];
NSData* responseData = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:url] returningResponse:&response error:&responseError];
if (!responseData || responseError)
{
[self _didFailUpdateEntries:block_c forEvent:event caller:callerqueue];
return;
}
NSError* __autoreleasing jsonError = nil;
NSDictionary* baseDictionary = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingAllowFragments error:&jsonError];
if (!baseDictionary || jsonError)
{
[self _didFailUpdateEntries:block_c forEvent:event caller:callerqueue];
return;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment