using System.Threading.Tasks; using System.Net.Http; using Oqtane.Documentation; using Oqtane.Shared; namespace Oqtane.Services { /// /// Service to retrieve cookie consent information. /// public interface ICookieConsentService { /// /// Get cookie consent bar actioned status /// /// Task IsActionedAsync(); /// /// Get cookie consent status /// /// Task CanTrackAsync(bool optOut); /// /// create actioned cookie /// /// Task CreateActionedCookieAsync(); /// /// create consent cookie /// /// Task CreateConsentCookieAsync(); /// /// widhdraw consent cookie /// /// Task WithdrawConsentCookieAsync(); } /// [PrivateApi("Don't show in the documentation, as everything should use the Interface")] public class CookieConsentService : ServiceBase, ICookieConsentService { public CookieConsentService(HttpClient http, SiteState siteState) : base(http, siteState) { } private string ApiUrl => CreateApiUrl("CookieConsent"); public async Task IsActionedAsync() { return await GetJsonAsync($"{ApiUrl}/IsActioned"); } public async Task CanTrackAsync(bool optOut) { return await GetJsonAsync($"{ApiUrl}/CanTrack?optout=" + optOut); } public async Task CreateActionedCookieAsync() { var cookie = await GetStringAsync($"{ApiUrl}/CreateActionedCookie"); return cookie ?? string.Empty; } public async Task CreateConsentCookieAsync() { var cookie = await GetStringAsync($"{ApiUrl}/CreateConsentCookie"); return cookie ?? string.Empty; } public async Task WithdrawConsentCookieAsync() { var cookie = await GetStringAsync($"{ApiUrl}/WithdrawConsentCookie"); return cookie ?? string.Empty; } } }