Last active
August 29, 2015 14:04
-
-
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
This file contains hidden or 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) _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