Sandbox
This page is for you to test out some of the API calls for our example game.
Play around and edit the code inline!
var leaderboard = new Clay.Leaderboard( { id: 1 } );
var options = { // Try these out
// html: "<strong>Hi</strong>",
// recent: 3600,
// limit: 5,
// showPersonal: true,
// cumulative: false,
// tabs: [{ id: 2 }]
}
leaderboard.show( options, function(response) {
console.log( response );
} );
var leaderboard = new Clay.Leaderboard( { id: 1 } );
leaderboard.post( { score: 50 }, function(response) {
console.log( response );
} );
var options = {
size: '125x125',
position:
{
left: '50%',
top: 100,
reference: 'center'
}
};
window.advertisement = new Clay.Advertisement( options );
// Comment the above line, uncomment below, and run again this to hide the ad
// advertisement.hide()
var achievement = new Clay.Achievement( { id: 1 } );
// This will grant you an achievement if you don't already have it
achievement.award( function(response) {
console.log( response );
} );
var pay = new Clay.Payment();
var handler = function() {
pay.checkout( function( response ) {
// Responses regarding payment
console.log( response.success );
console.log( response.status );
console.log( response.error );
// Boolean, if the payment was approved right away or not
console.log( response.completed );
// The items they ended up purchasing - this could be different than the
// items you pass since they can optionally remove items
console.log( response.itemIds );
} );
};
pay.addItem( { id: 3 }, handler );
Clay.Player.grantItem( { id: 1 }, function(response) {
console.log( response);
} );
var fb = new Clay.Facebook();
fb.post( { message: 'This is a test message from clay.io', editable: true }, function(obj) {
console.log( obj );
} );
var twitter = new Clay.Twitter();
twitter.post( { message: 'Test tweet from clay.io', editable: true }, function( response ) {
console.log( response );
} );
var stream = new Clay.Stream();
stream.post( { message: 'Test from API', editable: true }, function( response ) {
console.log( response );
} );
Clay.Ratings();
// Draw in the box below, then demo this
new Clay.Screenshot();
Clay.Player.fetchItems( function( response ) {
// Array of items this user has
console.log( response );
} );
if( Clay.Player.hasInstalled() )
console.log( 'You have installed this game' );
else
console.log( 'You have not installed this game' );
Clay.Player.purchaseGame( function( response ) {
// Called once purchase goes through
console.log( response );
} );
var quantity = 1; // Say, if you want to log 1 press of a certain button
Clay.Stats.logStat( { name: 'custom-name', quantity: quantity } );
var rooms = new Clay.Rooms( function( response ) {
console.log( response );
} );
rooms.show();
// Open in another tab and join
new Clay.Suggestions();
Clay.Player.saveUserData( 'test', {a: 'okay'}, function(response) {
console.log( response );
} );
Clay.Player.fetchUserData( 'test', function(response) {
console.log( response );
} );
Clay.Facebook.invite( {
caption: "Check out Clay.io" // optional
} );
// Displays all achievements available for a game, and whether or not they have been earned
Clay.Achievement.showAll();
Provide Feedback
We take customer support, and the quality of our developer tools and documentation very seriously. We want to hear how you think we can improve our documentation! Let us know if anything is missing, or unclear on this documentation page, and we'll get that fixed!