Skip to content

Instantly share code, notes, and snippets.

@fisherds
fisherds / queryForQuotes.m
Last active August 29, 2015 14:04
Perform a query for Moviequotes
- (void) _queryForQuotes {
// #1. Make a query object
// #2. Use the service to execute the query
// #3. Use a callback block to handle the response
GTLQueryMoviequotes* query = [GTLQueryMoviequotes queryForMoviequoteList];
query.order = @"-last_touch_date_time";
query.limit = 30;
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[self.service executeQuery:query
@fisherds
fisherds / insertQuote.m
Last active August 29, 2015 14:04
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;
}
@fisherds
fisherds / deleteQuote.m
Created August 3, 2014 04:12
Endpoints iOS function used to Delete a MovieQuote
- (void) _deleteQuote:(NSString*) entityKeyToDelete {
// Make a query object
// Use the service to execute the query
// Use a callback block to handle the response
GTLQueryMoviequotes* query = [GTLQueryMoviequotes queryForMoviequoteDeleteWithEntityKey:entityKeyToDelete];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[self.service executeQuery:query completionHandler:^(GTLServiceTicket* ticket,
GTLMoviequotesMovieQuote* returnedMovieQuote,
NSError* error) {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
@fisherds
fisherds / updateQuote.m
Created August 4, 2014 02:34
Endpoints iOS function used to update a Movie Quote
// Within RHDetailViewController.m
#pragma mark - Endpoints
- (void) _updateQuote {
// Make a query object
// Use the service to execute the query
// Use a callback block to handle the response
GTLQueryMoviequotes* query = [GTLQueryMoviequotes queryForMoviequoteInsertWithObject:self.movieQuote];
@fisherds
fisherds / iOSEndpointsSignIn.m
Last active August 29, 2015 14:05
RHOAuthUtils methods to signIn and signOut of Endpoints OAuth
#pragma mark - Sign in / sign out utils
// Revoke the authorizer and clear the saved authorizer.
+ (void) signOut {
[GTMOAuth2ViewControllerTouch removeAuthFromKeychainForName:kKeychainItemName];
[GTMOAuth2ViewControllerTouch revokeTokenForGoogleAuthentication:__authorizer];
[RHOAuthUtils _setAuthorizer:nil];
}
@fisherds
fisherds / queryForStudents.m
Last active August 29, 2015 14:05
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];
@fisherds
fisherds / GradeRecorderServiceAndAuthorizer.m
Last active August 29, 2015 14:05
iOS Client for Endpoints Backend. GradeRecorder Service and Authorizer objects
#pragma mark - Service
+ (BOOL) isLocalHost {
return kLocalHostTesting;
}
+ (GTLServiceGraderecorder*) getService {
if (__graderecorderService == nil) {
__graderecorderService = [[GTLServiceGraderecorder alloc] init];
@fisherds
fisherds / MovieQuotes_main.py
Created August 19, 2014 04:55
Google AppEngine Handlers for a simple MovieQuotes web app
import os
from google.appengine.ext import ndb
import jinja2
from models import MovieQuote
import webapp2
jinja_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
@fisherds
fisherds / moviequotes_nobootstrap.css
Created August 19, 2014 13:06
MovieQuotes CSS with no Bootstrap
body {
background: url('/static/images/noise.jpg');
font: 14px Helvetica, serif;
}
input[name=quote] {
width: 300px;
}
input[name=movie] {
@fisherds
fisherds / jinja_env.py
Last active August 29, 2015 14:05
Creating an instance of the Jinja Environment
import os
import jinja2
import webapp2
# Jinja Environment instance necessary to use Jinja templates.
jinja_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
autoescape=True)