internal static IEnumerator Request( MonoBehaviour caller, EngageCache cache, EngageRequest request, EngageResponse response, bool useConfigurationTimeout = false) { string requestJSON = request.ToJSON(); string url = DDNA.Instance.ResolveEngageURL(requestJSON); HttpRequest httpRequest = new HttpRequest(url); httpRequest.HTTPMethod = HttpRequest.HTTPMethodType.POST; httpRequest.HTTPBody = requestJSON; httpRequest.TimeoutSeconds = useConfigurationTimeout ? DDNA.Instance.Settings.HttpRequestConfigurationTimeoutSeconds : DDNA.Instance.Settings.HttpRequestEngageTimeoutSeconds; httpRequest.setHeader("Content-Type", "application/json"); Action <int, string, string> httpHandler = (statusCode, data, error) => { if (error == null && statusCode >= 200 && statusCode < 300) { cache.Put(request.DecisionPoint, request.Flavour, data); } else { Logger.LogDebug("Engagement failed with " + statusCode + " " + error); var isClientError = statusCode >= 400 && statusCode < 500; var cached = cache.Get(request.DecisionPoint, request.Flavour); if (cached != null && !isClientError) { Logger.LogDebug("Using cached response"); data = "{\"isCachedResponse\":true," + cached.Substring(1); } else { data = "{}"; } } response(data, statusCode, error); }; yield return(caller.StartCoroutine(Network.SendRequest(httpRequest, httpHandler))); }
public void InsertsAndRetrievesEngagement() { uut.Put("dp", "flavour", "data"); Expect(uut.Get("dp", "flavour"), Is.EqualTo("data")); }