A web UI for the Google Play Games API.
JavaScript HTML CSS
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src
test
.gitignore
LICENSE
README.md

README.md

Introduction

The goal of this project is to provide a web UI for the Google Play Games API loosely based on the Android UI.

Getting started

Follow the client only setup instructions.

Include the following at the end of your body element:

<script src="{PATH_TO_JS}/underscore.js"></script>
<script src="{PATH_TO_JS}/api.js"></script>
<!-- This is dumb, but the callback function must be directly attached to window. -->;
<script>YOUR_JS_CALLBACK_FUNCTION = GoogleGamesApi.authCallback;</script>
<script src="https://apis.google.com/js/client:platform.js"></script>

Start using the API.

Fetch a list of leaderboards for the game.

GoogleGamesApi.runWhenAuthenticated(function(oApi) {
  oApi.leaderboards.list(function(oResponse) {
    // Do something with the response.
  });
});

Load achievement definitions and instances in sequence.

GoogleGamesApi.runWhenAuthenticated(function(oApi) {
  var oAchievementInstanceMap = {};
  GoogleGamesApi.achievements.definitions(function(oResponse) {
      _.each(oResponse.items, function(oAchievementDefinition) {
        oAchievementInstanceMap[oAchievementDefinition.id] = oAchievementDefinition;
      });
  }).achievements.instances(function(oResponse) {
      _.each(oResponse.items, function(oAchievementInstance) {
        var oAchievementDefinition = oAchievementInstanceMap[oAchievementInstance.id];
        console.log('You have ' + oAchievementInstance.achievementState
            + ' the achievement ' + oAchievementDefinition.name);
      });
  }, {playerId: 'me'});
});

Dependencies

UnderscoreJs is currently the only required third party library, but as the code base grows, I will probably use RequireJs as well to modularize dependencies.

API

The existing Google Play Games API requires unnecessary boilerplate and lots of nested callback functions to order operations. Instead I wanted to wrap the authentication boilerplate and create chainable methods so dependent data can be loaded in sequence (ex. definitions & instances).

All methods have been namespaced on the GoogleGamesApi object and the returned object from any method will have the same namespaces. Only chained calls will wait on each other, calling GoogleGamesApi directly will execute all methods asynchronously.

All methods will assert that the Google Play Games Services are available or will raise an exception.

The signature for all API calls is a callback function followed by an object that should contain any required or optional keys. The required/optional keys can be found on the Google Play Games developer website.

Here is a list of the available API endpoints linked to their documentation:

Achievements

Applications

Events

Leaderboards

MetaGame

Players

Push Tokens

Quests

Rooms

Scores

Snapshots

Turn-based Multiplayer (TMBP)

Roadmap

  • 0.1 - API wrapper written
  • 0.2 - UI for achievements
  • 0.3 - UI for leaderboards
  • 0.4 - UI for players
  • 0.5 - UI for quests
  • 0.6 - modularize UI
  • 1.0 - usable product