Skip to content

Instantly share code, notes, and snippets.

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

  • Save fisherds/0892f64f6998c43807e2 to your computer and use it in GitHub Desktop.

Select an option

Save fisherds/0892f64f6998c43807e2 to your computer and use it in GitHub Desktop.
Endpoints iOS Function used to insert a movie quote to our Moviequotes API
- (void) _insertQuote:(GTLMoviequotesMovieQuote*) newQuote {
// Make a query object
// Use the service to execute the query
// Use a callback block to handle the response
GTLQueryMoviequotes* query = [GTLQueryMoviequotes queryForMoviequoteInsertWithObject:newQuote];
if (kLocalhostTesting) {
query.JSON = newQuote.JSON;
query.bodyObject = nil;
}
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[self.service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLMoviequotesMovieQuote* returnedMovieQuote,
NSError *error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
if (error != nil) {
[self _showErrorDialog:error];
return;
}
// Already visible to the user, but missing an entityKey
newQuote.entityKey = returnedMovieQuote.entityKey; // Update newQuote with the entityKey of the returnedQuote
// Now it has key that can be used later for edit or delete.
// Totally optional. Look for other new quotes now (after animation completes).
[self performSelector:@selector(_queryForQuotes) withObject:nil afterDelay:1.0];
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment