private void OnLoginSuccessRetryBufferedCall() { // Credentials should already be updated since the login was successful // try original call again Debug.LogError("Login success: attempting buffered call"); string url = bufferedCall.URL; string request = bufferedCall.RequestBody; Action <string> successHandler = bufferedCall.SuccessHandler; Action <string> failureHandler = bufferedCall.FailureHandler; bufferedCall = null; StartCoroutine(_PerformRequest <string>(url, request, successHandler, failureHandler, false)); }
private IEnumerator _PerformRequest <T>(string url, string jsonData, Action <T> callback, Action <string> errorCallback, bool bufferCall = true) where T : class { if (connectionError) { if (null != errorCallback) { errorCallback(HelperMethods.Instance.Error_NetworkTimeOut); yield break; } } byte[] encodedJSON = null; if (!string.IsNullOrEmpty(jsonData)) { var encoding = new UTF8Encoding(); encodedJSON = encoding.GetBytes(jsonData); } // Save this call in case it fails due to session credentials if (bufferCall) { bufferedCall = new BufferedCall(url, jsonData, callback as Action <string>, errorCallback); } ITTNetworkRequest networkRequest = new ITTNetworkRequest(url, encodedJSON, PostHeader(), DateTime.Now); _activeRequests.Add(networkRequest); #if UNITY_IPHONE while (null != networkRequest.www && !networkRequest.www.isDone) { yield return(null); } #else yield return(networkRequest.www); #endif _WWWRequest(networkRequest.www, callback, errorCallback); }
private void OnRefreshTokenSuccess(string json) { try { HelperMethods.RefreshTokenResponseObject tokenObject = ClientSDK.Utils.Json.GetObjectFromJson <HelperMethods.RefreshTokenResponseObject>(json); Debug.LogError("RefreshToken: normal"); SessionManager.UpdateUserToken(tokenObject.token); if (null == bufferedCall) { return; } // Make original call again StartCoroutine(_PerformRequest <string>(bufferedCall.URL, bufferedCall.RequestBody, bufferedCall.SuccessHandler, bufferedCall.FailureHandler)); } catch (JsonFx.Json.JsonDeserializationException d) { global::System.Text.RegularExpressions.Match match = global::System.Text.RegularExpressions.Regex.Match(json, "[A-Za-z0-9-_]{43}"); Debug.LogError("RefreshToken: odd format: " + json + " " + d.Message); SessionManager.UpdateUserToken(match.ToString()); if (null == bufferedCall) { return; } // Make original call again string url = bufferedCall.URL; string request = bufferedCall.RequestBody; Action <string> successHandler = bufferedCall.SuccessHandler; Action <string> failureHandler = bufferedCall.FailureHandler; bufferedCall = null; StartCoroutine(_PerformRequest <string>(url, request, successHandler, failureHandler, false)); } catch (Exception e) { Debug.LogError("Token response parsing error: " + e.Message); } }