using System; using System.Threading.Tasks; using Newtonsoft.Json; using Plugins.Countly.Helpers; using Plugins.Countly.Models; using UnityEngine; namespace Plugins.Countly.Services.Impls.Actual { public class InitializationCountlyService : IInitializationCountlyService { private readonly SessionCountlyService _sessionCountlyService; public InitializationCountlyService(SessionCountlyService sessionCountlyService) { _sessionCountlyService = sessionCountlyService; } public string ServerUrl { get; private set; } public string AppKey { get; private set; } /// /// Initializes countly instance /// /// /// /// public void Begin(string serverUrl, string appKey) { ServerUrl = serverUrl; AppKey = appKey; if (string.IsNullOrEmpty(ServerUrl)) throw new ArgumentNullException(serverUrl, "Server URL is required."); if (string.IsNullOrEmpty(AppKey)) throw new ArgumentNullException(appKey, "App Key is required."); //ConsentGranted = consentGranted; } /// /// Initializes the Countly SDK with default values /// /// /// /// /// /// public async Task SetDefaults(CountlyConfigModel configModel) { if (!configModel.EnableManualSessionHandling) { //Start Session and enable push notification var result = await _sessionCountlyService.BeginSessionAsync(); if (!result.IsSuccess) Debug.LogError("BeginSessionAsync error: " + result); else Debug.Log($"BeginSessionAsync Success {result}"); } return new CountlyResponse { IsSuccess = true }; } /// /// Gets the base url to make requests to the Countly server. /// /// public string GetBaseUrl() { return string.Format(ServerUrl[ServerUrl.Length - 1] == '/' ? "{0}i?" : "{0}/i?", ServerUrl); } } }