#if !DISABLE_PLAYFABENTITY_API using System; using System.Collections.Generic; using PlayFab.InsightsModels; using PlayFab.Internal; using PlayFab.SharedModels; namespace PlayFab { /// /// Manage the Insights performance level and data storage retention settings. /// public class PlayFabInsightsInstanceAPI : IPlayFabInstanceApi { public readonly PlayFabApiSettings apiSettings = null; public readonly PlayFabAuthenticationContext authenticationContext = null; public PlayFabInsightsInstanceAPI(PlayFabAuthenticationContext context) { if (context == null) throw new PlayFabException(PlayFabExceptionCode.AuthContextRequired, "Context cannot be null, create a PlayFabAuthenticationContext for each player in advance, or call .GetAuthenticationContext()"); authenticationContext = context; } public PlayFabInsightsInstanceAPI(PlayFabApiSettings settings, PlayFabAuthenticationContext context) { if (context == null) throw new PlayFabException(PlayFabExceptionCode.AuthContextRequired, "Context cannot be null, create a PlayFabAuthenticationContext for each player in advance, or call .GetAuthenticationContext()"); apiSettings = settings; authenticationContext = context; } /// /// Verify entity login. /// public bool IsEntityLoggedIn() { return authenticationContext == null ? false : authenticationContext.IsEntityLoggedIn(); } /// /// Clear the Client SessionToken which allows this Client to call API calls requiring login. /// A new/fresh login will be required after calling this. /// public void ForgetAllCredentials() { if (authenticationContext != null) { authenticationContext.ForgetAllCredentials(); } } /// /// Gets the current values for the Insights performance and data storage retention, list of pending operations, and the /// performance and data storage retention limits. /// public void GetDetails(InsightsEmptyRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? authenticationContext; var callSettings = apiSettings ?? PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Insights/GetDetails", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); } /// /// Retrieves the range of allowed values for performance and data storage retention values as well as the submeter details /// for each performance level. /// public void GetLimits(InsightsEmptyRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? authenticationContext; var callSettings = apiSettings ?? PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Insights/GetLimits", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); } /// /// Gets the status of a SetPerformance or SetStorageRetention operation. /// public void GetOperationStatus(InsightsGetOperationStatusRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? authenticationContext; var callSettings = apiSettings ?? PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Insights/GetOperationStatus", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); } /// /// Gets a list of pending SetPerformance and/or SetStorageRetention operations for the title. /// public void GetPendingOperations(InsightsGetPendingOperationsRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? authenticationContext; var callSettings = apiSettings ?? PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Insights/GetPendingOperations", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); } /// /// Sets the Insights performance level value for the title. /// public void SetPerformance(InsightsSetPerformanceRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? authenticationContext; var callSettings = apiSettings ?? PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Insights/SetPerformance", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); } /// /// Sets the Insights data storage retention days value for the title. /// public void SetStorageRetention(InsightsSetStorageRetentionRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? authenticationContext; var callSettings = apiSettings ?? PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Insights/SetStorageRetention", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); } } } #endif