#if !DISABLE_PLAYFABENTITY_API using System; using System.Collections.Generic; using PlayFab.DataModels; using PlayFab.Internal; using PlayFab.SharedModels; namespace PlayFab { /// /// Store arbitrary data associated with an entity. Objects are small (~1KB) JSON-compatible objects which are stored /// directly on the entity profile. Objects are made available for use in other PlayFab contexts, such as PlayStream events /// and CloudScript functions. Files can efficiently store data of any size or format. Both objects and files support a /// flexible permissions system to control read and write access by other entities. /// public class PlayFabDataInstanceAPI : IPlayFabInstanceApi { public readonly PlayFabApiSettings apiSettings = null; public readonly PlayFabAuthenticationContext authenticationContext = null; public PlayFabDataInstanceAPI(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 PlayFabDataInstanceAPI(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(); } } /// /// Abort pending file uploads to an entity's profile. /// public void AbortFileUploads(AbortFileUploadsRequest 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("/File/AbortFileUploads", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); } /// /// Delete files on an entity's profile. /// public void DeleteFiles(DeleteFilesRequest 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("/File/DeleteFiles", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); } /// /// Finalize file uploads to an entity's profile. /// public void FinalizeFileUploads(FinalizeFileUploadsRequest 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("/File/FinalizeFileUploads", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); } /// /// Retrieves file metadata from an entity's profile. /// public void GetFiles(GetFilesRequest 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("/File/GetFiles", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); } /// /// Retrieves objects from an entity's profile. /// public void GetObjects(GetObjectsRequest 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("/Object/GetObjects", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); } /// /// Initiates file uploads to an entity's profile. /// public void InitiateFileUploads(InitiateFileUploadsRequest 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("/File/InitiateFileUploads", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); } /// /// Sets objects on an entity's profile. /// public void SetObjects(SetObjectsRequest 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("/Object/SetObjects", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this); } } } #endif