Last active
June 30, 2017 13:35
-
-
Save agramonte/7a437ea74a7bbc613120c04c9c94a67d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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