public void TalkSession(Dictionary <int, string> campaignsDownloaded) { try { if (CanMakeSessionRequest()) { lastSessionRequestTime = SwrveHelper.GetMilliseconds(); string endpoint = getEndpoint("talk/game/" + swrve.ApiKey + "/user/" + swrve.UserId + "/session"); Dictionary <string, object> dictionary = new Dictionary <string, object>(); IList <object> list = new List <object>(); Dictionary <int, string> .Enumerator enumerator = campaignsDownloaded.GetEnumerator(); while (enumerator.MoveNext()) { int key = enumerator.Current.Key; string value = enumerator.Current.Value; Dictionary <string, object> dictionary2 = new Dictionary <string, object>(); dictionary2.Add("id", key); dictionary2.Add("reason", (value == null) ? string.Empty : value); dictionary2.Add("loaded", value == null); list.Add(dictionary2); } dictionary.Add("campaigns", list); Dictionary <string, string> deviceInfo = swrve.GetDeviceInfo(); dictionary.Add("device", deviceInfo); MakeRequest(endpoint, dictionary); } } catch (Exception ex) { SwrveLog.LogError("QA request talk session failed: " + ex.ToString()); } }
public void TalkSession(Dictionary <int, string> campaignsDownloaded) { try { if (CanMakeSessionRequest()) { lastSessionRequestTime = SwrveHelper.GetMilliseconds(); String endpoint = getEndpoint("talk/game/" + swrve.ApiKey + "/user/" + swrve.UserId + "/session"); Dictionary <string, object> talkSessionJson = new Dictionary <string, object> (); // Add campaigns (downloaded or not) to request IList <object> campaignsJson = new List <object> (); Dictionary <int, string> .Enumerator campaignIt = campaignsDownloaded.GetEnumerator(); while (campaignIt.MoveNext()) { int id = campaignIt.Current.Key; string reason = campaignIt.Current.Value; Dictionary <string, object> campaignInfo = new Dictionary <string, object> (); campaignInfo.Add("id", id); campaignInfo.Add("reason", (reason == null) ? string.Empty : reason); campaignInfo.Add("loaded", (reason == null)); campaignsJson.Add(campaignInfo); } talkSessionJson.Add("campaigns", campaignsJson); // Add device info to request Dictionary <string, string> deviceJson = swrve.GetDeviceInfo(); talkSessionJson.Add("device", deviceJson); MakeRequest(endpoint, talkSessionJson); } } catch (Exception exp) { SwrveLog.LogError("QA request talk session failed: " + exp.ToString()); } }
public void PushNotification(RemoteNotification notification) #endif { try { String endpoint = getEndpoint("talk/game/" + swrve.ApiKey + "/user/" + swrve.UserId + "/push"); if (CanMakePushNotificationRequest()) { lastPushNotificationRequestTime = SwrveHelper.GetMilliseconds(); Dictionary <string, object> pushJson = new Dictionary <string, object>(); pushJson.Add("alert", notification.alertBody); pushJson.Add("sound", notification.soundName); pushJson.Add("badge", notification.applicationIconBadgeNumber); if (notification.userInfo != null && notification.userInfo.Contains(PushTrackingKey)) { string pushId = notification.userInfo[PushTrackingKey].ToString(); pushJson.Add("id", pushId); } MakeRequest(endpoint, pushJson); } } catch (Exception exp) { SwrveLog.LogError("QA request talk session failed: " + exp.ToString()); } }
private bool CanMakeTimedRequest(long lastTime, long intervalTime) { if (CanMakeRequest() && (lastTime == 0 || SwrveHelper.GetMilliseconds() - lastTime > 1000)) { return(true); } return(false); }
public void Trigger(string eventName, SwrveBaseMessage baseMessage) { try { if (CanMakeTriggerRequest()) { lastTriggerRequestTime = SwrveHelper.GetMilliseconds(); Dictionary <int, string> _reasons = campaignReasons; Dictionary <int, SwrveBaseMessage> _messages = campaignMessages; campaignReasons = new Dictionary <int, string>(); campaignMessages = new Dictionary <int, SwrveBaseMessage>(); String endpoint = getEndpoint("talk/game/" + swrve.ApiKey + "/user/" + swrve.UserId + "/trigger"); Dictionary <string, object> triggerJson = new Dictionary <string, object> (); triggerJson.Add("trigger_name", eventName); triggerJson.Add("displayed", baseMessage != null); triggerJson.Add("reason", baseMessage == null ? "The loaded campaigns returned no conversation or message" : string.Empty); // Add campaigns that were not displayed IList <object> campaignsJson = new List <object> (); Dictionary <int, string> .Enumerator campaignIt = _reasons.GetEnumerator(); while (campaignIt.MoveNext()) { int campaignId = campaignIt.Current.Key; String reason = campaignIt.Current.Value; Dictionary <string, object> campaignInfo = new Dictionary <string, object> (); campaignInfo.Add("id", campaignId); campaignInfo.Add("displayed", false); campaignInfo.Add("reason", (reason == null) ? string.Empty : reason); if (_messages.ContainsKey(campaignId)) { SwrveBaseMessage _baseMessage = _messages [campaignId]; campaignInfo.Add(_baseMessage.GetBaseMessageType() + "_id", _baseMessage.Id); } campaignsJson.Add(campaignInfo); } // Add campaign that was shown, if available if (baseMessage != null) { Dictionary <string, object> campaignInfo = new Dictionary <string, object> (); campaignInfo.Add("id", baseMessage.Campaign.Id); campaignInfo.Add("displayed", true); campaignInfo.Add(baseMessage.GetBaseMessageType() + "_id", baseMessage.Id); campaignInfo.Add("reason", string.Empty); campaignsJson.Add(campaignInfo); } triggerJson.Add("campaigns", campaignsJson); MakeRequest(endpoint, triggerJson); } } catch (Exception exp) { SwrveLog.LogError("QA request talk session failed: " + exp.ToString()); } }
private bool CanMakeTimedRequest(long lastTime, long intervalTime) { if (CanMakeRequest()) { if (lastTime == 0 || (SwrveHelper.GetMilliseconds() - lastTime) > SessionInterval) { return(true); } } return(false); }
public void Trigger(string eventName, SwrveBaseMessage baseMessage) { try { if (!CanMakeTriggerRequest()) { return; } lastTriggerRequestTime = SwrveHelper.GetMilliseconds(); Dictionary <int, string> dictionary = campaignReasons; Dictionary <int, SwrveBaseMessage> dictionary2 = campaignMessages; campaignReasons = new Dictionary <int, string>(); campaignMessages = new Dictionary <int, SwrveBaseMessage>(); string endpoint = getEndpoint("talk/game/" + swrve.ApiKey + "/user/" + swrve.UserId + "/trigger"); Dictionary <string, object> dictionary3 = new Dictionary <string, object>(); dictionary3.Add("trigger_name", eventName); dictionary3.Add("displayed", baseMessage != null); dictionary3.Add("reason", (baseMessage == null) ? "The loaded campaigns returned no conversation or message" : string.Empty); IList <object> list = new List <object>(); Dictionary <int, string> .Enumerator enumerator = dictionary.GetEnumerator(); while (enumerator.MoveNext()) { int key = enumerator.Current.Key; string value = enumerator.Current.Value; Dictionary <string, object> dictionary4 = new Dictionary <string, object>(); dictionary4.Add("id", key); dictionary4.Add("displayed", false); dictionary4.Add("reason", (value == null) ? string.Empty : value); if (dictionary2.ContainsKey(key)) { SwrveBaseMessage swrveBaseMessage = dictionary2[key]; dictionary4.Add(swrveBaseMessage.GetBaseMessageType() + "_id", swrveBaseMessage.Id); } list.Add(dictionary4); } if (baseMessage != null) { Dictionary <string, object> dictionary4 = new Dictionary <string, object>(); dictionary4.Add("id", baseMessage.Campaign.Id); dictionary4.Add("displayed", true); dictionary4.Add(baseMessage.GetBaseMessageType() + "_id", baseMessage.Id); dictionary4.Add("reason", string.Empty); list.Add(dictionary4); } dictionary3.Add("campaigns", list); MakeRequest(endpoint, dictionary3); } catch (Exception ex) { SwrveLog.LogError("QA request talk session failed: " + ex.ToString()); } }
public void TalkSession(Dictionary <int, string> campaignsDownloaded) { try { if (this.CanMakeSessionRequest()) { this.lastSessionRequestTime = SwrveHelper.GetMilliseconds(); string endpoint = this.getEndpoint(string.Concat(new string[] { "talk/game/", this.swrve.ApiKey, "/user/", this.swrve.UserId, "/session" })); Dictionary <string, object> dictionary = new Dictionary <string, object>(); IList <object> list = new List <object>(); Dictionary <int, string> .Enumerator enumerator = campaignsDownloaded.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair <int, string> current = enumerator.Current; int key = current.Key; KeyValuePair <int, string> current2 = enumerator.Current; string value = current2.Value; list.Add(new Dictionary <string, object> { { "id", key }, { "reason", (value != null) ? value : string.Empty }, { "loaded", value == null } }); } dictionary.Add("campaigns", list); Dictionary <string, string> deviceInfo = this.swrve.GetDeviceInfo(); dictionary.Add("device", deviceInfo); this.MakeRequest(endpoint, dictionary); } } catch (Exception ex) { SwrveLog.LogError("QA request talk session failed: " + ex.ToString()); } }
public virtual IEnumerator Post(string url, byte[] encodedData, Dictionary <string, string> headers, Action <RESTResponse> listener) { if (!Application.isEditor) { headers = AddMetricsHeader(headers); } long start = SwrveHelper.GetMilliseconds(); using (var www = CrossPlatformUtils.MakeWWW(url, encodedData, headers)) { yield return(www); long wwwTime = SwrveHelper.GetMilliseconds() - start; ProcessResponse(www, wwwTime, url, listener); } }
public virtual IEnumerator Get(string url, Action <RESTResponse> listener) { var headers = new Dictionary <string, string> (); if (!Application.isEditor) { headers = AddMetricsHeader(headers); } long start = SwrveHelper.GetMilliseconds(); using (var www = CrossPlatformUtils.MakeRequest(url, UnityWebRequest.kHttpVerbGET, null, headers)) { yield return(www.SendWebRequest()); long wwwTime = SwrveHelper.GetMilliseconds() - start; ProcessResponse(www, wwwTime, url, listener); } }
public virtual IEnumerator Get(string url, Action <RESTResponse> listener) { var headers = new Dictionary <string, string> (); if (!Application.isEditor) { headers = AddMetricsHeader(headers); #if SUPPORTS_GZIP_RESPONSES headers.Add("Accept-Encoding", "gzip"); #endif } long start = SwrveHelper.GetMilliseconds(); using (var www = CrossPlatformUtils.MakeWWW(url, null, headers)) { yield return(www); long wwwTime = SwrveHelper.GetMilliseconds() - start; ProcessResponse(www, wwwTime, url, listener); } }
protected virtual long GetTime() { return(SwrveHelper.GetMilliseconds()); }
private bool CanMakeTimedRequest(long lastTime, long intervalTime) { return(this.CanMakeRequest() && (lastTime == 0L || SwrveHelper.GetMilliseconds() - lastTime > 1000L)); }
public void Trigger(string eventName, SwrveBaseMessage baseMessage) { try { if (this.CanMakeTriggerRequest()) { this.lastTriggerRequestTime = SwrveHelper.GetMilliseconds(); Dictionary <int, string> dictionary = this.campaignReasons; Dictionary <int, SwrveBaseMessage> dictionary2 = this.campaignMessages; this.campaignReasons = new Dictionary <int, string>(); this.campaignMessages = new Dictionary <int, SwrveBaseMessage>(); string endpoint = this.getEndpoint(string.Concat(new string[] { "talk/game/", this.swrve.ApiKey, "/user/", this.swrve.UserId, "/trigger" })); Dictionary <string, object> dictionary3 = new Dictionary <string, object>(); dictionary3.Add("trigger_name", eventName); dictionary3.Add("displayed", baseMessage != null); dictionary3.Add("reason", (baseMessage != null) ? string.Empty : "The loaded campaigns returned no conversation or message"); IList <object> list = new List <object>(); Dictionary <int, string> .Enumerator enumerator = dictionary.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair <int, string> current = enumerator.Current; int key = current.Key; KeyValuePair <int, string> current2 = enumerator.Current; string value = current2.Value; Dictionary <string, object> dictionary4 = new Dictionary <string, object>(); dictionary4.Add("id", key); dictionary4.Add("displayed", false); dictionary4.Add("reason", (value != null) ? value : string.Empty); if (dictionary2.ContainsKey(key)) { SwrveBaseMessage swrveBaseMessage = dictionary2[key]; dictionary4.Add(swrveBaseMessage.GetBaseMessageType() + "_id", swrveBaseMessage.Id); } list.Add(dictionary4); } if (baseMessage != null) { list.Add(new Dictionary <string, object> { { "id", baseMessage.Campaign.Id }, { "displayed", true }, { baseMessage.GetBaseMessageType() + "_id", baseMessage.Id }, { "reason", string.Empty } }); } dictionary3.Add("campaigns", list); this.MakeRequest(endpoint, dictionary3); } } catch (Exception ex) { SwrveLog.LogError("QA request talk session failed: " + ex.ToString()); } }
private void MakeRequest(string qaEventsStringJson) { if (qaEventsStringJson == null) { return; } byte[] qaPostEncodedData = null; qaPostEncodedData = PostBodyBuilder.BuildQaEvent(apiKey, appId, userId, this.deviceUUID, appVersion, SwrveHelper.GetMilliseconds(), qaEventsStringJson); Dictionary <string, string> requestHeaders = new Dictionary <string, string> { { @"Content-Type", @"application/json; charset=utf-8" } }; if (qaPostEncodedData != null) { container.StartCoroutine(restClient.Post(endPoint, qaPostEncodedData, requestHeaders, RestListener)); SwrveLog.LogInfo("Swrve: SwrveQa Json Event sent:" + qaEventsStringJson); } }