#if !DISABLE_PLAYFABENTITY_API && !DISABLE_PLAYFAB_STATIC_API using System; using System.Collections.Generic; using PlayFab.ExperimentationModels; using PlayFab.Internal; namespace PlayFab { /// /// APIs for managing experiments. /// public static class PlayFabExperimentationAPI { static PlayFabExperimentationAPI() {} /// /// Verify entity login. /// public static bool IsEntityLoggedIn() { return PlayFabSettings.staticPlayer.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 static void ForgetAllCredentials() { PlayFabSettings.staticPlayer.ForgetAllCredentials(); } /// /// Creates a new experiment exclusion group for a title. /// public static void CreateExclusionGroup(CreateExclusionGroupRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? PlayFabSettings.staticPlayer; var callSettings = PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Experimentation/CreateExclusionGroup", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings); } /// /// Creates a new experiment for a title. /// public static void CreateExperiment(CreateExperimentRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? PlayFabSettings.staticPlayer; var callSettings = PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Experimentation/CreateExperiment", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings); } /// /// Deletes an existing exclusion group for a title. /// public static void DeleteExclusionGroup(DeleteExclusionGroupRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? PlayFabSettings.staticPlayer; var callSettings = PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Experimentation/DeleteExclusionGroup", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings); } /// /// Deletes an existing experiment for a title. /// public static void DeleteExperiment(DeleteExperimentRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? PlayFabSettings.staticPlayer; var callSettings = PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Experimentation/DeleteExperiment", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings); } /// /// Gets the details of all exclusion groups for a title. /// public static void GetExclusionGroups(GetExclusionGroupsRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? PlayFabSettings.staticPlayer; var callSettings = PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Experimentation/GetExclusionGroups", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings); } /// /// Gets the details of all exclusion groups for a title. /// public static void GetExclusionGroupTraffic(GetExclusionGroupTrafficRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? PlayFabSettings.staticPlayer; var callSettings = PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Experimentation/GetExclusionGroupTraffic", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings); } /// /// Gets the details of all experiments for a title. /// public static void GetExperiments(GetExperimentsRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? PlayFabSettings.staticPlayer; var callSettings = PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Experimentation/GetExperiments", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings); } /// /// Gets the latest scorecard of the experiment for the title. /// public static void GetLatestScorecard(GetLatestScorecardRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? PlayFabSettings.staticPlayer; var callSettings = PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Experimentation/GetLatestScorecard", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings); } /// /// Gets the treatment assignments for a player for every running experiment in the title. /// public static void GetTreatmentAssignment(GetTreatmentAssignmentRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? PlayFabSettings.staticPlayer; var callSettings = PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Experimentation/GetTreatmentAssignment", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings); } /// /// Starts an existing experiment for a title. /// public static void StartExperiment(StartExperimentRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? PlayFabSettings.staticPlayer; var callSettings = PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Experimentation/StartExperiment", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings); } /// /// Stops an existing experiment for a title. /// public static void StopExperiment(StopExperimentRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? PlayFabSettings.staticPlayer; var callSettings = PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Experimentation/StopExperiment", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings); } /// /// Updates an existing exclusion group for a title. /// public static void UpdateExclusionGroup(UpdateExclusionGroupRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? PlayFabSettings.staticPlayer; var callSettings = PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Experimentation/UpdateExclusionGroup", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings); } /// /// Updates an existing experiment for a title. /// public static void UpdateExperiment(UpdateExperimentRequest request, Action resultCallback, Action errorCallback, object customData = null, Dictionary extraHeaders = null) { var context = (request == null ? null : request.AuthenticationContext) ?? PlayFabSettings.staticPlayer; var callSettings = PlayFabSettings.staticSettings; if (!context.IsEntityLoggedIn()) throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn,"Must be logged in to call this method"); PlayFabHttp.MakeApiCall("/Experimentation/UpdateExperiment", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings); } } } #endif