Data

The SDK provides a simple Key Value (KV) store. On login, two data stores are opened / created for this user. There is a private data store for this users exclusive use, and a global data store this user shares with all other users of this same app. If a user logs out and logs in at a later date, the data in the private data store will be as left upon logout. The contents of the global data store will most likely have changed based on write operation of other users.

  • Write Data

This method will write a KV pair to the referenced data store. If a key is used more than once for writing, the value associated with the key will be updated and reflect the most recent write operation.

PPwriteData(bucketname, key, value)
parms:
bucketname - the name of the data store (string). To use one of the pre-defined buckets (one private, one app global) this method can be called with PPgetMyBucketName(p) where p is boolean (true = my private, false = app global)
key - a key to associate with this data (string)
value - value to store (JSON.stringify'able JSON, e.g. objects w/o functions)
returns:
A promise that will resolve to indicate the success/error status of the write operation.

Example: to write { somekey : somevalue } to your application private data store:

PPwriteData(PPgetMyBucketName(true), somekey, somevalue)
.then((response) => {
console.log("KV written K:", somekey + " V:" + JSON.stingify(somevalue));
})
.catch((error) => {
console.error(error);
})
  • Read data

This method will read a value from the bucket named bucketname for the Key key. It returns a promise that will either contain JSON data (on success) or an error.

PPreadData(bucket, key)
parms:
bucketname - the name of the data store (string) or use the PPgetMyBucketName(boolean)
key - the key to read data from (string)
returns:
A promise that will resolve on success to a response containing the profiles of the user's friends and on failure an error indicating the error status.

Example: to read { somekey } from your application global app data store:

PPreadData(PPgetMyBucketName(false), somekey)
.then((response) => {
console.log("KV read K:", somekey + " V:" + JSON.stringify(response));
})
.catch((error) => {
console.error(error);
})
  • Create bucket

The user may also create additional data stores as necessary. That is done as:

PPcreateBucket(bucketname, users[], ispublic)
parms:
bucketname - the name of the data store (string)
users - CSV array of user ids
ispublic - non-zero / non-null creates a public bucket
returns:
A promise that will resolve on success to a response containing the newly created bucket's metadata and on failure an error indicating the error status.

Example: create a new bucket named "gamescores" that is accessible by any app user

PPcreateBucket('gamescores', [], true)
.then((response) => {
console.log("new bucket created: ", newbucket);
})
.catch((error) => {
console.error(error);
})

For subsequent reads/writes to this new bucket, the same name should be utilized as the bucketname, e.g. gamescores.