public async override Task <ICollection <Campaign> > GetCampaigns(VisitorDelegateAbstract visitor) { try { var url = $"{Constants.BASE_API_URL}{Config.EnvId}/campaigns?exposeAllKeys=true"; if (!visitor.HasConsented) { url += $"&{Constants.SEND_CONTEXT_EVENT}=false"; } var requestMessage = new HttpRequestMessage(HttpMethod.Post, url); requestMessage.Headers.Add(Constants.HEADER_X_API_KEY, Config.ApiKey); requestMessage.Headers.Add(Constants.HEADER_X_SDK_CLIENT, Constants.SDK_LANGUAGE); requestMessage.Headers.Add(Constants.HEADER_X_SDK_VERSION, Constants.SDK_VERSION); requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(Constants.HEADER_APPLICATION_JSON)); var postData = new Dictionary <string, object> { ["visitorId"] = visitor.VisitorId, ["anonymousId"] = visitor.AnonymousId, ["trigger_hit"] = false, ["context"] = visitor.Context }; var postDatajson = JsonConvert.SerializeObject(postData); var stringContent = new StringContent(postDatajson, Encoding.UTF8, "application/json"); requestMessage.Content = stringContent; var response = await HttpClient.SendAsync(requestMessage); if (response.StatusCode != System.Net.HttpStatusCode.OK) { throw new Exception(response.ReasonPhrase); } string responseBody = await response.Content.ReadAsStringAsync(); var decisionResponse = JsonConvert.DeserializeObject <DecisionResponse>(responseBody); IsPanic = decisionResponse.Panic; return(decisionResponse.Campaigns); } catch (Exception ex) { Log.LogError(Config, ex.Message, "GetCampaigns"); return(new Collection <Campaign>()); } }
public async Task SendActive(VisitorDelegateAbstract visitor, FlagDTO flag) { var url = $"{Constants.BASE_API_URL}activate"; var requestMessage = new HttpRequestMessage(HttpMethod.Post, url); requestMessage.Headers.Add(Constants.HEADER_X_API_KEY, Config.ApiKey); requestMessage.Headers.Add(Constants.HEADER_X_SDK_CLIENT, Constants.SDK_LANGUAGE); requestMessage.Headers.Add(Constants.HEADER_X_SDK_VERSION, Constants.SDK_VERSION); requestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(Constants.HEADER_APPLICATION_JSON)); var postData = new Dictionary <string, object> { [Constants.VISITOR_ID_API_ITEM] = visitor.VisitorId, [Constants.VARIATION_ID_API_ITEM] = flag.VariationId, [Constants.VARIATION_GROUP_ID_API_ITEM] = flag.VariationGroupId, [Constants.CUSTOMER_ENV_ID_API_ITEM] = Config.EnvId }; if (!string.IsNullOrWhiteSpace(visitor.AnonymousId) && !string.IsNullOrWhiteSpace(visitor.VisitorId)) { postData[Constants.VISITOR_ID_API_ITEM] = visitor.VisitorId; postData[Constants.ANONYMOUS_ID] = visitor.AnonymousId; } else { postData[Constants.VISITOR_ID_API_ITEM] = visitor.AnonymousId ?? visitor.VisitorId; postData[Constants.ANONYMOUS_ID] = null; } var postDatajson = JsonConvert.SerializeObject(postData); var stringContent = new StringContent(postDatajson, Encoding.UTF8, Constants.HEADER_APPLICATION_JSON); requestMessage.Content = stringContent; await HttpClient.SendAsync(requestMessage); }
internal Flag(string key, VisitorDelegateAbstract visitorDelegate, object DefaultValue) { _key = key; _visitorDelegateAbstract = visitorDelegate; _defaultValue = DefaultValue; }