src/ApprienUnitySDK/Assets/Apprien/Editor/ApprienConnectionTester.cs
/// <summary>
/// Validates the supplied access token with the Apprien API
/// </summary>
/// <returns>Returns an IEnumerator that can be forwarded manually or passed to StartCoroutine</returns>
Validates the supplied access token with the Apprien API
Validates the supplied access token with the Apprien API
public IEnumerator<bool?> CheckTokenValidity()
        {
            var requestSendTimestamp = DateTime.Now;
            var url = string.Format(REST_GET_VALIDATE_TOKEN_URL, ApprienUtility.GetIntegrationUri(ApprienIntegrationType.GooglePlayStore), Application.identifier);
            using(var request = UnityWebRequest.Get(url))
            {
                request.SetRequestHeader("Authorization", "Bearer " + _apprienManager.Token);
                ApprienUtility.SendWebRequest(request);
                while (!request.isDone)
                {
                    if ((DateTime.Now - requestSendTimestamp).TotalSeconds > _apprienManager.RequestTimeout)
                    {
                        Debug.LogError("Token check: Request Timeout");
                        yield return false;
                        yield break;
                    }
                    yield return null;
                }
                if (ApprienUtility.IsHttpError(request))
                {
                    yield return false;
                    yield break;
                }
                else if (ApprienUtility.IsNetworkError(request))
                {
                    yield return false;
                    yield break;
                }
                yield return true;
            }
        }
public IEnumerator < bool ? > CheckTokenValidity ( ) { var requestSendTimestamp = DateTime . Now ; var url = string . Format ( REST_GET_VALIDATE_TOKEN_URL , ApprienUtility . GetIntegrationUri ( ApprienIntegrationType . GooglePlayStore ) , Application . identifier ) ; using ( var request = UnityWebRequest . Get ( url ) ) { request . SetRequestHeader ( " " , " " + _apprienManager . Token ) ; ApprienUtility . SendWebRequest ( request ) ; while ( ! request . isDone ) { if ( ( DateTime . Now - requestSendTimestamp ) . TotalSeconds > _apprienManager . RequestTimeout ) { Debug . LogError ( " " ) ; yield return false ; yield break ; } yield return null ; } if ( ApprienUtility . IsHttpError ( request ) ) { yield return false ; yield break ; } else if ( ApprienUtility . IsNetworkError ( request ) ) { yield return false ; yield break ; } yield return true ; } }
Validates the supplied access token with the Apprien API
Validates the supplied access token with the Apprien API
// Timeout the request and return false // Specify that the request is still in progress // If there was an error sending the request, or the server returns an error code > 400 //Debug.LogError("Token check: HTTP Error " + request.responseCode); //Debug.LogError("Token check: Network Error " + request.responseCode); // The token is valid
Returns an IEnumerator that can be forwarded manually or passed to StartCoroutine
Returns an IEnumerator that can be forwarded manually or passed to StartCoroutine