Skip to content

Instantly share code, notes, and snippets.

@agramonte
Last active June 30, 2017 13:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agramonte/7a437ea74a7bbc613120c04c9c94a67d to your computer and use it in GitHub Desktop.
Save agramonte/7a437ea74a7bbc613120c04c9c94a67d to your computer and use it in GitHub Desktop.
//Get url: https://preview.gamesparks.net/callback/<apiKey>/savePlayerTable/<credential secret>?username=<username>&password=<user password>&tablename=<table name>
//Save url: https://preview.gamesparks.net/callback/<apiKey>/getPlayerTable/<credential secret>?username=<username>&password=<user password>&tablename=<table name>
//Get Code
var uPwd = Spark.getData().password;
var uName = Spark.getData().username;
var uTableName = Spark.getData().tablename;
var authenticationResponse = Spark.sendRequest(
{
"@class": ".AuthenticationRequest",
"password": uPwd,
"userName": uName
}
)
if (authenticationResponse.error == null) {
var collection = Spark.runtimeCollection(uTableName);
var tableholder = collection.findOne({"userId":authenticationResponse.userId});
if (tableholder) {
var table = tableholder["userTable"];
Spark.setScriptData("RESPONSE_RAW", table);
} else {
Spark.setScriptData("RESPONSE_RAW", '{"Status": ""}');
}
}
//Save Code
var playerTable = Spark.getData().params;
var uPwd = Spark.getData().password;
var uName = Spark.getData().username;
var uTableName = Spark.getData().tablename;
var authenticationResponse = Spark.sendRequest(
{
"@class": ".AuthenticationRequest",
"password": uPwd,
"userName": uName
}
)
if (authenticationResponse.error == null) {
if (playerTable){
var collection = Spark.runtimeCollection(uTableName);
var jsonObject = JSON.parse(playerTable);
var tableholder = {};
tableholder["userId"] = authenticationResponse.userId;
tableholder["userTable"] = jsonObject;
collection.remove({"userId":authenticationResponse.userId});
collection.insert(tableholder);
Spark.setScriptData("RESPONSE_RAW", '{"Status":"Success"}');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment