
At other companies I’ve been with, there was always a need to be on call after hours to deal with server problems. This isn’t necessary here, because Google App Engine just works.
public class Game { public Game updateGame(String state) { // method logic here return game; } }
@Api public class Game { public Game updateGame(@Named("state") String state) { // method logic here return game; } }
localhost:home user$ ./ServiceGenerator my-api-v1-rpc.discovery ========================================================== Writing: + GTLQueryMyApi.h (1610 bytes) - NEW + GTLQueryMyApi.m (2316 bytes) - NEW + GTLServiceMyApi.h (1471 bytes) - NEW + GTLServiceMyApi.m (1364 bytes) - NEW + GTLMyApi.h (474 bytes) - NEW
GTLGame *game = [GTLGame alloc]; [game setState:state]; GTLQueryGame *query = [GTLQueryGame queryForGameUpdateWithObject:game]; ...
@Api( name = "tictactoe", version = "v1", clientIds = {Ids.WEB_CLIENT_ID, Ids.ANDROID_CLIENT_ID, Ids.IOS_CLIENT_ID}, audiences = {Ids.ANDROID_AUDIENCE} )
public class Ids { public static final String WEB_CLIENT_ID = "abc123.apps.googleusercontent.com"; public static final String ANDROID_CLIENT_ID = "abc123-4567.apps.googleusercontent.com"; public static final String IOS_CLIENT_ID = "abc123.apps.googleusercontent.com"; public static final String ANDROID_AUDIENCE = WEB_CLIENT_ID; }
@ApiMethod(name = "scores.insert") public Score insert(Score score, User user) throws OAuthRequestException, IOException { if (user != null) { score.setPlayed(new Date()); score.setPlayer(user); PersistenceManager pm = getPersistenceManager(); pm.makePersistent(score); pm.close(); return score; } else { throw new OAuthRequestException("Invalid user."); } }
var apisToLoad = 2; var callback = function() { if (--apisToLoad == 0) { signin(true, userAuthed); } } gapi.client.load('tictactoe', 'v1', callback, apiRoot); gapi.client.load('oauth2', 'v2', callback);
function signin(mode, callback) { gapi.auth.authorize({client_id: CLIENT_ID, scope: SCOPES, immediate: mode, response_type: 'token id_token'}, callback); }
function userAuthed() { var request = gapi.client.oauth2.userinfo.get().execute(function(resp) { if (!resp.code) { var token = gapi.auth.getToken(); token.access_token = token.id_token; gapi.auth.setToken(token); // User is signed in, call Endpoints } }); }
<a href="#" onclick="auth();" id="signinButton">Sign in!</a>
This calls authorize
without immediate mode:
function auth() { signin(false, userAuthed); }