// An example of how to access Cloud Script methods. void TestCloudScript() { // this will be called after we have an API endpoint UnityAction RunAfterEndpoint = () => { RunCloudScriptRequest request = new RunCloudScriptRequest(); request.ActionId = "helloWorld"; PlayFabClientAPI.RunCloudScript(request, (RunCloudScriptResult result) => { // we are expecting a string,string keyvaluepair, so here we are capturing the kvp with a dictionary due to it being easier to work with. Dictionary <string, string> deserializedResults = new Dictionary <string, string>(); deserializedResults = JsonConvert.DeserializeObject <Dictionary <string, string> >(result.ResultsEncoded); string message = string.Empty; if (deserializedResults.TryGetValue("messageValue", out message)) { cloudScriptResponse.text = string.Format("Cloud Script -- Version: {0}, Revision: {1} \nResponse: {2}", result.Version, result.Revision, message); } else { cloudScriptResponse.text = "Cloud Script call was successful, but there was an error deserializing the messageValue"; } }, OnPlayFabError); }; // we need to supply the SDK with the endpoint before our RunCloudScriptRequests will succeed GetCloudScriptEndpoint(RunAfterEndpoint); }
public void CloudRequest() { Dictionary <string, string> upgradeParams = new Dictionary <string, string>(); upgradeParams.Add("Class", "Buildings"); RunCloudScriptRequest request = new RunCloudScriptRequest() { ActionId = "initiateUpgrade", Params = new { data = upgradeParams } }; PlayFabClientAPI.RunCloudScript(request, (result) => { Debug.Log("Got log entries:"); Debug.Log(result.ActionLog); Debug.Log("Time: " + result.ExecutionTime); if (result.Results != null) { Debug.Log("and return value: " + result.Results.ToString()); } }, (error) => { Debug.Log("Error calling helloWorld in Cloud Script:"); Debug.Log(error.ErrorMessage); }); }
public void GetAllTitleDataForClass(string i_className, Callback <string> requestSuccessCallback) { StartRequest("Request all data for class " + i_className); Dictionary <string, string> upgradeParams = new Dictionary <string, string>(); upgradeParams.Add("Class", i_className); RunCloudScriptRequest request = new RunCloudScriptRequest() { ActionId = "getAllDataForClass", Params = new { data = upgradeParams } }; PlayFabClientAPI.RunCloudScript(request, (result) => { RequestComplete("Cloud logs for all data request for " + i_className + "(" + result.ExecutionTime + "):" + result.ActionLog, LogTypes.Info); if (result.Results != null) { string res = result.Results.ToString(); res = res.CleanStringForJsonDeserialization(); requestSuccessCallback(res); } }, (error) => { HandleError(error, BackendMessages.TITLE_DATA_FAIL); }); }
public void MakeCloudCall(string i_methodName, Dictionary <string, string> i_params, Callback <Dictionary <string, string> > i_requestSuccessCallback) { StartRequest("Request for cloud call " + i_methodName); LogCloudCallParams(i_params); RunCloudScriptRequest request = new RunCloudScriptRequest() { ActionId = i_methodName, Params = new { data = i_params } }; PlayFabClientAPI.RunCloudScript(request, (result) => { RequestComplete("Cloud logs for " + i_methodName + "(" + result.ExecutionTime + ") call " + ": " + result.ActionLog, LogTypes.Info); Dictionary <string, string> resultsDeserialized = new Dictionary <string, string>(); if (result.Results != null) { string resultAsString = result.Results.ToString(); resultsDeserialized = JsonConvert.DeserializeObject <Dictionary <string, string> >(resultAsString); CheckForAndUpdateSyncState(resultsDeserialized); } if (i_requestSuccessCallback != null) { i_requestSuccessCallback(resultsDeserialized); } }, (error) => { HandleError(error, i_methodName); }); }
public void CloudScript() { var getUrlTask = PlayFabClientAPI.GetCloudScriptUrlAsync(new GetCloudScriptUrlRequest()); WaitForResultSuccess(getUrlTask, "Failed to get LogicServerURL"); var request = new RunCloudScriptRequest(); request.ActionId = "helloWorld"; var cloudTask = PlayFabClientAPI.RunCloudScriptAsync(request); WaitForResultSuccess(cloudTask, "Failed to Execute CloudScript"); UUnitAssert.False(string.IsNullOrEmpty(cloudTask.Result.Result.ResultsEncoded), "Failed to Execute CloudScript"); // Get the helloWorld return message JObject jobj = cloudTask.Result.Result.Results as JObject; UUnitAssert.NotNull(jobj); JToken jtok; jobj.TryGetValue("messageValue", out jtok); UUnitAssert.NotNull(jtok); JValue jval = jtok as JValue; UUnitAssert.NotNull(jval); string actualMessage = jval.Value as string; UUnitAssert.StringEquals("Hello " + playFabId + "!", actualMessage); }
private void CloudScript() { if (string.IsNullOrEmpty(PlayFabSettings.LogicServerUrl)) { PlayFabClientAPI.GetCloudScriptUrl(new GetCloudScriptUrlRequest(), CloudScriptUrlCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.True(lastReceivedMessage.StartsWith("CloudScript setup complete: "), lastReceivedMessage); } var request = new RunCloudScriptRequest(); request.ActionId = "helloWorld"; PlayFabClientAPI.RunCloudScript(request, CloudScriptHwCallback, SharedErrorCallback); WaitForApiCalls(); UUnitAssert.Equals("Hello " + playFabId + "!", lastReceivedMessage); }