Ejemplo n.º 1
0
        private static void FetchClientToken(WitConfiguration configuration, Action action)
        {
            if (!string.IsNullOrEmpty(configuration.application?.id))
            {
                var tokenRequest = configuration.GetClientToken(configuration.application.id);
                tokenRequest.onResponse = (r) =>
                {
                    if (r.StatusCode == 200)
                    {
                        var token = r.ResponseData["client_token"];

                        EditorForegroundRunner.Run(() =>
                        {
                            SerializedObject so = new SerializedObject(configuration);
                            so.FindProperty("clientAccessToken").stringValue =
                                r.ResponseData["client_token"];
                            so.ApplyModifiedProperties();

                            configuration.clientAccessToken = token;
                            EditorUtility.SetDirty(configuration);
                            action?.Invoke();
                        });
                    }
                    else
                    {
                        Debug.LogError(r.StatusDescription);
                    }
                };
                tokenRequest.Request();
            }
        }
Ejemplo n.º 2
0
        // Refresh client data
        private static void SetClientData(WitConfiguration configuration, string serverToken, Action <string> onSetComplete)
        {
            // Invalid app ID
            string appID = GetAppID(configuration);

            if (string.IsNullOrEmpty(appID))
            {
                SetConfigServerTokenComplete(configuration, serverToken, "Invalid App ID", onSetComplete);
                return;
            }
            // Set server token
            WitAuthUtility.SetAppServerToken(appID, serverToken);
            // Clear client token
            ApplyClientToken(configuration, string.Empty, null);
            // Find client id
            PerformConfigRequest(configuration, configuration.GetClientToken(appID), ApplyClientToken, (error) =>
            {
                SetConfigServerTokenComplete(configuration, serverToken, error, onSetComplete);
            });
        }