Created
October 21, 2011 21:12
-
-
Save greenisus/1304992 to your computer and use it in GitHub Desktop.
RSServer get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (void)get { | |
[RSServer get:nil completionBlock:^(CKResult *result) { | |
NSLog(@"server get response code %i: %@", result.responseCode, [[NSString alloc] initWithData:result.responseBody encoding:NSUTF8StringEncoding]); | |
if ([result isSuccess]) { | |
// We should remove servers that didn't come back in the results. | |
// To do this, we need to find the complement to the result set and | |
// the set of all servers currently stored in Core Data. | |
NSArray *allServers = [RSServer findWithPredicate:[self predicate]]; | |
NSMutableSet *complementSet = [NSMutableSet setWithArray:allServers]; | |
NSMutableSet *intersectionSet = [NSMutableSet setWithArray:allServers]; | |
NSMutableSet *resultsSet = [NSMutableSet setWithArray:result.objects]; | |
[intersectionSet intersectSet:resultsSet]; | |
[complementSet minusSet:intersectionSet]; | |
[RSServer removeAllInSet:complementSet]; | |
[RSServer save]; | |
} else if (result.responseCode == 401) { | |
// the auth token has expired. reauthenticate and try this request again | |
if ([[RSAccount activeAccount] authenticate]) { | |
[self get]; | |
} | |
} | |
} errorBlock:^(CKResult *result) { | |
NSLog(@"error: %@", [result.error description]); | |
}]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment