Skip to content

Instantly share code, notes, and snippets.

@fisherds
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save fisherds/4cd2dde07a7d4e9b0bed to your computer and use it in GitHub Desktop.

Select an option

Save fisherds/4cd2dde07a7d4e9b0bed to your computer and use it in GitHub Desktop.
iOS Client to Endpoints Backend query to get Students for GradeRecorder
+ (void) _queryForStudentsWithPageToken:(NSString*) pageToken withCallback:(void (^)()) callback {
GTLServiceGraderecorder* service = [RHOAuthUtils getService];
GTLQueryGraderecorder* query = [GTLQueryGraderecorder queryForStudentList];
query.limit = 10;
query.pageToken = pageToken;
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[service executeQuery:query completionHandler:^(GTLServiceTicket* ticket,
GTLGraderecorderStudentCollection* studentCollection,
NSError* error){
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
if (error != nil) {
NSLog(@"Unable to query for students %@", error);
[RHDialogUtils showErrorDialog:error];
__isQueryInProgress = NO;
return;
}
// Add the new students to the array and the maps.
[__students addObjectsFromArray:studentCollection.items];
for (GTLGraderecorderStudent* student in studentCollection.items) {
// Add this student to the array of students for the team.
if (student.team) {
NSMutableArray* teamMembers = [__teamMap objectForKey:student.team];
if (teamMembers == nil) {
teamMembers = [[NSMutableArray alloc] init]; // First student on team.
}
[teamMembers addObject:student];
[__teamMap setObject:teamMembers forKey:student.team];
}
}
// See if there are more students on the server.
if (studentCollection.nextPageToken != nil) {
NSLog(@"Finished query but there are more students! So far we have %d students.",
(int)__students.count);
[self _queryForStudentsWithPageToken:studentCollection.nextPageToken withCallback:callback];
} else {
NSLog(@"Finished all student queries. Ended up with %d students.", (int)__students.count);
__isQueryInProgress = NO;
if (callback != nil) {
callback(); // Could also use a notification, but I prefer callback blocks.
}
}
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment