/// <summary> /// Requests an Engagement with Engage. The engagement is populated with the result of the request and /// returned in the onCompleted callback. The engagement's json field can be queried for the returned json. /// A cache is maintained that will return the last valid response if available. /// </summary> /// <param name="engagement">The engagement the request is for.</param> /// <param name="onCompleted">Method called with the Engagement populated by Engage.</param> /// <exception cref="System.Exception">Thrown if the SDK has not been started, and if the Engage URL has not been set.</exception> public void RequestEngagement(Engagement engagement, Action <Engagement> onCompleted, Action <Exception> onError) { if (!this.started) { throw new Exception("You must first start the SDK via the StartSDK method."); } if (String.IsNullOrEmpty(this.EngageURL)) { throw new Exception("Engage URL not configured."); } try { var dict = engagement.AsDictionary(); var request = new EngageRequest(dict["decisionPoint"] as string); request.Flavour = dict["flavour"] as string; request.Parameters = dict["parameters"] as Dictionary <string, object>; EngageResponse handler = (string response, int statusCode, string error) => { engagement.Raw = response; engagement.StatusCode = statusCode; engagement.Error = error; onCompleted(engagement); }; StartCoroutine(Engage.Request(this, request, handler)); } catch (Exception ex) { Logger.LogWarning("Engagement request failed: " + ex.Message); } }
internal void RequestEngagement(string request) { Action action = delegate() { JSONObject engagement = null; try { engagement = Json.Deserialize(request) as JSONObject; } catch (Exception exception) { Logger.LogError("Failed to deserialise engage request: " + exception.Message); } if (engagement != null) { var decisionPoint = engagement["decisionPoint"] as string; var flavour = engagement["flavour"] as string; var parameters = engagement["parameters"] as JSONObject; var id = engagement["id"] as string; EngageResponse engageResponse = (response, statusCode, error) => { manager.EngageResponse(id, response, statusCode, error); }; EngageRequest engageRequest = new EngageRequest(decisionPoint); engageRequest.Flavour = flavour; engageRequest.Parameters = parameters; StartCoroutine(Engage.Request(this, engageRequest, engageResponse)); } }; actions.Enqueue(action); }
override internal void ClearPersistentData() { if (eventStore != null) { eventStore.ClearAll(); } Engage.ClearCache(); }
override internal void RequestEngagement(Engagement engagement, Action <Dictionary <string, object> > callback) { if (!this.started) { throw new Exception("You must first start the SDK via the StartSDK method."); } else if (whitelistDps.Count != 0 && !whitelistDps.Contains(engagement.GetDecisionPointAndFlavour())) { Logger.LogDebug(string.Format( "Decision point {0} is not whitelisted", engagement.GetDecisionPointAndFlavour())); engagement.StatusCode = 200; engagement.Raw = "{}"; callback(engagement.JSON); return; } if (String.IsNullOrEmpty(this.EngageURL)) { throw new Exception("Engage URL not configured."); } try { var dict = engagement.AsDictionary(); var request = new EngageRequest(dict["decisionPoint"] as string); request.Flavour = dict["flavour"] as string; request.Parameters = dict["parameters"] as Dictionary <string, object>; EngageResponse handler = (string response, int statusCode, string error) => { JSONObject responseJSON = new JSONObject(); if (response != null) { try { responseJSON = DeltaDNA.MiniJSON.Json.Deserialize(response) as JSONObject; } catch (Exception exception) { Logger.LogError("Engagement " + engagement.DecisionPoint + " responded with invalid JSON: " + exception.Message); } } callback(responseJSON); }; StartCoroutine(Engage.Request(ddna, engageCache, request, handler)); } catch (Exception ex) { Logger.LogWarning("Engagement request failed: " + ex.Message); } }
/// <summary> /// Clears the persistent data, such as user id. The SDK should be stopped /// before this method is called. /// /// Useful for testing purposes. /// </summary> public void ClearPersistentData() { if (HasStarted) { Logger.LogWarning("SDK has not been stopped before clearing persistent data"); } PlayerPrefs.DeleteKey(PF_KEY_USER_ID); if (this.eventStore != null) { this.eventStore.ClearAll(); } Engage.ClearCache(); }
override internal void RequestEngagement(Engagement engagement, Action <Engagement> onCompleted, Action <Exception> onError) { if (!this.started) { throw new Exception("You must first start the SDK via the StartSDK method."); } else if (whitelistDps.Count != 0 && !whitelistDps.Contains(engagement.GetDecisionPointAndFlavour())) { Logger.LogDebug(string.Format( "Decision point {0} is not whitelisted", engagement.GetDecisionPointAndFlavour())); engagement.StatusCode = 200; engagement.Raw = "{}"; onCompleted(engagement); return; } if (String.IsNullOrEmpty(this.EngageURL)) { throw new Exception("Engage URL not configured."); } try { var dict = engagement.AsDictionary(); var request = new EngageRequest(dict["decisionPoint"] as string); request.Flavour = dict["flavour"] as string; request.Parameters = dict["parameters"] as Dictionary <string, object>; EngageResponse handler = (string response, int statusCode, string error) => { engagement.Raw = response; engagement.StatusCode = statusCode; engagement.Error = error; onCompleted(engagement); }; StartCoroutine(Engage.Request(ddna, engageCache, request, handler)); } catch (Exception ex) { Logger.LogWarning("Engagement request failed: " + ex.Message); } }
/// <summary> /// Makes an Engage request. The result of the engagement will be passed as a dictionary object to your callback method. The dictionary /// will be empty if engage couldn't be reached on a campaign is not running. /// A cache is maintained that will return the last valid response if available. /// </summary> /// <param name="engagement">The engagement the request is for.</param> /// <param name="callback">Method called with the response from Engage.</param> /// <exception cref="System.Exception">Thrown if the SDK has not been started, and if the Engage URL has not been set.</exception> public void RequestEngagement(Engagement engagement, Action <Dictionary <string, object> > callback) { if (!this.started) { throw new Exception("You must first start the SDK via the StartSDK method."); } if (String.IsNullOrEmpty(this.EngageURL)) { throw new Exception("Engage URL not configured."); } try { var dict = engagement.AsDictionary(); var request = new EngageRequest(dict["decisionPoint"] as string); request.Flavour = dict["flavour"] as string; request.Parameters = dict["parameters"] as Dictionary <string, object>; EngageResponse handler = (string response, int statusCode, string error) => { JSONObject responseJSON = new JSONObject(); if (response != null) { try { responseJSON = DeltaDNA.MiniJSON.Json.Deserialize(response) as JSONObject; } catch (Exception exception) { Logger.LogError("Engagement " + engagement.DecisionPoint + " responded with invalid JSON: " + exception.Message); } } callback(responseJSON); }; StartCoroutine(Engage.Request(this, request, handler)); } catch (Exception ex) { Logger.LogWarning("Engagement request failed: " + ex.Message); } }