private IEnumerator PostEvents(string[] events, Action <bool, int> resultCallback) { string bulkEvent = "{\"eventList\":[" + String.Join(",", events) + "]}"; string url; if (HashSecret != null) { string md5Hash = DDNA.GenerateHash(bulkEvent, this.HashSecret); url = DDNA.FormatURI(Settings.COLLECT_HASH_URL_PATTERN, this.CollectURL, this.EnvironmentKey, md5Hash); } else { url = DDNA.FormatURI(Settings.COLLECT_URL_PATTERN, this.CollectURL, this.EnvironmentKey, null); } int attempts = 0; bool succeeded = false; int status = 0; Action <int, string, string> completionHandler = (statusCode, data, error) => { if (statusCode > 0 && statusCode < 400) { succeeded = true; } else { Logger.LogDebug("Error posting events: " + error + " " + data); } status = statusCode; }; HttpRequest request = new HttpRequest(url); request.HTTPMethod = HttpRequest.HTTPMethodType.POST; request.HTTPBody = bulkEvent; request.setHeader("Content-Type", "application/json"); do { yield return(StartCoroutine(Network.SendRequest(request, completionHandler))); if (succeeded || ++attempts < Settings.HttpRequestMaxRetries) { break; } yield return(new WaitForSeconds(Settings.HttpRequestRetryDelaySeconds)); } while (attempts < Settings.HttpRequestMaxRetries); resultCallback(succeeded, status); }
internal override void ForgetMe() { if (PlayerPrefs.HasKey(DDNA.PF_KEY_FORGOTTEN)) { Logger.LogDebug("Already forgotten user " + UserID); return; } Logger.LogDebug("Forgetting user " + UserID); PlayerPrefs.SetInt(DDNA.PF_KEY_FORGET_ME, 1); if (IsUploading) { return; } string gameEvent; try { gameEvent = MiniJSON.Json.Serialize( new GameEvent("ddnaForgetMe") .AddParam("eventTimestamp", GetCurrentTimestamp()) .AddParam("eventUUID", Guid.NewGuid().ToString()) .AddParam("sessionID", SessionID) .AddParam("userID", UserID) .AddParam("eventParams", new Params() .AddParam("platform", Platform) .AddParam("sdkVersion", Settings.SDK_VERSION)) .AddParam("ddnaAdvertisingId", PlayerPrefs.GetString(DDNA.PF_KEY_ADVERTISING_ID)) .AsDictionary()); } catch (Exception e) { Logger.LogWarning("Unable to generate JSON for 'ddnaForgetMe' event. " + e.Message); return; } var url = (HashSecret != null) ? DDNA.FormatURI( Settings.COLLECT_HASH_URL_PATTERN, CollectURL, EnvironmentKey, DDNA.GenerateHash(gameEvent, HashSecret)) : DDNA.FormatURI( Settings.COLLECT_URL_PATTERN, CollectURL, EnvironmentKey, null); HttpRequest request = new HttpRequest(url) { HTTPMethod = HttpRequest.HTTPMethodType.POST, HTTPBody = gameEvent }; request.setHeader("Content-Type", "application/json"); StartCoroutine(Send( request, () => { Logger.LogDebug("Forgot user " + UserID); PlayerPrefs.SetInt(DDNA.PF_KEY_FORGOTTEN, 1); })); }
internal override void ForgetMe() { if (PlayerPrefs.HasKey(DDNA.PF_KEY_FORGOTTEN)) { Logger.LogDebug("Already forgotten user " + UserID); return; } Logger.LogDebug("Forgetting user " + UserID); PlayerPrefs.SetInt(DDNA.PF_KEY_FORGET_ME, 1); if (IsUploading) { return; } var advertisingId = PlayerPrefs.GetString(DDNA.PF_KEY_ADVERTISING_ID); var dictionary = new Dictionary <string, object>() { { "eventName", "ddnaForgetMe" }, { "eventTimestamp", GetCurrentTimestamp() }, { "eventUUID", Guid.NewGuid().ToString() }, { "sessionID", SessionID }, { "userID", UserID }, { "eventParams", new Dictionary <string, object>() { { "platform", Platform }, { "sdkVersion", Settings.SDK_VERSION }, { "ddnaAdvertisingId", advertisingId } } } }; if (string.IsNullOrEmpty(advertisingId)) { (dictionary["eventParams"] as Dictionary <string, object>) .Remove("ddnaAdvertisingId"); } string json; try { json = MiniJSON.Json.Serialize(dictionary); } catch (Exception e) { Logger.LogWarning("Unable to generate JSON for 'ddnaForgetMe' event. " + e.Message); return; } var url = (HashSecret != null) ? DDNA.FormatURI( Settings.COLLECT_HASH_URL_PATTERN.Replace("/bulk", ""), CollectURL, EnvironmentKey, DDNA.GenerateHash(json, HashSecret)) : DDNA.FormatURI( Settings.COLLECT_URL_PATTERN.Replace("/bulk", ""), CollectURL, EnvironmentKey, null); HttpRequest request = new HttpRequest(url) { HTTPMethod = HttpRequest.HTTPMethodType.POST, HTTPBody = json }; request.setHeader("Content-Type", "application/json"); StartCoroutine(Send( request, () => { Logger.LogDebug("Forgot user " + UserID); PlayerPrefs.SetInt(DDNA.PF_KEY_FORGOTTEN, 1); })); }